:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1f2733; --muted: #7a8595;
  --line: #e3e8ef; --brand: #2563eb; --brand-d: #1d4ed8;
  --green: #d6f5dd; --green-i: #137a3a; --yellow: #fdf3c9; --yellow-i: #8a6d00;
  --red: #fde2e1; --red-i: #b42318; --shadow: 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--red-i); margin-top: 8px; min-height: 18px; font-size: 13px; }
button { cursor: pointer; font-family: inherit; }

/* Prisijungimas */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg,#1e3a8a,#2563eb); }
.login-card { background: var(--panel); padding: 32px; border-radius: 14px; width: 340px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: block; margin: 16px 0 0; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.login-card button[type=submit] { width: 100%; margin-top: 20px; padding: 11px; background: var(--brand); color: #fff; border: 0; border-radius: 8px; font-size: 15px; font-weight: 600; }
.login-card button[type=submit]:hover { background: var(--brand-d); }

/* Karkasas */
.topbar { display: flex; align-items: center; gap: 24px; background: var(--panel); border-bottom: 1px solid var(--line); padding: 0 20px; height: 56px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tab { background: transparent; border: 0; padding: 8px 16px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 500; }
.tab.active { background: #eef2ff; color: var(--brand-d); }
.user { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.ghost { background: transparent; border: 1px solid var(--line); padding: 7px 12px; border-radius: 8px; color: var(--ink); }
.ghost:hover { background: #f0f3f8; }

.layout { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 12px; }
.sidebar-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; }
.veh-list { list-style: none; margin: 0; padding: 0; }
.veh-list li { padding: 9px 10px; border-radius: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.veh-list li:hover { background: #f0f3f8; }
.veh-list li.active { background: #eef2ff; }
.veh-list li.inactive .plate { color: #9aa3b0; }
.veh-list li.inactive .loc { color: #c2c8d0; }
.veh-list .plate { font-weight: 600; }
.veh-list .loc { font-size: 12px; color: var(--muted); }

.content { padding: 20px; overflow: auto; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.view-head h2 { margin: 0; font-size: 18px; }
.period-bar { display: flex; align-items: center; gap: 10px; }
.period-bar select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

/* Lentelės */
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.grid { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }
.grid th { background: #f7f9fc; text-align: left; padding: 9px 10px; border-bottom: 2px solid var(--line); position: sticky; top: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); }
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
.grid tbody tr:hover td, .grid tr:hover td { background: #fafbfd; }
.grid.editable td.cell-input { padding: 0; }
.grid.editable input { width: 100%; min-width: 70px; border: 0; background: transparent; padding: 7px 10px; font: inherit; color: inherit; }
.grid.editable input:focus { outline: 2px solid var(--brand); outline-offset: -2px; background: #fff; border-radius: 4px; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .row-del { color: var(--muted); border: 0; background: transparent; font-size: 16px; padding: 2px 6px; }
.grid .row-del:hover { color: var(--red-i); }
.cell.g { background: var(--green); color: var(--green-i); font-weight: 600; }
.cell.y { background: var(--yellow); color: var(--yellow-i); font-weight: 600; }
.cell.r { background: var(--red); color: var(--red-i); font-weight: 600; }
.grid tr.inactive td:not(.cell) { color: #aab2bd; }
.grid tr.inactive .plate-link { color: #9aa3b0; }
.plate-link { color: var(--brand); font-weight: 600; cursor: pointer; }
.plate-link:hover { text-decoration: underline; }

.trips-grid-wrap { margin-bottom: 8px; }
#addTrip, #addPeriod { margin-top: 8px; }

/* Parametrai + metrikos */
.period-panel { margin-top: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); }
.period-panel h3 { margin: 6px 0 10px; font-size: 14px; }
.param-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.param-fields label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
.param-fields input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; color: var(--ink); }
.param-fields input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 4px; }
.metric { background: #f7f9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.metric .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.metric .v { font-size: 18px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3); font-size: 14px; z-index: 50; }

/* Rolės ženkliukas */
.role-badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: #eef2ff; color: var(--brand-d); text-transform: uppercase; letter-spacing: .03em; }
.role-badge.admin { background: #fde7d6; color: #b45309; }
.role-badge.dispatcher { background: #e0f0ff; color: #1d4ed8; }
.role-badge.driver { background: #e6f6ec; color: #137a3a; }
.readonly-note { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }

/* Vartotojų forma */
.user-form-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 18px; max-width: 760px; }
.user-form-card h3 { margin: 0 0 12px; font-size: 15px; }
.user-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.user-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 5px; }
.user-form input, .user-form select { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; color: var(--ink); }
.user-form-actions { display: flex; gap: 8px; grid-column: 1 / -1; }
.user-form-actions button[type=submit] { background: var(--brand); color: #fff; border: 0; padding: 9px 18px; border-radius: 8px; font-weight: 600; }
.user-form-actions button[type=submit]:hover { background: var(--brand-d); }
.btn-link { background: transparent; border: 0; color: var(--brand); cursor: pointer; padding: 2px 6px; font-size: 13px; }
.btn-link.danger { color: var(--red-i); }
.btn-link:hover { text-decoration: underline; }

/* Analizė */
.analytics-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { background: transparent; border: 0; padding: 7px 14px; font-size: 13px; color: var(--muted); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--brand); color: #fff; font-weight: 600; }
.an-veh { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.an-veh select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
#anCards { margin-bottom: 16px; }
.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px 10px; box-shadow: var(--shadow); margin-bottom: 16px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.chart-head h3 { margin: 0; font-size: 14px; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.chart-legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { width: 100%; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-val { font-size: 11px; fill: var(--ink); font-variant-numeric: tabular-nums; }
.chart-xlbl { font-size: 11px; fill: var(--muted); }
#anTable .cell.g, #cmpTable .cell.g { background: var(--green); color: var(--green-i); }
#anTable .cell.y, #cmpTable .cell.y { background: var(--yellow); color: var(--yellow-i); }
#anTable .cell.r, #cmpTable .cell.r { background: var(--red); color: var(--red-i); }

/* Mašinų palyginimas */
.cmp-best { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.cmp-best-card { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; box-shadow: var(--shadow); min-width: 180px; }
.cmp-best-card.top { border-color: #f5c518; background: linear-gradient(180deg,#fffdf3,#fff); }
.cmp-trophy { font-size: 26px; }
.cmp-best-k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.cmp-best-v { font-size: 19px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
