:root {
    --teal: #0D9488;
    --teal-dark: #0F766E;
    --teal-deep: #115E59;
    --teal-tint: #E6F7F3;
    --ink: #0F172A;
    --muted: #64748B;
    --line: #E3EBE8;
    --line-soft: #F0F5F3;
    --bg: #F4F7F6;
    --white: #fff;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -18px rgba(15, 23, 42, .25);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--teal-dark); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.01em; }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 256px;
    flex: 0 0 256px;
    background: var(--white);
    border-right: 1px solid var(--line);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px;
    background: linear-gradient(135deg, #14B8A6, var(--teal-dark));
    color: #fff; font-weight: 800; font-size: 18px;
    display: grid; place-items: center;
    box-shadow: 0 6px 14px -8px rgba(13, 148, 136, .9);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 16px; letter-spacing: .02em; }
.brand-text small { font-size: 11px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 10px;
    color: #475569; font-size: 14px; font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.nav-link svg { width: 19px; height: 19px; flex: 0 0 19px; opacity: .85; }
.nav-link:hover { background: var(--line-soft); color: var(--ink); }
.nav-link.active { background: var(--teal-tint); color: var(--teal-deep); font-weight: 600; }
.nav-link.active svg { opacity: 1; }

.sidebar-foot { border-top: 1px solid var(--line-soft); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.who { display: flex; align-items: center; gap: 10px; padding: 6px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--teal-tint); color: var(--teal-deep);
    display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.who-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.who-text strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small { font-size: 11.5px; color: var(--muted); }
.nav-link.logout { color: #B91C1C; }
.nav-link.logout:hover { background: #FEF2F2; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 18px 28px;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar .sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.scope-chip {
    font-size: 12.5px; font-weight: 600; color: var(--teal-deep);
    background: var(--teal-tint); border: 1px solid #CDEDE5;
    padding: 6px 12px; border-radius: 999px; white-space: nowrap;
}

.hamburger { display: none; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; cursor: pointer; }
.hamburger span { display: block; width: 16px; height: 2px; background: #334155; margin: 3px 0; border-radius: 2px; }
.scrim { display: none; }

.content { padding: 26px 28px 48px; max-width: 1240px; width: 100%; }

/* ---------- Cards & grid ---------- */
.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; font-weight: 700; }
.card-head p { margin: 3px 0 0; font-size: 13px; color: var(--muted); }

.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stat { display: flex; align-items: center; gap: 14px; }
.stat-icon {
    width: 44px; height: 44px; border-radius: 12px; flex: 0 0 44px;
    display: grid; place-items: center;
    background: var(--teal-tint); color: var(--teal-deep);
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-body { display: flex; flex-direction: column; }
.stat-body small { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stat-body strong { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    padding: 9px 16px; border-radius: 10px;
    font-size: 14px; font-weight: 600; font-family: inherit;
    border: 1px solid transparent; cursor: pointer;
    transition: filter .15s ease, background .15s ease;
    white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg, #14B8A6, var(--teal-dark)); color: #fff; box-shadow: 0 8px 18px -12px rgba(13, 148, 136, .95); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: #fff; border-color: var(--line); color: #334155; }
.btn-ghost:hover { background: var(--line-soft); }
.btn-danger { background: #FEF2F2; border-color: #FECACA; color: #B91C1C; }
.btn-danger:hover { background: #FEE2E2; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-link { background: none; border: none; color: var(--teal-dark); font-weight: 600; font-size: 13.5px; cursor: pointer; padding: 0; font-family: inherit; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="file"], select, textarea {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 10px;
    font-size: 14px; font-family: inherit; color: var(--ink);
    background: #fff; outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="file"] { padding: 8px 10px; background: #FAFCFB; }
input:focus, select:focus, textarea:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, .14);
}
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }
textarea { resize: vertical; min-height: 74px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-soft); }

.filters { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; margin-bottom: 20px; }

/* ---------- Table ---------- */
.table-wrap {
    background: #fff; border: 1px solid var(--line);
    border-radius: var(--radius); overflow: auto;
    box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
    text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); font-weight: 700;
    background: #FAFCFB; padding: 12px 16px;
    border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFCFB; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
.cell-strong { font-weight: 600; }

/* ---------- Badges & flash ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: #ECFDF5; color: #047857; }
.badge.warn { background: #FFFBEB; color: #B45309; }
.badge.bad { background: #FEF2F2; color: #B91C1C; }
.badge.neutral { background: #F1F5F9; color: #475569; }
.badge.teal { background: var(--teal-tint); color: var(--teal-deep); }

.flash {
    padding: 12px 16px; border-radius: 11px; font-size: 14px; font-weight: 500;
    margin-bottom: 18px; border: 1px solid transparent;
}
.flash.success { background: #ECFDF5; border-color: #A7F3D0; color: #047857; }
.flash.error { background: #FEF2F2; border-color: #FECACA; color: #B91C1C; }
.flash.info { background: #EFF6FF; border-color: #BFDBFE; color: #1D4ED8; }

/* ---------- Misc ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { font-size: 18px; font-weight: 700; }
.page-head p { margin: 4px 0 0; font-size: 13.5px; color: var(--muted); }

.empty { text-align: center; padding: 46px 24px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 6px; }

.bar-row { display: grid; grid-template-columns: 96px 1fr 56px; align-items: center; gap: 12px; margin-bottom: 12px; font-size: 13.5px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-track { background: var(--line-soft); border-radius: 999px; height: 9px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #2DD4BF, var(--teal-dark)); }
.bar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.list-plain { margin: 0; padding: 0; list-style: none; }
.list-plain li { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.list-plain li:last-child { border-bottom: none; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 34px; height: 34px; padding: 0 10px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); border-radius: 9px; background: #fff;
    font-size: 13.5px; color: #334155; font-weight: 500;
}
.pagination .current { background: var(--teal-tint); border-color: #CDEDE5; color: var(--teal-deep); font-weight: 700; }
.pagination .disabled { opacity: .45; }

/* ---------- Login ---------- */
.login-shell {
    min-height: 100vh; display: grid; place-items: center; padding: 24px;
    background:
        radial-gradient(900px 520px at 12% 8%, #D7F5EE 0%, transparent 60%),
        radial-gradient(700px 420px at 92% 92%, #E3F2F0 0%, transparent 55%),
        var(--bg);
}
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: 0 24px 60px -34px rgba(15, 23, 42, .45); }
.login-head { text-align: center; margin-bottom: 26px; }
.login-head .brand-mark { margin: 0 auto 14px; width: 46px; height: 46px; font-size: 21px; border-radius: 13px; }
.login-head h1 { font-size: 20px; }
.login-head p { margin: 6px 0 0; font-size: 13.5px; color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 15px; }
.login-card .btn { width: 100%; padding: 11px 16px; }
.login-foot { margin-top: 22px; text-align: center; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
    .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; height: 100vh;
        transform: translateX(-105%); transition: transform .22s ease;
        box-shadow: 0 20px 50px -20px rgba(15, 23, 42, .4);
    }
    .sidebar.open { transform: translateX(0); }
    .hamburger { display: block; }
    .scrim.show { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 35; }
    .content { padding: 20px 16px 40px; }
    .topbar { padding: 14px 16px; }
    .topbar .sub { display: none; }
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
    .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
    .kv { grid-template-columns: 120px 1fr; }
}
