:root {
  --bg: #0f1117;
  --fg: #e8eaf0;
  --muted: #8b90a0;
  --accent: #4a9eff;
  --border: #2a2d3a;
  --card-bg: #181c27;
  --price-up: #4a7c59;
  --price-down: #c0392b;
  --status-anchor: #d4a017;
  --status-moored: #4a7c59;
}

body.theme-light {
  --bg: #f5f5f5;
  --fg: #1a1a1a;
  --muted: #666666;
  --accent: #4a9eff;
  --border: #d0d0d0;
  --card-bg: #ffffff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--accent);
}

main {
  padding: 1rem;
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

section {
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

section h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

@media (min-width: 720px) {
  main {
    grid-template-columns: 1fr 1fr;
    padding: 1.5rem;
    gap: 1.25rem;
  }
}

/* Site nav bar */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.site-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--fg);
}

.site-nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.site-nav a:hover {
  color: var(--fg);
}

.site-nav a.nav-active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

@media (max-width: 480px) {
  .site-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .site-nav {
    flex-wrap: wrap;
  }
}

/* Watchlist */

.watchlist-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.watchlist-field {
  display: flex;
  flex-direction: column;
}

.watchlist-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  background-color: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
}

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

.watchlist-add-btn {
  padding: 0.45rem 1rem;
  background-color: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
}

.watchlist-add-btn:hover {
  opacity: 0.88;
}

@media (min-width: 720px) {
  .watchlist-form {
    flex-direction: row;
    align-items: flex-start;
  }

  .watchlist-field {
    flex: 1;
  }

  .watchlist-input {
    width: 100%;
  }

  .watchlist-add-btn {
    flex-shrink: 0;
  }
}

.watchlist-error {
  display: none;
  font-size: 0.8rem;
  color: #e05555;
  margin-top: 0.2rem;
}

.watchlist-error--visible {
  display: block;
}

.watchlist-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.watchlist-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.watchlist-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.watchlist-item-info {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.watchlist-item-name {
  font-weight: 600;
}

.watchlist-item-imo {
  font-size: 0.85rem;
  color: var(--muted);
}

.watchlist-status {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--border);
}

.watchlist-status-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.watchlist-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-underway {
  background-color: var(--accent);
}

.status-at-anchor {
  background-color: var(--status-anchor);
}

.status-moored {
  background-color: var(--status-moored);
}

.status-unknown {
  background-color: var(--muted);
}

.watchlist-status-detail {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.watchlist-status-unavailable {
  font-size: 0.9rem;
  color: var(--muted);
}

.watchlist-item-links {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.watchlist-item-links a {
  color: var(--accent);
  text-decoration: none;
}

.watchlist-item-links a:hover {
  text-decoration: underline;
}

.watchlist-remove-btn {
  align-self: flex-start;
  padding: 0.2rem 0.55rem;
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

.watchlist-remove-btn:hover {
  color: var(--fg);
  border-color: var(--muted);
}

/* Movements */

.movement-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.movement-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.movement-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
}

.movement-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.movement-item-vessel {
  font-weight: 600;
}

.movement-item-terminal {
  font-size: 0.9rem;
  color: var(--muted);
}

.movement-item-direction {
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}

.movement-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

.movement-badge--arrival {
  background-color: var(--accent);
  color: #fff;
}

.movement-badge--departure {
  background-color: var(--muted);
  color: var(--bg);
}

.movement-item-date {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Movements filter bar */

.movement-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.movement-filter-select,
.movement-filter-input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  background-color: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: inherit;
}

.movement-filter-select::placeholder,
.movement-filter-input::placeholder {
  color: var(--muted);
}

@media (min-width: 600px) {
  .movement-filter-bar {
    flex-direction: row;
  }

  .movement-filter-select,
  .movement-filter-input {
    width: auto;
    flex: 1;
  }
}

.movement-count {
  margin: 0 0 0.6rem 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Sources */

.source-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.source-item {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.source-item-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.source-item-link:hover {
  text-decoration: underline;
}

.source-item-description {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Notes */

.notes-textarea {
  width: 100%;
  min-height: 9rem;
  padding: 0.6rem;
  background-color: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
}

.notes-textarea::placeholder {
  color: var(--muted);
}

.notes-status {
  margin: 0.4rem 0 0 0;
  font-size: 0.8rem;
  transition: color 0.2s ease;
}

.notes-status--saved {
  color: var(--accent);
}

.notes-status--saving {
  color: var(--muted);
}

/* Settings */

.settings-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.settings-item {
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 44px;
  padding: 0.5rem 0;
  cursor: pointer;
  font-size: 0.95rem;
}

.settings-checkbox {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Sign out button (dashboard header) */

.signout-btn {
  padding: 0.3rem 0.75rem;
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-left: auto;
}

.signout-btn:hover {
  color: var(--fg);
  border-color: var(--muted);
}

/* Theme toggle button (dashboard header) */

.theme-toggle-btn {
  padding: 0.3rem 0.75rem;
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  margin-left: 0.5rem;
}

.theme-toggle-btn:hover {
  color: var(--fg);
  border-color: var(--muted);
}

/* Backup section */

.backup-export-btn {
  padding: 0.45rem 1rem;
  background: none;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  display: block;
  margin-bottom: 0.75rem;
}

.backup-export-btn:hover {
  border-color: var(--muted);
}

.backup-file-label {
  display: inline-block;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.backup-file-input {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.85rem;
  color: var(--fg);
  cursor: pointer;
}

.backup-message {
  font-size: 0.85rem;
  margin: 0;
  min-height: 1.2em;
}

.backup-message--success {
  color: #4caf7d;
}

.backup-message--error {
  color: #e05555;
}

/* Price section */

.price-section {
  margin-bottom: 2rem;
}

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

@media (min-width: 720px) {
  .price-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.price-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.price-card .commodity-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  margin: 0 0 0.25rem 0;
}

.price-card .price-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--fg);
}

.price-card .price-unit {
  font-size: 0.75rem;
  color: var(--muted);
}

.price-up {
  color: var(--price-up);
  margin: 0.25rem 0 0 0;
  font-size: 0.9rem;
}

.price-down {
  color: var(--price-down);
  margin: 0.25rem 0 0 0;
  font-size: 0.9rem;
}

.sparkline {
  width: 100%;
  height: 40px;
  display: block;
  margin-top: 0.5rem;
}

.unavailable-msg {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.5rem 0 0.25rem 0;
}

.unavailable-reason {
  color: var(--muted);
  font-size: 0.75rem;
  font-style: italic;
  margin: 0;
}

.data-timestamp {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1rem;
  margin: 0 0 1rem 0;
}

/* Chart and table controls */

.chart-controls {
  margin-bottom: 0.5rem;
}

.toggle-btn {
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

.toggle-btn:hover {
  color: var(--fg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
}

td {
  padding: 0.4rem 0.6rem;
}

.row-alt {
  background: var(--card-bg);
}

/* Live vessel map */

#vessel-map-section {
  grid-column: 1 / -1;
}

.map-container {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card-bg);
  margin: 0.75rem 0;
}

.map-container iframe {
  display: block;
  width: 100%;
  height: 320px;
  border: none;
}

@media (min-width: 720px) {
  .map-container iframe {
    height: 600px;
  }
}

.section-description {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.map-attribution {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.map-attribution a {
  color: var(--accent);
  text-decoration: none;
}

.map-attribution a:hover {
  text-decoration: underline;
}

/* Tab bar */

.tab-bar {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.4rem 0.75rem;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  margin-bottom: -1px;
  font-family: inherit;
}

.tab-btn:hover {
  color: var(--fg);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

/* Tab panels */

.tab-panel {
  min-height: 120px;
}

.loading-msg {
  color: var(--muted);
  font-size: 0.85rem;
}

.attribution {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.attribution a {
  color: var(--accent);
  text-decoration: none;
}

/* Warning banner */

.warning-banner {
  background: rgba(212, 160, 23, 0.15);
  border: 1px solid var(--status-anchor);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--status-anchor);
  margin-bottom: 0.75rem;
}

/* Period label */

.period-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

/* Trade flow SVG chart */

.trade-flow-chart {
  display: block;
  width: 100%;
  max-width: 400px;
  margin-bottom: 1rem;
}

/* Settings experimental note */

.settings-experimental-note {
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: 0.5rem;
}

.settings-item-desc {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 0.25rem 0;
  padding-left: 1.75rem;
}

/* Login page */

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-main {
  width: 100%;
  padding: 1rem;
  display: flex;
  justify-content: center;
}

.login-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.login-heading {
  margin: 0;
  font-size: 1.4rem;
  color: var(--accent);
  text-align: center;
}

.login-subheading {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  text-align: center;
}

.login-error {
  display: none;
  font-size: 0.85rem;
  color: #e05555;
  text-align: center;
}

.login-error.visible {
  display: block;
}

.login-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background-color: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  font-family: inherit;
}

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

.login-btn {
  width: 100%;
  padding: 0.6rem 1rem;
  background-color: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  margin-top: 0.25rem;
}

.login-btn:hover {
  opacity: 0.88;
}
