/**
 * Shared styles for surf.institute
 * Include via: <link rel="stylesheet" href="/static/styles.css">
 */

/* ============ CSS Variables (Theme) ============ */
:root {
  --bg-body: #0a0e12;
  --bg-header: #151a21;
  --bg-card: #111722;
  --bg-input: #1f2933;
  --bg-input-alt: #0f1720;
  --border-primary: #1f2933;
  --border-secondary: #2d3748;
  --border-tertiary: #1f2a3a;
  --text-primary: #e0e0e0;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --text-heading: #fff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #60a5fa;
  --shadow-card: rgba(0, 0, 0, 0.25);
  --shadow-dropdown: rgba(0, 0, 0, 0.35);
  --success: #22c55e;
  --warning: #f59e0b;

  /* Ocean palette */
  --ocean-deep: #0ea5e9;
  --ocean-teal: #14b8a6;
  --ocean-foam: #67e8f9;
  --ocean-warm: #f97316;
  --ocean-mist: rgba(14, 165, 233, 0.08);
}

[data-theme="light"] {
  --bg-body: #eef1f5;
  --bg-header: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0f2f5;
  --bg-input-alt: #e8ebef;
  --border-primary: #d1d5db;
  --border-secondary: #e5e7eb;
  --border-tertiary: #d1d5db;
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-heading: #111827;
  --shadow-card: rgba(0, 0, 0, 0.08);
  --shadow-dropdown: rgba(0, 0, 0, 0.15);

  /* Ocean palette (light mode) */
  --ocean-deep: #0284c7;
  --ocean-teal: #0d9488;
  --ocean-foam: #06b6d4;
  --ocean-warm: #ea580c;
  --ocean-mist: rgba(14, 165, 233, 0.06);
}

/* ============ Base Reset ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg-body);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
}

/* ============ Header ============ */
header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-primary);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 68px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 24px;
}

/* ============ Header Center (Search) ============ */
.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 480px;
  margin: 0 auto;
}

/* ============ Icon Buttons ============ */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border-tertiary);
  background: var(--bg-input-alt);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.icon-btn:hover {
  background: var(--bg-input);
  border-color: var(--border-secondary);
  color: var(--text-primary);
}

.icon-btn:hover svg {
  color: var(--accent-light);
}

.icon-btn svg {
  transition: color 0.15s ease;
}

/* Theme Toggle - show sun in dark mode, moon in light mode */
#themeToggle .sun-icon {
  display: none;
}
#themeToggle .moon-icon {
  display: block;
}
[data-theme="dark"] #themeToggle .sun-icon,
:root:not([data-theme="light"]) #themeToggle .sun-icon {
  display: block;
}
[data-theme="dark"] #themeToggle .moon-icon,
:root:not([data-theme="light"]) #themeToggle .moon-icon {
  display: none;
}

/* ============ Nav Menu ============ */
.nav-menu {
  position: relative;
}

.nav-dropdown {
  position: absolute;
  top: 44px;
  right: 0;
  background: var(--bg-input-alt);
  border: 1px solid var(--border-tertiary);
  border-radius: 12px;
  box-shadow: 0 18px 32px var(--shadow-dropdown);
  padding: 8px;
  min-width: 200px;
  z-index: 20;
  display: none;
}

.nav-dropdown.open {
  display: block;
}

/* ============ Logo ============ */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}

.logo-mark {
  height: 30px;
  width: 30px;
  object-fit: contain;
}

.logo-text {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.logo-primary {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-heading);
  line-height: 1;
}

/* ============ Search ============ */
.search-picker {
  position: relative;
  flex: 1;
  width: 100%;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-secondary);
  border-radius: 10px;
  padding-right: 6px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-wrap:focus-within {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.12);
}

.search-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 10px 8px 10px 12px;
  font-size: 14px;
  outline: none;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.clear-btn {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.clear-btn.visible {
  display: inline-flex;
}

.clear-btn:hover {
  color: var(--text-primary);
  background: var(--border-secondary);
}

.search-shortcut {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--bg-body);
  border: 1px solid var(--border-secondary);
  color: var(--text-muted);
  font-size: 12px;
  font-family: monospace;
  flex-shrink: 0;
  margin-right: 4px;
}

.ask-btn {
  display: none;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border-secondary);
  border-radius: 14px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  margin-left: 4px;
}

.ask-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.ask-btn.visible {
  display: inline-flex;
}

/* ============ Search Dropdown ============ */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 10px;
  box-shadow: 0 12px 30px var(--shadow-dropdown);
  padding: 6px 0;
  max-height: 340px;
  overflow-y: auto;
  z-index: 10;
  display: none;
}

.search-items {
  list-style: none;
  padding: 0;
  margin: 0;
}

.search-item {
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.12s ease;
  text-decoration: none;
  color: inherit;
}

.search-item:hover,
.search-item.active {
  background: var(--bg-input);
}

.search-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--bg-input);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-light);
  font-size: 13px;
}

.search-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.search-title {
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.empty-state {
  padding: 12px 14px;
  color: var(--text-muted);
  font-size: 13px;
}

.search-group-header {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-group-header:not(:first-child) {
  margin-top: 4px;
  border-top: 1px solid var(--border-primary);
  padding-top: 10px;
}

.search-icon.saved {
  color: #f59e0b;
}

.search-icon.station {
  color: var(--text-secondary);
}

.search-icon.station.ndbc {
  color: var(--accent-light);
}

.search-icon.station.cdip {
  color: #a855f7;
}

.search-icon.station.coops {
  color: var(--success);
}

/* ============ Header Right / User Button ============ */
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-btn {
  position: relative;
}

.user-btn .icon-btn {
  border-radius: 50%;
  overflow: hidden;
}

.user-btn .icon-btn.loading {
  opacity: 0.7;
  cursor: wait;
}

.user-avatar {
  width: 100%;
  height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============ User Dropdown ============ */
.user-dropdown {
  position: absolute;
  top: 48px;
  right: 0;
  background: var(--bg-input-alt);
  border: 1px solid var(--border-tertiary);
  border-radius: 12px;
  box-shadow: 0 18px 32px var(--shadow-dropdown);
  padding: 8px;
  min-width: 180px;
  z-index: 20;
  display: none;
}

.user-dropdown.open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  color: var(--text-secondary);
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 13px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}

.dropdown-item:hover {
  background: var(--bg-input);
  text-decoration: none;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-tertiary);
  margin: 6px 0;
}

/* ============ Mobile Responsive ============ */
@media (max-width: 600px) {
  header {
    padding: 10px 12px;
    gap: 10px;
  }

  .header-left {
    gap: 12px;
  }

  .logo-text {
    display: none;
  }

  .header-center {
    min-width: 0;
    max-width: none;
    margin: 0 8px;
  }

  .search-input {
    padding: 8px 6px 8px 10px;
    font-size: 16px; /* Prevents iOS zoom */
  }

  .search-shortcut {
    display: none;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  .header-right {
    gap: 6px;
  }

  main {
    padding: 16px 12px;
  }

  .page-title {
    font-size: 24px;
  }
}

/* ============ Main Layout ============ */
main {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

/* ============ Page Header ============ */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}

/* ============ Links ============ */
a {
  color: var(--accent-light);
  text-decoration: none;
}

a:hover {
  color: var(--accent-primary);
}

a:visited {
  color: var(--text-primary);
}

/* ============ Cards ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 4px 12px var(--shadow-card);
}

.card:hover {
  border-color: var(--accent-light);
}

/* ============ Sections ============ */
.section {
  background: var(--bg-card);
  border: 1px solid var(--border-tertiary);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 12px 30px var(--shadow-card);
}

.section h2 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-heading);
}

.section p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-size: 14px;
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  text-decoration: none;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  text-decoration: none;
}

.btn-primary:hover {
  background: var(--accent-hover);
  text-decoration: none;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-tertiary);
}

.btn-secondary:hover {
  background: var(--bg-input);
  border-color: var(--border-secondary);
  text-decoration: none;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  background: transparent;
  border: 1px solid var(--border-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}

.btn-ghost:hover {
  border-color: var(--border-secondary);
  text-decoration: none;
}

/* ============ Forms ============ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

input,
textarea,
select {
  background: var(--bg-input-alt);
  border: 1px solid var(--border-tertiary);
  color: var(--text-primary);
  padding: 10px;
  border-radius: 8px;
  font-size: 14px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

/* ============ Grid Layouts ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 900px) {
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

/* ============ Stats ============ */
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-heading);
}

.stat-value .unit {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 2px;
}

.stat-detail {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ============ Loading States ============ */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.loading-shimmer {
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border-secondary) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  color: transparent;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============ Error States ============ */
.error {
  background: #7f1d1d;
  border: 1px solid #991b1b;
  padding: 16px;
  border-radius: 8px;
  color: #fca5a5;
  margin-bottom: 20px;
}

.error.rate-limited {
  background: linear-gradient(135deg, #1e3a5f 0%, #1a2744 100%);
  border: 1px solid #2563eb;
  text-align: center;
  padding: 32px 24px;
}

.error.rate-limited .error-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.error.rate-limited .error-title {
  font-size: 18px;
  font-weight: 600;
  color: #93c5fd;
  margin-bottom: 8px;
}

.error.rate-limited .error-message {
  color: #bfdbfe;
  font-size: 14px;
  line-height: 1.5;
}

.error.rate-limited .error-hint {
  margin-top: 16px;
  font-size: 13px;
  color: #64748b;
}

[data-theme="light"] .error.rate-limited {
  background: linear-gradient(135deg, #dbeafe 0%, #e0f2fe 100%);
  border-color: #3b82f6;
}

[data-theme="light"] .error.rate-limited .error-title {
  color: #1e40af;
}

[data-theme="light"] .error.rate-limited .error-message {
  color: #1e3a8a;
}

[data-theme="light"] .error.rate-limited .error-hint {
  color: #64748b;
}

/* ============ No Data / Empty States ============ */
.no-data {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 15px;
  font-style: italic;
}

.no-data h3 {
  font-size: 16px;
  font-weight: 600;
  font-style: normal;
  color: var(--text-heading);
  margin-bottom: 4px;
}

.no-data p {
  margin: 0;
  font-style: normal;
}

/* ============ Status Messages ============ */
.status {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.status.success {
  color: var(--success);
}

.status.error {
  color: #fca5a5;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
}

/* ============ Badges ============ */
.badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 4px;
}

.badge-primary {
  color: var(--accent-light);
  background: rgba(96, 165, 250, 0.15);
}

.badge-success {
  color: var(--success);
  background: rgba(34, 197, 94, 0.15);
}

.badge-warning {
  color: var(--warning);
  background: rgba(245, 158, 11, 0.15);
}

/* ============ Filter Toggles ============ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-toggles {
  display: flex;
  gap: 6px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-secondary);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-toggle:hover {
  border-color: var(--accent-light);
}

.filter-toggle.active {
  background: var(--accent-light);
  color: var(--bg-body);
  border-color: var(--accent-light);
}

.filter-toggle.muted {
  opacity: 0.5;
  background: transparent;
}

.filter-toggle.off {
  opacity: 0.4;
  background: transparent;
}

.filter-toggle svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .filter-toggle {
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }
  .filter-toggle-label {
    display: none;
  }
}

/* ============ Sort Control ============ */
.sort-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.sort-control label {
  font-size: 13px;
  color: var(--text-muted);
  flex-direction: row;
}

.sort-select {
  background: var(--bg-input);
  border: 1px solid var(--border-secondary);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.sort-select:focus {
  outline: none;
  border-color: var(--accent-light);
}

/* ============ Results Count ============ */
.results-count {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ============ Region Sections ============ */
.region-section {
  margin-bottom: 32px;
}

.region-header {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.region-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 10px;
}
