/* SPDX-FileCopyrightText: 2026 David Dalzell */
/* SPDX-License-Identifier: MIT */

/* Rail Car Movement Simulator — global/shared primitives.
   Everything here is used by 2+ tabs; feature-scoped CSS lives in its own
   file under static/css/ (see templates/index.html for the full list). */

body {
  font-family: "Red Rose", system-ui, sans-serif;
  padding-top: 4.5rem;
  padding-bottom: 3.5rem; /* room for #session-status-bar (session.css) when visible */
}

:root {
  --rail-accent:    #c0392b;
  --rail-accent-bg: #fdf3f2;
  --rail-dark:      #2c3e50;
  --rail-darker:    #212f3c;
  --rail-light:     #ecf0f1;
  --rail-red:       #e74c3c;
  --card-radius:    8px;

  --bg-muted:         #f4f4f4;
  --border-light:     #ddd;
  --border-muted:     #aaa;
  --border-subtle:    #eee;
  --text-muted:       #888;
  --text-secondary:   #555;
  --text-light:       #777;
  --text-placeholder: #666;
  --text-strong:      #333;

  /* Adaptive: light-mode defaults */
  --consist-card-bg:     #f0f2f4;
  --consist-card-border: #d0d5db;
  --info-offer-bg:       #f0f2f4;
  /* Flat, non-theme-adaptive — this is a letterbox/pad color behind car
     photos, like paper under a print; it shouldn't invert with the theme. */
  --car-img-bg:          #f6ece2;

  --rail-blue:      #2980b9;
  --badge-blue:     #2980b9;
  --badge-muted-bg: #bdc3c7;
  --badge-muted-fg: #555;
  --badge-green:    #27ae60;
  --badge-purple:   #8e44ad;
  --badge-orange:   #d68910;
  --color-warning:  var(--badge-orange);

  --rail-green: #5c7a3e;

  /* UI primitives (shared by Layout Setup + other tabs) */
  --panel-header-bg: var(--rail-dark);
  --panel-header-fg: var(--rail-light);
  --panel-border:    color-mix(in srgb, var(--rail-dark), var(--rail-light) 40%);
  --accent:          var(--badge-orange);
  --accent-tint:     color-mix(in srgb, var(--badge-orange) 14%, transparent);
  --icon-btn-hover:  rgba(127, 127, 127, 0.15);
  --pill-bg:         rgba(255, 255, 255, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --consist-card-bg:     var(--rail-darker);
    --consist-card-border: var(--rail-dark);
    --info-offer-bg:       var(--rail-dark);
    --bg-muted:            #2a2a2a;
  }
}

[data-theme="dark"] {
  --consist-card-bg:     var(--rail-darker);
  --consist-card-border: var(--rail-dark);
  --info-offer-bg:       var(--rail-dark);
  --bg-muted:            #2a2a2a;
}

/* ── UI primitives — reusable across tabs ────────────────────────────────── */

/* Compact default button height — scoped to the button tag via custom
   property, so it never touches input/select/textarea sizing (Pico shares
   --pico-form-element-spacing-vertical across all form elements, but a
   property redefined on `button` only inherits down into buttons).
   Must list all four [type=...] button variants Pico itself targets
   (button/submit/reset/file) plus [role=button] — Pico's own button rule
   is `[role=button],[type=button],[type=file]::file-selector-button,
   [type=reset],[type=submit],button`, and any `[type=...]` attribute
   selector (specificity 0,1,0) beats a plain `button` type selector
   (0,0,1). Omitting [type="button"] here left every <button type="button">
   in the app (20+ in templates/index.html alone) matching Pico's
   higher-specificity [type=button] font-size instead of this rule's.
   margin-bottom: 0 for the same reason — Pico's own
   `[type=button],[type=reset],[type=submit]{margin-bottom:var(--pico-spacing)}`
   only matches elements with an explicit type="button"/"submit"/"reset"
   attribute, so a bare <button> sibling with no type attribute (matching
   only the lower-specificity `button` selector) gets no such margin —
   two visually-identical buttons side by side end up different heights
   purely because one happens to declare type="button" and the other
   doesn't (issue #60). */
button, [type="button"], [type="submit"], [type="reset"], [role="button"] {
  --pico-form-element-spacing-vertical: 0.4rem;
  --pico-form-element-spacing-horizontal: 1rem;
  font-size: 0.85rem;
  margin-bottom: 0;
}

/* Borderless icon button (edit / delete / move / collapse-caret). Replaces
   boxed `.outline small [contrast]`. Used app-wide, including the Layout
   Setup tree (#location-tree) — do not re-scope a tree-local copy of this;
   it previously existed as a byte-identical duplicate and was consolidated
   into this single definition. */
button.icon-btn {
  background: none;
  border: none;
  margin: 0;
  width: auto;
  padding: 0.12rem 0.3rem;
  font-size: 0.82rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  border-radius: 4px;
  color: inherit;
}
button.icon-btn:hover { opacity: 1; background: var(--icon-btn-hover); }
button.icon-btn:disabled { opacity: 0.22; cursor: default; }
button.icon-btn:disabled:hover { background: none; }
/* Smaller borderless caret for collapse toggles. flex-shrink so it never
   loses space to a flex:1 name/title sibling (e.g. the Location Tree rows). */
button.icon-btn.caret {
  font-size: 0.7rem;
  padding: 0.1rem 0.25rem;
  color: var(--pico-muted-color);
  opacity: 1;
  flex-shrink: 0;
}
button.icon-btn.caret:hover { color: var(--pico-contrast, #e8eaf0); background: none; }

/* Outlined accent button (e.g. "+ Add"). */
button.btn-accent {
  background: none;
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--accent);
  margin: 0;
  width: auto;
  padding: 0.12rem 0.55rem;
  font-size: 0.76rem;
  cursor: pointer;
}
button.btn-accent:hover { background: var(--accent-tint); }

/* Muted text button. */
button.btn-muted {
  background: none;
  border: none;
  color: var(--pico-muted-color);
  margin: 0;
  width: auto;
  padding: 0.12rem 0.4rem;
  font-size: 0.76rem;
  cursor: pointer;
}
button.btn-muted:hover { color: var(--accent); }

/* Slate card header bar. */
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: var(--panel-header-bg);
  color: var(--panel-header-fg);
  margin: 0;
}
.panel-head h2,
.panel-head h3,
.panel-head .panel-title {
  margin: 0;
  color: var(--panel-header-fg);
  font-size: 1rem;
}
/* Keep the header caret legible on the slate bar (mirrors .tree-group-row). */
.panel-head .icon-btn.caret {
  color: var(--panel-header-fg);
  opacity: 0.8;
}
.panel-head .icon-btn.caret:hover { opacity: 1; color: var(--panel-header-fg); }

/* Standalone slate bar for a flat sub-section header (not inside a bordered
   panel-card) — e.g. Industries, Commodity-map, Car Types, Power Pool. */
.panel-head.standalone {
  border-radius: var(--card-radius);
  margin-bottom: 0.6rem;
}

/* Card with a slate header + brighter slate boundary. Overrides any Pico
   article/section defaults (background, padding) so panel-head/panel-body
   sit flush against the border instead of inset by the tag's own padding. */
.panel-card {
  border: 1px solid var(--panel-border);
  border-radius: var(--card-radius);
  overflow: hidden;
  margin-bottom: 0.6rem;
  padding: 0;
  background: var(--pico-card-background-color, #f9f9f9);
}

/* Standard inner padding for panel-card content below the panel-head. */
.panel-body {
  padding: 0.6rem 0.75rem;
}

/* Rounded pill (status / count / tag). */
.pill {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Compact field height — opt-in for dialogs (mirrors .inline-form). */
.compact-form input,
.compact-form select,
.compact-form textarea {
  padding-top: 0.3rem !important;
  padding-bottom: 0.3rem !important;
  line-height: 1.25;
  height: auto;
  min-height: 0;
  margin-bottom: 0.4rem;
}

/* A hint/status line right under a compact field needs its own breathing
   room — margin-bottom on the input isn't enough once padding shrank. */
.compact-form label > small {
  display: block;
  margin-top: 0.3rem;
}

main.container {
  max-width: 1024px;
}

/* Generic two-column form grid — desktop columns come from Pico's own
   `.grid` default; only the mobile single-column collapse is custom
   (see the @media block below). */

/* Small red notification dot/count on a nav tab label. */
.tab-badge {
  display: inline-block;
  margin-left: 0.35rem;
  background: #dc3545;
  color: #fff;
  font-size: 0.7rem;
  font-weight: bold;
  border-radius: 10px;
  padding: 0.1rem 0.4rem;
  vertical-align: middle;
  line-height: 1.3;
}

/* ── Header & navigation ─────────────────────────────────────────────────── */
header.container-fluid {
  background: var(--rail-dark);
  padding: 0.4rem 1rem;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.nav-hamburger { display: none; }
.nav-current-tab { display: none; }

#account-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  min-height: 2rem;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  padding: 0;
  line-height: 1;
  font-size: 0.85rem;
  font-weight: 600;
  margin-left: 0.25rem;
  flex-shrink: 0;
  align-self: center;
  overflow: hidden;
}

header nav .brand,
.brand {
  color: var(--rail-light);
  font-family: "Montserrat Alternates", system-ui, sans-serif;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

header nav .brand-rail {
  color: var(--rail-red);
}

header nav a {
  color: var(--rail-light);
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  transition: background 0.15s;
  text-decoration: none;
}

header nav a:hover:not(.active) {
  background: rgba(255,255,255,0.1);
}

header nav a.active {
  background: var(--rail-red);
  color: white;
  font-weight: 600;
}

/* ── Toast notifications ─────────────────────────────────────────────────── */
.dialog-toast-container {
  position: sticky;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 10;
}

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--rail-dark);
  color: var(--rail-light);
  padding: 0.65rem 1rem;
  border-radius: var(--card-radius);
  font-size: 0.875rem;
  max-width: 340px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success { background: var(--badge-green); }
.toast.error   { background: var(--rail-accent); }
.toast.warn    { background: var(--badge-orange); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0,0,0,0.15);
  border-top-color: var(--text-strong);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 0.35rem;
}

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-header h2,
.section-header h3 {
  margin: 0;
}

.section-header-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.error-msg {
  color: var(--rail-accent);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

/* ── Car data plate (prototype weight/reweigh/COTS fields) ───────────────── */
.dataplate-fields {
  border: 1px solid var(--border-light);
  border-radius: var(--card-radius);
  margin-bottom: 1rem;
  padding: 0;
}
.dataplate-fields[open] {
  border-color: var(--badge-orange);
  padding-bottom: 0.75rem;
}
.dataplate-fields summary {
  cursor: pointer;
  padding: 0.6rem 0.85rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.dataplate-fields > .grid,
.dataplate-fields > label {
  padding: 0 0.85rem;
}
.dataplate-fields small {
  color: var(--text-muted);
  font-weight: 400;
}

.ai-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: #8a6d1f;
  background: #fdf2da;
  border: 1px solid #efd9a3;
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  margin: 0 0.85rem 0.6rem;
}

.button-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* ── Empty states ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 0.9rem;
  margin: 0;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.muted   { color: var(--text-muted); font-size: 0.85rem; }
.empty-msg { color: var(--text-muted); font-style: italic; margin-top: 1rem; }
.ml-sm   { margin-left: 0.5rem; }
.mb-md   { margin-bottom: 1rem; }

button.small {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

.btn-confirming {
  background-color: var(--rail-accent) !important;
  border-color: var(--rail-accent) !important;
  color: white !important;
}

/* ── Mobile (≤ 600px) ────────────────────────────────────────────────────── */
@media (max-width: 600px) {

  /* Navigation — hamburger dropdown */
  .nav-current-tab {
    display: inline;
    color: var(--rail-light);
    font-size: 0.9rem;
    opacity: 0.75;
    margin-left: auto;
    align-self: center;
    padding-right: 0.25rem;
  }

  .nav-hamburger {
    display: flex;
    align-items: center;
    background: none;
    border: none;
    color: var(--rail-light);
    font-size: 1.5rem;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    min-height: 36px;
  }

  #nav-tab-list {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--rail-dark);
    padding: 0.5rem;
    gap: 0.4rem;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    margin: 0;
  }

  #nav-tab-list.nav-open {
    display: flex;
  }

  #nav-tab-list {
    padding: 0.25rem 0;
    margin: 0;
    padding-inline-start: 0;
  }

  #nav-tab-list li {
    padding: 0;
    margin: 0;
    padding-inline-start: 0;
  }

  #nav-tab-list a {
    display: block;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    white-space: nowrap;
    font-size: 0.95rem;
  }

  /* Main container — tighter side padding */
  main.container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  /* Two-column form grids → single column (app-wide) */
  .grid {
    grid-template-columns: 1fr !important;
  }

  /* Touch targets — 44px minimum height */
  button,
  [role="button"],
  a.outline {
    min-height: 44px;
  }

  /* Pico close button — keep square, not squished by min-height */
  button[rel="prev"] {
    min-width: 44px;
  }

  button.small {
    min-height: 36px;
    font-size: 0.85rem;
  }

  /* Toast — full width */
  #toast-container {
    left: 0.75rem;
    right: 0.75rem;
  }

  .toast {
    max-width: 100%;
  }

  /* Section headers — allow wrap */
  .section-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .section-header .button-row {
    margin-top: 0;
  }
}
