/* LeaseTrack — shared stylesheet.
 *
 * Consolidated from the six per-template <style> blocks that used to live
 * inline in web.rs. Served as a single cacheable document by `web::assets`,
 * so the palette and component rules exist in exactly one place.
 */

:root {
  /* Tells the browser which scheme the page is painted in, so native UI —
   * the date-picker glyph, number spinners, scrollbars, autofill — is drawn
   * to match. Without it the UA assumes light and renders a dark calendar
   * icon on our dark inputs, where it is all but invisible. */
  color-scheme: light;

  --bg:          #ffffff;
  --bg-card:     #f6f8fa;
  --bg-panel:    #f6f8fa;
  --bg-header:   #f6f8fa;
  --bg-input:    #ffffff;
  --bg-bar:      #eaeef2;
  --bg-bar-fut:  #d0d7de;
  --border:      #d0d7de;
  --border-sub:  #eaeef2;
  --text:        #1f2328;
  --muted:       #656d76;
  --accent:      #0969da;
  --green:       #1a7f37;
  --red:         #cf222e;
  --yellow:      #9a6700;
  --btn-bg:      #1a7f37;
  --btn-hover:   #2da44e;
  --input-bg:    #ffffff;
  --err-bg:      #fff0ee;
  --err-fg:      #cf222e;
  --err-border:  #f85149;
  --ok-bg:       #dafbe1;
  --ok-fg:       #1a7f37;
  --ok-border:   #2da44e;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg:          #0d1117;
    --bg-card:     #161b22;
    --bg-panel:    #161b22;
    --bg-header:   #161b22;
    --bg-input:    #0d1117;
    --bg-bar:      #21262d;
    --bg-bar-fut:  #30363d;
    --border:      #30363d;
    --border-sub:  #21262d;
    --text:        #c9d1d9;
    --muted:       #8b949e;
    --accent:      #58a6ff;
    --green:       #3fb950;
    --red:         #f85149;
    --yellow:      #d29922;
    --btn-bg:      #238636;
    --btn-hover:   #2ea043;
    --input-bg:    #0d1117;
    --err-bg:      #3d1e1e;
    --err-fg:      #f85149;
    --err-border:  #f85149;
    --ok-bg:       #1a2e1a;
    --ok-fg:       #3fb950;
    --ok-border:   #3fb950;
  }
}

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

body {
  font-family: 'Courier New', monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* The single-card pages (login, register, forgot, reset, setup) centre their
 * card; the dashboard lays out a full-width grid instead. */
body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Preview banner ──────────────────────────────────────────────────────── */

.preview-banner {
  background: #9a6700;
  color: #fff;
  text-align: center;
  padding: 0.4rem;
  font-size: 0.8rem;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.05em;
}

/* Centred pages float the banner so it cannot push the card off-centre. */
body.centered .preview-banner {
  position: fixed;
  top: 0;
  width: 100%;
}

/* ── Card pages ──────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}

.card.card-wide  { max-width: 420px; }
.card.card-wider { max-width: 440px; }

h1 { font-size: 1.4rem; margin-bottom: 0.25rem; color: var(--accent); }

.subtitle { font-size: 0.8rem; color: var(--muted); margin-bottom: 2rem; }

label { display: block; font-size: 0.85rem; margin-bottom: 0.4rem; color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=date] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

input:focus { outline: none; border-color: var(--accent); }

/* The calendar glyph is the only clickable part of a date field, but by
 * default it is a bare icon with no affordance — easy to miss entirely. Give
 * it a chip background and a hover state so it reads as a button. */
input[type=date]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  opacity: 1;
  padding: 2px;
  margin-left: 0.25rem;
  border-radius: 4px;
  background-color: var(--bg-bar);
}

input[type=date]::-webkit-calendar-picker-indicator:hover,
input[type=date]::-webkit-calendar-picker-indicator:focus {
  background-color: var(--bg-bar-fut);
}

button {
  width: 100%;
  padding: 0.65rem;
  background: var(--btn-bg);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}

button:hover { background: var(--btn-hover); }

/* Login / register / forgot stack their fields with generous spacing. */
.auth-form input { margin-bottom: 1.25rem; }

/* Setup labels sit above tightly-packed fields instead. */
.setup-form label { margin-top: 1rem; margin-bottom: 0.3rem; }
.setup-form label:first-of-type { margin-top: 0; }
.setup-form button { margin-top: 1.5rem; }

.error {
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  border-radius: 6px;
  color: var(--err-fg);
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.success {
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: 6px;
  color: var(--ok-fg);
  padding: 0.75rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.key {
  display: block;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  font-size: 1.05rem;
  word-break: break-all;
  margin-bottom: 1rem;
}

.hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.hint-block { font-size: 0.8rem; color: var(--muted); margin-bottom: 1rem; margin-top: 0; }

.back {
  display: block;
  text-align: center;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}

.back:hover { color: var(--text); }
.back.tight { margin-top: 0.5rem; }

/* ── Dashboard ───────────────────────────────────────────────────────────── */

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

header h1 { font-size: 1.1rem; color: var(--accent); }
header a { font-size: 0.8rem; color: var(--muted); text-decoration: none; }
header a:hover { color: var(--text); }
header a.brand { font-size: inherit; }
header a.brand h1 { transition: opacity 0.15s; }
header a.brand:hover h1 { opacity: 0.75; }

.header-car { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.header-car h1 { margin: 0; white-space: nowrap; }

.car-selector-form { min-width: 0; }

.car-selector {
  max-width: 18rem;
  padding: 0.35rem 2rem 0.35rem 0.55rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.car-selector:focus { outline: none; border-color: var(--accent); }

header a.add-car {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8rem;
  height: 1.8rem;
  flex: 0 0 1.8rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 1.2rem;
  line-height: 1;
}

header a.add-car:hover { background: var(--accent); color: #fff; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header-actions { display: flex; align-items: center; gap: 1rem; }
.header-email { font-size: 0.8rem; color: var(--muted); }

@media (max-width: 720px) {
  header { padding: 0.65rem 0.75rem; gap: 0.75rem; }
  .header-car { flex: 1; }
  .header-car .brand { display: none; }
  .car-selector { width: 100%; max-width: none; }
  .header-email { display: none; }
  .header-actions { gap: 0.5rem; }
}

/* Signing out changes server state, so it is a POST form styled to match the
 * links beside it rather than an anchor. */
.signout-form { width: auto; }

.signout {
  width: auto;
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.signout:hover { background: transparent; color: var(--text); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 720px) { main { grid-template-columns: 1fr; } }

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

.panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.3rem 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-sub);
}

.info-row:last-child { border-bottom: none; }
.info-row span:first-child { color: var(--muted); flex-shrink: 0; margin-right: 1rem; }
.info-row span:last-child { font-weight: bold; }

.info-row input[type=text],
.info-row input[type=number],
.info-row input[type=date] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: bold;
  padding: 0.15rem 0.4rem;
  text-align: right;
  width: 10rem;
}

.info-row .computed { color: var(--muted); font-size: 0.85rem; font-weight: normal; }

.edit-toggle {
  width: auto;
  font-size: 0.75rem;
  padding: 0.2rem 0.65rem;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
}

.edit-toggle:hover { background: var(--accent); color: #fff; }

.config-save {
  margin-top: 1rem;
  width: 100%;
  padding: 0.55rem;
  background: var(--btn-bg);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.config-save:hover { background: var(--btn-hover); }

.bar-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; font-size: 0.85rem; }
.bar-label { width: 3.5rem; text-align: right; color: var(--muted); flex-shrink: 0; }
.bar-track { flex: 1; background: var(--bg-bar); border-radius: 3px; height: 18px; display: flex; }
.bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.bar-fill.ok      { background: var(--green); }
.bar-fill.over    { background: var(--red); }
.bar-fill.current { background: var(--yellow); border-radius: 3px 0 0 3px; }
.bar-fill.future  { background: var(--bg-bar-fut); }
.bar-fill.proj    { background: var(--yellow); opacity: 0.35; border-radius: 0 3px 3px 0; }
.bar-km { width: 5.5rem; text-align: right; color: var(--muted); font-size: 0.8rem; flex-shrink: 0; }

.proj-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .proj-grid { grid-template-columns: 1fr; } }
.proj-card { background: var(--bg); border: 1px solid var(--border-sub); border-radius: 6px; padding: 1rem; }
.proj-label { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.4rem; }
.proj-val { font-size: 1.5rem; font-weight: bold; margin-bottom: 0.25rem; }
.proj-sub { color: var(--muted); font-size: 0.78rem; }
.proj-empty { color: var(--muted); font-size: 0.85rem; }

.green { color: var(--green); }
.red   { color: var(--red); }

.records-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.records-table th {
  color: var(--muted);
  font-weight: normal;
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.records-table td { padding: 0.35rem 0.4rem; border-bottom: 1px solid var(--border-sub); }
.records-table tr:last-child td { border-bottom: none; }
.record-action { width: 1%; text-align: right; white-space: nowrap; }
.record-delete-form { margin: 0; }
.delete-record {
  width: auto;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--red);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.delete-record:hover { opacity: 0.7; }

.delta.pos { color: var(--green); }
.delta.neg { color: var(--red); }

.span-full { grid-column: 1 / -1; }

.error-box {
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  border-radius: 6px;
  color: var(--err-fg);
  padding: 1rem;
}

.error-box.inline { padding: 0.6rem 0.75rem; font-size: 0.85rem; margin-bottom: 1rem; }

.success-box {
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: 6px;
  color: var(--ok-fg);
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.record-form input[type=number], .record-form input[type=date] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.record-form label { font-size: 0.8rem; color: var(--muted); display: block; margin-bottom: 0.3rem; }

.record-form button {
  width: 100%;
  padding: 0.6rem;
  background: var(--btn-bg);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.record-form button:hover { background: var(--btn-hover); }

/* Reserves the space a fixed preview banner covers on the centred pages. */
.banner-spacer { height: 1.8rem; }
