:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe3ee;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --primary-soft: #eaf2ff;
  --success: #16a34a;
  --success-soft: #ecfdf3;
  --warning: #d97706;
  --warning-soft: #fff7ed;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --sidebar: #0f172a;
  --sidebar-2: #162033;
  --shadow: 0 18px 50px rgba(15, 23, 42, .10);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 10% 10%, rgba(37, 99, 235, .20), transparent 34%),
    radial-gradient(circle at 90% 80%, rgba(14, 165, 233, .13), transparent 30%),
    #0b1220;
  position: relative;
}
.login-card {
  width: min(460px, 100%);
  background: rgba(255,255,255,.98);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 30px 90px rgba(0,0,0,.30);
  border-radius: 24px;
  padding: 34px;
}
.login-heading { margin: 34px 0 28px; }
.login-heading h1 { margin: 6px 0 8px; font-size: 34px; letter-spacing: -.03em; }
.login-heading p { margin: 0; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 8px; font-size: 13px; font-weight: 700; color: #334155; }
.login-form input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.login-form input:focus { border-color: #93b4ff; box-shadow: 0 0 0 4px rgba(37,99,235,.10); }
.login-foot { position: absolute; bottom: 18px; color: #71809a; font-size: 12px; }
.form-error { padding: 11px 12px; border-radius: 10px; background: var(--danger-soft); color: #991b1b; font-size: 13px; }

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  border-radius: 12px; font-weight: 900; letter-spacing: -.04em;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff;
  box-shadow: 0 8px 24px rgba(37,99,235,.24);
}
.brand-name { font-size: 18px; font-weight: 850; letter-spacing: -.02em; }
.brand-subtitle { font-size: 11px; color: #93a4bd; text-transform: uppercase; letter-spacing: .12em; margin-top: 1px; }
.brand-login .brand-name { color: #0f172a; }
.brand-login .brand-subtitle { color: #64748b; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0,1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 22px 16px 16px;
  background: linear-gradient(180deg, var(--sidebar), #0b1323);
  color: #fff; display: flex; flex-direction: column; justify-content: space-between;
}
.sidebar .brand { padding: 0 8px 22px; }
.nav { display: grid; gap: 6px; margin-top: 12px; }
.nav-item {
  width: 100%; border: 0; color: #9fb0c8; background: transparent;
  display: flex; align-items: center; gap: 12px; padding: 11px 12px;
  border-radius: 11px; text-align: left; font-weight: 700;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: #1e2b43; box-shadow: inset 3px 0 0 #3b82f6; }
.nav-icon { width: 22px; text-align: center; font-size: 17px; opacity: .9; }
.sidebar-user {
  display: grid; grid-template-columns: 38px 1fr 34px; align-items: center; gap: 9px;
  padding: 12px 9px; border-radius: 12px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.06);
}
.avatar { width: 36px; height: 36px; display: grid; place-items: center; background: #233551; border-radius: 50%; font-weight: 900; }
.sidebar-user-text { min-width: 0; display: grid; gap: 2px; }
.sidebar-user-text strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-text span { color: #8ea0ba; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.icon-btn { border: 0; background: transparent; color: inherit; border-radius: 9px; width: 34px; height: 34px; font-size: 20px; }
.icon-btn:hover { background: rgba(255,255,255,.08); }

.main { min-width: 0; }
.topbar {
  height: 88px; display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 0 30px; background: rgba(255,255,255,.91); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px);
}
.topbar h1 { margin: 3px 0 0; font-size: 24px; letter-spacing: -.025em; }
.eyebrow { color: var(--primary); text-transform: uppercase; letter-spacing: .11em; font-size: 10px; font-weight: 900; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.company-chip { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 999px; background: #f8fafc; border: 1px solid var(--border); font-size: 12px; font-weight: 700; color: #475569; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(22,163,74,.12); }
.content { padding: 26px 30px 42px; }

.btn { border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; font-weight: 800; font-size: 13px; transition: transform .1s ease, background .15s ease, border-color .15s ease; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { background: #fff; color: #334155; border-color: var(--border); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; padding-block: 13px; }
.btn-sm { padding: 8px 10px; font-size: 12px; }

.grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat-card, .panel, .company-card, .template-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(15,23,42,.02);
}
.stat-card { padding: 19px; }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 900; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 800; }
.stat-value { font-size: 30px; font-weight: 900; letter-spacing: -.04em; margin-top: 14px; }
.stat-foot { color: var(--muted); font-size: 11px; margin-top: 5px; }

.panel { overflow: hidden; }
.panel-header { min-height: 62px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.panel-header h2, .panel-header h3 { margin: 0; font-size: 16px; }
.panel-subtitle { color: var(--muted); font-size: 12px; margin-top: 3px; }
.panel-body { padding: 18px; }
.section-gap { margin-top: 20px; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { min-width: 250px; flex: 1; max-width: 420px; }
.input, .select {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; background: #fff;
  padding: 10px 12px; outline: none; color: var(--text);
}
.input:focus, .select:focus { border-color: #93b4ff; box-shadow: 0 0 0 4px rgba(37,99,235,.08); }

.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: #64748b; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; padding: 11px 14px; background: #f8fafc; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid #edf1f5; vertical-align: middle; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f8fbff; }
tbody tr.clickable { cursor: pointer; }
.plate { font-weight: 900; letter-spacing: .03em; }
.muted { color: var(--muted); }
.small { font-size: 11px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 900; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.badge-success { color: #166534; background: var(--success-soft); }
.badge-muted { color: #475569; background: #eef2f7; }
.badge-blue { color: #1d4ed8; background: var(--primary-soft); }
.badge-warning { color: #9a3412; background: var(--warning-soft); }

.company-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
.company-card { padding: 18px; cursor: pointer; transition: transform .13s ease, box-shadow .13s ease, border-color .13s ease; }
.company-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: #b7c7dc; }
.company-card h3 { margin: 14px 0 4px; font-size: 16px; }
.company-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.company-code { font-size: 11px; font-weight: 900; color: #64748b; background: #f1f5f9; padding: 5px 7px; border-radius: 7px; }

.template-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
.template-card { padding: 18px; }
.template-card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.template-card h3 { margin: 0; font-size: 16px; }
.template-code { color: var(--primary); font-size: 10px; font-weight: 900; letter-spacing: .08em; margin-top: 4px; }
.template-desc { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 12px 0; min-height: 36px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; padding: 5px 8px; border-radius: 8px; background: #f1f5f9; color: #475569; font-size: 10px; font-weight: 800; }
.template-footer { margin-top: 14px; padding-top: 12px; border-top: 1px solid #edf1f5; display: grid; gap: 5px; font-size: 11px; color: #64748b; }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: #334155; margin-bottom: 4px; }
.loading { min-height: 180px; display: grid; place-items: center; color: var(--muted); }
.spinner { width: 26px; height: 26px; border: 3px solid #dbeafe; border-top-color: var(--primary); border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.58); z-index: 100; display: grid; place-items: center; padding: 22px; backdrop-filter: blur(3px); }
.modal { width: min(1040px, 100%); max-height: calc(100vh - 44px); background: #f8fafc; border-radius: 20px; overflow: hidden; box-shadow: 0 30px 100px rgba(0,0,0,.28); }
.modal-header { height: 80px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; background: #fff; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 3px 0 0; font-size: 22px; }
.modal-close { color: #475569; font-size: 26px; }
.modal-close:hover { background: #f1f5f9; }
.modal-body { padding: 20px; overflow: auto; max-height: calc(100vh - 124px); }

.vehicle-summary { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; }
.config-hero { background: linear-gradient(135deg,#0f172a,#1e293b); color: #fff; border-radius: 16px; padding: 20px; }
.config-hero .eyebrow { color: #93c5fd; }
.config-hero h3 { margin: 6px 0 3px; font-size: 24px; }
.config-hero p { margin: 0; color: #aebbd0; font-size: 12px; }
.config-hero-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.hero-pill { padding: 7px 9px; border-radius: 8px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.08); font-size: 11px; font-weight: 800; }
.apply-card { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
.apply-card h3 { margin: 0 0 4px; font-size: 15px; }
.apply-card p { margin: 0 0 14px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.apply-actions { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.config-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; margin-top: 16px; }
.config-box { background: #fff; border: 1px solid var(--border); border-radius: 15px; overflow: hidden; }
.config-box-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 15px; border-bottom: 1px solid var(--border); }
.config-box-head h4 { margin: 0; font-size: 13px; }
.config-list { padding: 5px 0; }
.config-row { min-height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 15px; border-bottom: 1px solid #f0f3f7; }
.config-row:last-child { border-bottom: 0; }
.config-row-main { min-width: 0; }
.config-row-title { font-size: 12px; font-weight: 800; }
.config-row-sub { font-size: 10px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.tank-card { margin: 10px 12px; border: 1px solid var(--border); border-radius: 11px; padding: 12px; background: #fbfdff; }
.tank-top { display: flex; justify-content: space-between; gap: 10px; }
.tank-title { font-weight: 900; font-size: 12px; }
.tank-details { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 10px; }
.tank-kv { padding: 8px; border-radius: 8px; background: #f1f5f9; }
.tank-kv span { display: block; font-size: 9px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tank-kv strong { display: block; margin-top: 2px; font-size: 11px; }
.calibration { margin-top: 10px; font-size: 10px; color: var(--muted); }

.toast-host { position: fixed; right: 20px; top: 20px; z-index: 200; display: grid; gap: 10px; width: min(360px, calc(100vw - 40px)); }
.toast { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 11px; padding: 12px 14px; box-shadow: var(--shadow); font-size: 12px; animation: toastIn .18s ease; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast strong { display: block; margin-bottom: 2px; }
@keyframes toastIn { from { transform: translateY(-6px); opacity: 0; } }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .company-grid, .template-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .vehicle-summary { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 12px; }
  .sidebar-top { display: flex; align-items: center; gap: 10px; }
  .sidebar .brand { padding: 0; min-width: 158px; }
  .sidebar .brand-subtitle { display: none; }
  .nav { margin: 0; display: flex; overflow-x: auto; }
  .nav-item { width: auto; white-space: nowrap; padding: 9px 10px; }
  .nav-item span:last-child { display: none; }
  .sidebar-user { display: none; }
  .topbar { height: auto; padding: 16px; position: static; align-items: flex-end; }
  .topbar-actions { flex-direction: column; align-items: flex-end; }
  .company-chip { display: none; }
  .content { padding: 16px; }
  .stats-grid, .company-grid, .template-grid, .config-grid { grid-template-columns: 1fr; }
  .search { min-width: 100%; max-width: none; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal { max-height: 100vh; border-radius: 0; }
  .modal-body { max-height: calc(100vh - 80px); }
  .apply-actions { grid-template-columns: 1fr; }
  .tank-details { grid-template-columns: 1fr; }
}
