*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    background-image:
        radial-gradient(1100px 600px at 0% -10%, rgba(22, 163, 74, 0.12), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, rgba(245, 158, 11, 0.08), transparent 60%);
    background-attachment: fixed;
}
h1, h2, h3 { margin: 0 0 6px; letter-spacing: -0.01em; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 700; }
p { margin: 0 0 8px; }
.muted { color: var(--text-muted); }
.block { display: block; }
.hint { font-size: 13px; color: var(--text-muted); }
.skip-link { position: absolute; left: -999px; }
.skip-link:focus { left: 12px; top: 12px; background: var(--surface-solid); padding: 8px 12px; z-index: 99; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.glass {
    background: var(--surface);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius-lg);
}

/* Boot and login */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot__mark img { width: 140px; animation: pulse 1.6s ease-in-out infinite; }
.login-root { min-height: 100vh; }
.login { position: relative; min-height: 100vh; display: grid; place-items: center; overflow: hidden; padding: 24px; }
.login__mesh {
    position: absolute; inset: -20%;
    background:
        radial-gradient(circle at 20% 30%, rgba(22, 163, 74, 0.45), transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(245, 158, 11, 0.35), transparent 40%),
        radial-gradient(circle at 60% 20%, rgba(163, 230, 53, 0.35), transparent 35%);
    filter: blur(50px);
    animation: drift 16s ease-in-out infinite alternate;
    z-index: 0;
}
.login__card { position: relative; z-index: 1; width: min(420px, 100%); padding: 32px; animation: rise 0.6s both; }
.login__logo { width: 180px; margin-bottom: 18px; }
.login__card .link { margin-top: 12px; }

/* App shell */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar {
    position: sticky; top: 12px; height: calc(100vh - 24px); margin: 12px;
    display: flex; flex-direction: column; overflow: auto; padding: 16px 12px; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; text-decoration: none; color: inherit; }
.brand img { width: 44px; height: 44px; object-fit: contain; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--text-muted); font-size: 12px; }
.nav__title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 14px 10px 6px; }
.nav__item {
    position: relative; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: 12px; color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: 14px;
    transition: background 0.2s, color 0.2s, transform 0.2s;
}
.nav__item:hover { background: rgba(22, 163, 74, 0.08); color: var(--text); transform: translateX(2px); }
.nav__item.is-active { color: var(--brand-700); background: rgba(22, 163, 74, 0.12); }
.nav__item.is-active::before {
    content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px;
    border-radius: 4px; background: var(--grad-brand); animation: grow 0.35s ease both;
}
.nav__item em { margin-left: auto; font-style: normal; font-size: 10px; padding: 2px 6px; border-radius: 999px; background: var(--border); }
.sidebar__foot { margin-top: auto; padding: 12px 8px; color: var(--text-muted); font-size: 12px; }

.main { min-width: 0; padding: 0 16px 100px 0; }
.topbar {
    position: sticky; top: 12px; z-index: 20; margin: 12px 12px 0 0;
    display: flex; align-items: center; gap: 12px; padding: 10px 14px;
}
.search {
    flex: 1; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    border-radius: 12px; background: var(--surface-solid); border: 1px solid var(--border); color: var(--text-muted);
}
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; }
.topbar__right { display: flex; align-items: center; gap: 8px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
    background: var(--grad-brand); color: #fff; font-weight: 700; font-size: 13px;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin: 16px 12px 0 4px; }
.crumbs a { color: var(--text-muted); text-decoration: none; }
.crumbs .ico { width: 14px; height: 14px; }
.view { padding: 12px 12px 0 4px; }
.view.enter { animation: pageIn 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.eyebrow { text-transform: uppercase; font-size: 12px; letter-spacing: 0.08em; color: var(--brand-500); font-weight: 700; margin-bottom: 4px; }
.menu-btn, .only-mobile { display: none; }

/* Buttons and icon buttons */
.btn {
    position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: 12px; border: 0; font: inherit; font-weight: 600; cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--grad-brand); color: #fff; box-shadow: 0 8px 20px -8px rgba(22, 163, 74, 0.6); }
.btn--ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn--ghost:hover { background: rgba(22, 163, 74, 0.08); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }
.btn--sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn::after {
    content: ''; position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.5); transform: translate(-50%, -50%) scale(0); opacity: 0; pointer-events: none;
}
.btn:active::after { transform: translate(-50%, -50%) scale(30); opacity: 1; transition: transform 0.5s, opacity 0.6s; }

.icon-btn {
    width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 12px;
    border: 1px solid var(--border); background: var(--surface-solid); color: var(--text); cursor: pointer;
    transition: transform 0.15s, color 0.2s;
}
.icon-btn:hover { transform: translateY(-1px); color: var(--brand-500); }
.icon-btn.danger:hover { color: var(--danger); }
.link { background: none; border: 0; color: var(--brand-700); font: inherit; font-weight: 600; cursor: pointer; padding: 6px 0; }
.link:hover { text-decoration: underline; }

/* Floating-label fields */
.field { position: relative; margin-bottom: 16px; }
.field input, .field select {
    width: 100%; min-height: 52px; padding: 18px 14px 6px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--surface-solid); color: var(--text);
    font: inherit; font-size: 15px; outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus, .field select:focus { border-color: var(--brand-500); box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.15); }
.field label {
    position: absolute; left: 14px; top: 16px; color: var(--text-muted); font-size: 15px;
    pointer-events: none; transition: top 0.2s, font-size 0.2s, color 0.2s;
}
.field input:not(:placeholder-shown) + label,
.field input:focus + label,
.field input[type="date"] + label,
.field select + label { top: 6px; font-size: 11px; color: var(--brand-500); }
.field--wide { grid-column: 1 / -1; }
.field--sm { min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-section { grid-column: 1 / -1; margin: 10px 0 6px; font-size: 14px; color: var(--brand-700); font-weight: 700; }
.form-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; margin-top: 8px; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1.3em; margin: 0 0 12px; }
.shake { animation: shake 0.4s; }
.select { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; color: var(--text-muted); }
.select select {
    min-width: 220px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
    background: var(--surface-solid); color: var(--text); font: inherit;
}

/* Tables */
.table-wrap {
    overflow: auto; max-height: 70vh; border-radius: var(--radius-md);
    border: 1px solid var(--border); background: var(--surface-solid);
}
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th {
    position: sticky; top: 0; z-index: 1; background: var(--surface-solid); text-align: left;
    padding: 12px 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background 0.2s; }
.table tbody tr:hover td { background: rgba(22, 163, 74, 0.05); }
.table .actions { text-align: right; white-space: nowrap; }
.table .empty { text-align: center; color: var(--text-muted); padding: 28px; }
.table small { font-size: 12px; }
.matrix .check { display: inline-flex; }

.check { display: inline-flex; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-500); cursor: pointer; }

/* Badges and pills */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    background: rgba(22, 163, 74, 0.12); color: var(--brand-700); font-size: 12px; font-weight: 600;
}
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; text-transform: capitalize; }
.pill--ok { background: rgba(22, 163, 74, 0.15); color: var(--brand-500); }
.pill--off { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); }

/* Tabs */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin: 18px 0; overflow-x: auto; }
.tab { position: relative; padding: 10px 14px; color: var(--text-muted); text-decoration: none; font-weight: 600; white-space: nowrap; transition: color 0.2s; }
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--brand-700); }
.tab.is-active::after {
    content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px;
    border-radius: 3px; background: var(--grad-brand); transform-origin: left; animation: grow 0.35s ease both;
}

/* Layout helpers */
.card { padding: 20px; animation: rise 0.5s both; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 { margin: 0; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 12px 0 16px; }
.inline-form .field { flex: 1; min-width: 180px; margin-bottom: 0; }
.inline-form .field--sm { flex: 0 0 160px; min-width: 0; }
.inline-form .btn { height: 52px; }
.notice-banner {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 16px;
    border-radius: 12px; background: rgba(245, 158, 11, 0.12); color: #92400E; font-size: 14px;
}
.notice-banner .ico { color: var(--amber); }
:root[data-theme="dark"] .notice-banner { color: #FCD34D; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }

/* Bento KPI grid */
.bento { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi {
    position: relative; padding: 20px; overflow: hidden; animation: rise 0.6s both;
    animation-delay: var(--d, 0ms); transition: transform 0.25s, box-shadow 0.25s;
}
.kpi:hover { transform: translateY(-4px); box-shadow: 0 18px 40px -16px rgba(11, 107, 58, 0.35); }
.kpi.skeleton { min-height: 140px; }
.kpi::after {
    content: ''; position: absolute; right: -36px; top: -36px; width: 120px; height: 120px; border-radius: 50%;
    background: radial-gradient(circle, rgba(22, 163, 74, 0.18), transparent 70%);
}
.kpi__icon {
    width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
    color: #fff; background: var(--grad-brand);
}
.kpi__icon .ico { width: 22px; height: 22px; }
.kpi.tone-lime .kpi__icon { background: linear-gradient(135deg, #65A30D, #A3E635); }
.kpi.tone-amber .kpi__icon { background: linear-gradient(135deg, #D97706, #FBBF24); }
.kpi.tone-sky .kpi__icon { background: linear-gradient(135deg, #0284C7, #38BDF8); }
.kpi p { margin: 14px 0 4px; color: var(--text-muted); font-size: 13px; font-weight: 600; }
.kpi strong { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi em { display: block; font-style: normal; font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Checklist and roadmap */
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checklist li {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--surface-solid); cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}
.checklist li:hover { transform: translateX(3px); border-color: rgba(22, 163, 74, 0.4); }
.checklist .mark {
    width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
    border: 2px solid var(--border); color: transparent;
}
.checklist .mark .ico { width: 14px; height: 14px; stroke-width: 3; }
.checklist li.done .mark { background: var(--brand-500); border-color: var(--brand-500); color: #fff; animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.checklist li.done > span:last-child { color: var(--text-muted); text-decoration: line-through; }
.roadmap { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.roadmap li {
    display: flex; gap: 12px; align-items: baseline; padding: 10px 12px; border-radius: 12px;
    background: var(--surface-solid); border: 1px dashed var(--border);
}
.roadmap b { color: var(--brand-700); min-width: 64px; font-size: 13px; }
.roadmap span { color: var(--text-muted); font-size: 14px; }

/* Empty states */
.empty-card { text-align: center; padding: 48px 24px; animation: rise 0.5s both; }
.empty-card h2 { margin: 14px 0 6px; }
.empty-card p { max-width: 460px; margin: 0 auto; }
.empty-art {
    width: 72px; height: 72px; margin: 0 auto; border-radius: 22px; display: grid; place-items: center;
    background: var(--grad-brand); color: #fff; box-shadow: var(--shadow);
}
.empty-art .ico { width: 34px; height: 34px; }

/* Roles and permission matrix */
.roles { display: grid; grid-template-columns: 260px 1fr; gap: 16px; align-items: start; }
.role-list { display: grid; gap: 6px; }
.role-item {
    display: flex; flex-direction: column; gap: 2px; text-align: left; width: 100%; padding: 12px;
    border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--text);
    font: inherit; cursor: pointer; transition: background 0.2s, border-color 0.2s, transform 0.2s;
}
.role-item:hover { transform: translateX(2px); background: var(--surface-solid); }
.role-item.is-active { background: var(--surface-solid); border-color: rgba(22, 163, 74, 0.45); box-shadow: 0 8px 20px -12px rgba(22, 163, 74, 0.5); }
.role-item small { color: var(--text-muted); font-size: 12px; line-height: 1.4; }
.role-matrix { min-width: 0; }
.role-matrix .table th { font-size: 11px; }
.role-matrix .table td:first-child { min-width: 180px; font-weight: 600; }

/* Toasts and modals */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: grid; gap: 10px; width: min(360px, calc(100vw - 32px)); }
.toast {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px;
    background: var(--surface-solid); border: 1px solid var(--border); box-shadow: var(--shadow);
    font-size: 14px; animation: slideIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.toast .ico { color: var(--brand-500); }
.toast--error .ico { color: var(--danger); }
.toast.out { animation: slideOut 0.3s ease forwards; }
.modal-wrap {
    position: fixed; inset: 0; z-index: 150; display: grid; place-items: center; padding: 16px;
    background: rgba(2, 8, 6, 0.45); backdrop-filter: blur(4px); opacity: 0; transition: opacity 0.25s;
}
.modal-wrap.open { opacity: 1; }
.modal { width: min(560px, 100%); padding: 20px; transform: translateY(24px) scale(0.96); transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
.modal-wrap.open .modal { transform: none; }
.modal header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal__body .form-grid { grid-template-columns: 1fr; }

/* Loaders */
.skeleton { position: relative; overflow: hidden; background: var(--surface-solid); border-radius: var(--radius-md); }
.skeleton::after {
    content: ''; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
    transform: translateX(-100%); animation: shimmer 1.4s infinite;
}
.skeleton.line { height: 16px; width: 60%; }

/* Mobile chrome (hidden on desktop) */
.scrim { display: none; }
.bottom-nav { display: none; }

/* Responsive */
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; height: 100%; width: 280px; margin: 0;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0; transform: translateX(-105%);
        transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    body.nav-open .sidebar { transform: none; }
    .scrim {
        display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.35);
        opacity: 0; pointer-events: none; transition: opacity 0.3s;
    }
    body.nav-open .scrim { opacity: 1; pointer-events: auto; }
    .menu-btn { display: inline-grid; }
    .main { padding: 0 12px 104px 0; }
    .topbar { margin: 10px 10px 0 0; padding: 8px 10px; gap: 8px; }
    .view { padding: 8px 10px 0 4px; }
    .bottom-nav {
        display: flex; position: fixed; left: 10px; right: 10px; z-index: 40; justify-content: space-around;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)); padding: 6px; border-radius: 18px;
    }
    .bottom-nav a {
        flex: 1; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 2px; font-size: 11px; font-weight: 600; color: var(--text-muted); text-decoration: none; border-radius: 12px;
    }
    .bottom-nav a .ico { width: 22px; height: 22px; }
    .bottom-nav a.is-active { color: var(--brand-700); background: rgba(22, 163, 74, 0.12); }
    .form-grid, .grid-2, .roles { grid-template-columns: 1fr; }
    .bento { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .kpi strong { font-size: 26px; }
    .table-wrap { max-height: none; }
    h1 { font-size: 22px; }
    .login__card { padding: 24px; }
}
@media (max-width: 560px) {
    .field input, .field select, .search input { font-size: 16px; }
    .inline-form .field, .inline-form .field--sm { flex: 1 1 100%; }
    .select select { min-width: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Keyframes */
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 0.9; } 50% { transform: scale(1.06); opacity: 1; } }
@keyframes drift { from { transform: translate3d(-3%, -2%, 0) rotate(0deg); } to { transform: translate3d(3%, 2%, 0) rotate(8deg); } }
@keyframes grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); }
    80% { transform: translateX(5px); }
}
@keyframes slideIn { from { opacity: 0; transform: translateX(40px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes slideOut { to { opacity: 0; transform: translateX(40px); } }
@keyframes pop { from { transform: scale(0.4); } to { transform: scale(1); } }
