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

:root {
    --sidebar-w: 240px;
    --sidebar-bg: #202124;
    --sidebar-text: #e8eaed;
    --sidebar-muted: #9aa0a6;
    --sidebar-hover: #3c4043;
    --sidebar-active-bg: #3d2d1a;
    --sidebar-active: #f89f56;
    --accent: #f89f56;
    --accent-hover: #bf7030;
    --bg: #f1f3f4;
    --card-bg: #fff;
    --border: #dadce0;
    --text: #202124;
    --text-muted: #5f6368;
    --positive: #137333;
    --negative: #c5221f;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body { font-family: 'Google Sans', Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
    z-index: 10;
}

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

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: var(--shadow);
    flex-wrap: wrap;
    min-height: 60px;
    padding: 10px 16px;
}

.content { flex: 1; overflow-y: auto; padding: 28px 32px; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-logo {
    padding: 18px 16px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #3c4043;
    letter-spacing: -.2px;
}

.sidebar-logo svg { flex-shrink: 0; }

.sidebar-section { padding: 12px 0 4px; }

.sidebar-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--sidebar-muted);
    padding: 0 16px 6px;
    text-transform: uppercase;
    letter-spacing: .8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    cursor: pointer;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    transition: background .1s;
    border-left: 3px solid transparent;
}

.sidebar-item:hover { background: var(--sidebar-hover); }

.sidebar-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
}

.sidebar-item .icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-user {
    margin-top: auto;
    padding: 14px 16px;
    border-top: 1px solid #3c4043;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-name { font-size: 12px; color: var(--sidebar-text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.logout-btn {
    background: none;
    border: none;
    color: var(--sidebar-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    display: flex;
    align-items: center;
}
.logout-btn:hover { color: var(--sidebar-text); }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar-title { font-size: 16px; font-weight: 600; color: var(--text); flex: 1; }

/* ── Page heading ────────────────────────────────────────────────────────── */
.page-heading { font-size: 20px; font-weight: 600; color: var(--text); margin-bottom: 24px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 14px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.chart-card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 20px 22px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.chart-card-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 16px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-card {
    background: var(--card-bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.table-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.table-header-title { font-size: 14px; font-weight: 600; color: var(--text); }

table { width: 100%; border-collapse: collapse; }

th {
    padding: 10px 20px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 11px 20px;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8f9fa; }

.td-num { text-align: center; }
th.th-center { text-align: center; }

/* ── Two-column layout ───────────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .3px; }
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    outline: none;
    transition: border-color .15s;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(248,159,86,.2); }
.form-control:disabled { opacity: .6; cursor: not-allowed; background: var(--bg); }

.form-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, box-shadow .15s;
    text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 1px 4px rgba(0,0,0,.2); }

.btn-secondary { background: #fff; color: var(--accent); border-color: var(--border); }
.btn-secondary:hover { background: #f8f9fa; }

.btn-danger { background: #fff; color: var(--negative); border-color: var(--border); }
.btn-danger:hover { background: #fce8e6; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: #fff;
    border-radius: 10px;
    padding: 28px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 8px 40px rgba(0,0,0,.22);
    animation: modal-in .15s ease;
}

@keyframes modal-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }

.modal-title { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

/* ── States ──────────────────────────────────────────────────────────────── */
.loading-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.spinner { display: inline-block; width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; margin-bottom: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 56px 20px; color: var(--text-muted); }
.empty-state h3 { font-size: 16px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; }

.error-state { text-align: center; padding: 40px 20px; color: var(--negative); }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
}

.login-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 40px 40px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 2px 16px rgba(0,0,0,.12);
    border: 1px solid var(--border);
}

.login-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 28px; }
.login-logo-text { font-size: 18px; font-weight: 600; color: var(--text); }

.login-card h2 { font-size: 22px; font-weight: 600; color: var(--text); margin-bottom: 6px; text-align: center; }
.login-subtitle { font-size: 13px; color: var(--text-muted); text-align: center; margin-bottom: 28px; }

.login-error {
    background: #fce8e6;
    color: var(--negative);
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
}

.login-btn { width: 100%; padding: 10px; font-size: 14px; margin-top: 8px; justify-content: center; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-orange { background: #fef0e6; color: var(--accent); }
.badge-green  { background: #e6f4ea; color: var(--positive); }
.badge-red    { background: #fce8e6; color: var(--negative); }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; }
.mb-20 { margin-bottom: 20px; }

/* ── Hamburger / Mobile ──────────────────────────────────────────────────── */
.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    line-height: 1;
    border-radius: 4px;
    flex-shrink: 0;
}
.hamburger:hover { color: var(--text); background: var(--bg); }

.sidebar-close {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    color: var(--sidebar-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.sidebar-close:hover { color: var(--sidebar-text); background: var(--sidebar-hover); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 9;
}
.sidebar-overlay.visible { display: block; }

/* ── Scrollable table wrapper ─────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 500px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 22px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    min-width: 180px;
    text-align: center;
    pointer-events: none;
}
.toast-success { background: #1a7340; color: #fff; }
.toast-error   { background: var(--negative); color: #fff; }

/* ── Profile avatar ──────────────────────────────────────────────────────── */
.avatar-wrap { text-align: center; margin-bottom: 16px; }

.user-avatar-lg {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 34px;
    font-weight: 700;
    color: #fff;
    margin: 0 auto;
    border: 3px solid var(--border);
}

.avatar-img {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto;
    border: 3px solid var(--border);
}

/* ── App access badges ───────────────────────────────────────────────────── */
.apps-grid { display: flex; flex-wrap: wrap; gap: 8px; }

.app-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: #e6f4ea;
    color: var(--positive);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

/* Access matrix checkbox */
.access-cb {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .hamburger { display: flex; align-items: center; }
    .sidebar-close { display: block; }

    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform .25s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.3);
    }

    .content { padding: 20px 16px; }
    .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
    .modal { padding: 20px; }
    .login-card { padding: 28px 24px; }
    th, td { padding: 10px 12px; }
}
