/* cars.tti.in.ua — TTI corporate design system (docs/SPEC.md §5.0)
   Tokens & type come from the official TTI Corporate Identity Guide (Gate C RESOLVED). */

@font-face {
  font-family: "Centrale Sans";
  src: url("/static/fonts/CentraleSans-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Centrale Sans";
  src: url("/static/fonts/CentraleSans-Bold.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  /* official TTI brand palette */
  --tti-navy: #002855;       /* TTI DARK BLUE / Pantone 295 */
  --tti-navy-700: #003775;   /* UI blue scale step */
  --tti-blue: #0082CA;       /* TTI BLUE / Process Blue */
  --tti-blue-700: #006AA3;
  --tti-turquoise: #05BEC8;  /* TTI LIGHT BLUE / Pantone 311 */
  --tti-yellow: #CEDC00;     /* TTI YELLOW / Pantone 381 */
  --tti-orange: #E63323;     /* TTI ORANGE / Pantone 1788 */
  /* status (orange = official brand alert; green added for budget semantics) */
  --ok-green: #2E7D32;
  --alert-red: #E63323;
  --amber: #B8860B;
  /* neutrals from the guide */
  --ink: #1A1A1A;            /* TTI RICH BLACK */
  --muted: #6B6B6B;          /* TTI GREY / Pantone 424 */
  --line: #E3E7EB;
  --surface: #F8F8F8;        /* TTI WHITE */
  --white: #FFFFFF;
  /* system */
  --radius: 5px;
  --gap: 16px;
  --font-sans: "Centrale Sans", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  --shadow: 0 1px 2px rgba(0, 40, 85, .06), 0 1px 3px rgba(0, 40, 85, .04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "cv05" 1;
}

/* numbers always tabular */
.num, td.num, .metric-value, .odo, .money { font-variant-numeric: tabular-nums; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.012em; color: var(--tti-navy); margin: 0 0 .4em; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
a { color: var(--tti-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- header ---- */
.app-header {
  background: var(--tti-navy);
  color: var(--white);
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 56px;
}
.app-header .brand { display: flex; align-items: center; gap: 11px; font-weight: 700; color: var(--white); letter-spacing: -.01em; }
.app-header .brand img { display: block; height: 26px; width: auto; }
.app-header .brand .brand-sep { width: 1px; height: 22px; background: rgba(255,255,255,.28); }
.app-header .brand .brand-ua { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--tti-navy); background: var(--tti-turquoise); border-radius: 3px; padding: 1px 5px; }
.app-header .brand .brand-app { font-size: 14px; font-weight: 400; color: rgba(255,255,255,.85); white-space: nowrap; }
.app-header nav { display: flex; gap: 18px; margin-left: 8px; }
.app-header nav a { color: rgba(255,255,255,.82); font-size: 14px; padding: 4px 0; border-bottom: 2px solid transparent; }
.app-header nav a:hover, .app-header nav a.active { color: var(--white); text-decoration: none; border-bottom-color: var(--tti-turquoise); }
.app-header .spacer { flex: 1; }
.lang-switch { display: inline-flex; border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius); overflow: hidden; }
.lang-switch a { color: rgba(255,255,255,.7); padding: 3px 9px; font-size: 12px; font-weight: 600; }
.lang-switch a.active { background: var(--white); color: var(--tti-navy); }
.lang-switch a:hover { text-decoration: none; }
.user-box { display: inline-flex; align-items: center; gap: 10px; margin: 0; }
.user-name { color: rgba(255,255,255,.85); font-size: 13px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { font: inherit; font-size: 12px; font-weight: 600; color: rgba(255,255,255,.78); background: transparent; border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius); padding: 4px 10px; cursor: pointer; }
.logout-btn:hover { color: var(--white); border-color: rgba(255,255,255,.6); }

/* ---- layout ---- */
.container { max-width: 1120px; margin: 0 auto; padding: 24px; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid transparent;
  background: var(--tti-blue); color: var(--white);
}
.btn:hover { background: var(--tti-blue-700); text-decoration: none; }
.btn.secondary { background: var(--white); color: var(--tti-navy); border-color: var(--line); }
.btn.secondary:hover { background: var(--surface); }
.btn.ghost { background: transparent; color: var(--tti-navy); border-color: transparent; }

/* ---- tables ---- */
table.grid { width: 100%; border-collapse: collapse; background: var(--white); }
table.grid th, table.grid td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); }
table.grid th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface); }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid tr:last-child td { border-bottom: none; }
table.grid tbody tr:hover { background: #fbfcfd; }

/* ---- status badge ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; padding: 3px 10px; border-radius: var(--radius); letter-spacing: .02em; }
.badge.under { background: rgba(46,125,50,.10); color: var(--ok-green); }
.badge.over { background: rgba(198,40,40,.10); color: var(--alert-red); }
.badge.big { font-size: 20px; padding: 8px 16px; }
.badge.warn { background: rgba(184,134,11,.12); color: var(--amber); }
.coords-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .coords-grid { grid-template-columns: 1fr; } }

/* ---- forms ---- */
form.stack { display: grid; gap: 20px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 0; }
fieldset > legend { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--tti-navy); font-weight: 700; padding: 0 6px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.field .req { color: var(--alert-red); }
.field .hint { font-size: 12px; color: var(--muted); }
.field input, .field select {
  font: inherit; font-size: 14px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid var(--tti-blue); outline-offset: 0; border-color: var(--tti-blue); }
.form-error { background: rgba(198,40,40,.08); color: var(--alert-red); border: 1px solid rgba(198,40,40,.25); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--tti-navy); padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--white); border-radius: var(--radius); padding: 32px; box-shadow: 0 10px 40px rgba(0,16,42,.35); }
.login-card .brand-mono { display: flex; justify-content: center; margin-bottom: 18px; }
.login-card h1 { text-align: center; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card form { display: grid; gap: 14px; }
.login-card .btn { width: 100%; justify-content: center; }

/* ---- CSS-only modal (record-reading from fleet) ---- */
.modal { position: fixed; inset: 0; background: rgba(0,16,42,.45); display: none; place-items: center; z-index: 60; padding: 16px; }
.modal:target { display: grid; }
.modal-card { background: var(--white); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 420px; box-shadow: 0 14px 44px rgba(0,16,42,.32); }
.modal-close { font-size: 18px; color: var(--muted); text-decoration: none; line-height: 1; padding: 2px 8px; }
.modal-close:hover { color: var(--ink); text-decoration: none; }

/* ---- misc ---- */
.muted { color: var(--muted); }
.subline { font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.countdown { font-weight: 700; color: var(--tti-navy); }

/* ---- gauge (driven vs time fraction) ---- */
.gauge { padding: 14px 2px 6px; }
.gauge-track { position: relative; height: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.gauge-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; background: var(--tti-turquoise); }
.gauge-fill.over { background: var(--alert-red); }
.gauge-marker { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--tti-navy); }
.gauge-marker::after { content: ""; position: absolute; top: -3px; left: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--tti-navy); }
.gauge-legend { display: flex; gap: 18px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.gauge-legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.gauge-legend .sw.fill { background: var(--tti-turquoise); }
.gauge-legend .sw.mark { background: var(--tti-navy); border-radius: 50%; }

@media (max-width: 720px) {
  body { font-size: 14px; }
  .container { padding: 14px; }
  .field-grid { grid-template-columns: 1fr; }

  /* header: logo + UA + lang/logout on row 1, nav wraps to a full-width row 2 */
  .app-header { height: auto; min-height: 52px; flex-wrap: wrap; padding: 8px 12px; gap: 10px; row-gap: 8px; }
  .app-header .brand img { height: 22px; }
  .app-header .brand .brand-app { display: none; }
  .app-header nav { order: 10; flex-basis: 100%; gap: 16px; overflow-x: auto; }
  .app-header nav a { white-space: nowrap; }

  /* wide data tables scroll horizontally instead of overflowing */
  table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  /* key/value tables (metrics) stay full-width and wrap labels so values are never clipped */
  table.grid.kv { display: table; width: 100%; white-space: normal; table-layout: fixed; }
  table.grid.kv td:last-child { width: 42%; }

  /* toolbars + headings wrap */
  .toolbar { flex-wrap: wrap; gap: 10px; }
  .toolbar .spacer { display: none; }
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }
  .badge.big { font-size: 15px; padding: 6px 12px; }

  /* full-width primary actions on small screens */
  .toolbar .btn { flex: 1 1 auto; justify-content: center; }
  #budget-chart { height: 300px; }

  /* drop non-essential columns on narrow screens */
  .hide-sm { display: none; }

  /* fleet list wraps to fit (long model names) instead of horizontal scroll */
  table.grid.fleet { display: table; width: 100%; white-space: normal; }
  table.grid.fleet th, table.grid.fleet td { padding: 10px 8px; }
  table.grid.fleet .badge { font-size: 12px; padding: 3px 7px; }
}

@media (max-width: 420px) {
  .app-header .lang-switch a { padding: 3px 7px; }
  .user-name { max-width: 90px; }
  fieldset { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
