:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-muted: #f1f5f9;
    --text: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-soft: #edf2f7;
    --primary: #1d4ed8;
    --primary-dark: #1e40af;
    --sidebar-start: #050505;
    --sidebar-end: #101010;
    --success-bg: #ecfdf3;
    --success-text: #027a48;
    --warning-bg: #fffaeb;
    --warning-text: #b54708;
    --danger-bg: #fef3f2;
    --danger-text: #b42318;
    --info-bg: #eff8ff;
    --info-text: #175cd3;
    --neutral-bg: #f1f5f9;
    --neutral-text: #475569;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Plus Jakarta Sans", Arial, sans-serif;
    font-feature-settings: "ss01" on, "cv01" on, "cv02" on;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.sidebar-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
a { color: inherit; }

.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    z-index: 90;
    background: rgba(246, 248, 251, 0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
}
.mobile-topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mobile-menu-btn,
.mobile-topbar-add {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    text-decoration: none;
}
.mobile-topbar-title { min-width: 0; flex: 1; }
.mobile-topbar-label { font-size: 11px; color: var(--muted); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.mobile-topbar-name { font-size: 16px; font-weight: 800; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
    opacity: 0;
    visibility: hidden;
    transition: .25s ease;
    z-index: 45;
}
.sidebar-backdrop.show { opacity: 1; visibility: visible; }

.sidebar {
    width: 270px;
    background: linear-gradient(180deg, var(--sidebar-start), var(--sidebar-end));
    padding: 22px 16px;
    position: fixed;
    inset: 0 auto 0 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 50;
    border-right: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform .25s ease;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 999px; }
.sidebar-bottom { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 16px; margin-top: 22px; }
.brand { display: flex; align-items: center; gap: 14px; padding: 8px 10px 22px; border-bottom: 1px solid rgba(255,255,255,0.08); margin-bottom: 22px; }
.brand-icon { width: 46px; height: 46px; border-radius: 12px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 5px; flex-shrink: 0; }
.brand-icon img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-label { font-size: 11px; color: rgba(255,255,255,0.55); letter-spacing: .14em; text-transform: uppercase; margin-bottom: 4px; }
.brand-title { font-size: 20px; font-weight: 800; line-height: 1.2; color: #fff; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu-group { display: grid; gap: 6px; margin-bottom: 18px; }
.menu-label { font-size: 11px; color: rgba(255,255,255,0.44); font-weight: 800; letter-spacing: .12em; text-transform: uppercase; padding: 0 14px 4px; }
.menu a { display: flex; align-items: center; gap: 12px; text-decoration: none; color: rgba(255,255,255,0.72); padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; transition: all .2s ease; border: 1px solid transparent; }
.menu a:hover,
.menu a.active { background: rgba(255,255,255,0.07); color: #fff; border-color: rgba(255,255,255,0.06); }
.menu-icon { width: 20px; min-width: 20px; text-align: center; font-size: 15px; }
.menu .submenu-link { margin-left: 32px; width: calc(100% - 32px); padding: 10px 14px; min-height: 42px; font-size: 14px; color: rgba(255,255,255,0.62); background: transparent; border-color: transparent; }
.menu .submenu-link:hover,
.menu .submenu-link.active { background: rgba(255,255,255,0.07); color: #fff; border-color: rgba(255,255,255,0.06); }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 10px; border-radius: 12px; background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.06); }
.sidebar-user-avatar { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.14); color: #fff; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.sidebar-user-name { color: #fff; font-size: 14px; font-weight: 700; line-height: 1.2; word-break: break-word; }
.sidebar-user-role { color: rgba(255,255,255,0.60); font-size: 12px; margin-top: 2px; }
.sidebar-help-btn,
.sidebar-logout { display: flex; align-items: center; gap: 12px; text-decoration: none; padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 600; border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.04); transition: all .2s ease; width: 100%; }
.sidebar-help-btn { color: rgba(255,255,255,0.74); margin-bottom: 10px; }
.sidebar-help-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-logout { color: #fecaca; }
.sidebar-logout:hover { background: rgba(239,68,68,0.12); color: #fff; }

.main {
    margin-left: 270px;
    width: calc(100% - 270px);
    min-height: 100vh;
    padding: 18px;
}

.page-hero {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 18px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
}
.page-kicker { font-size: 12px; color: var(--primary); font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin-bottom: 8px; }
.page-hero h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.04em; line-height: 1.1; }
.page-hero p { margin: 8px 0 0; color: var(--muted); font-size: 14px; font-weight: 500; max-width: 680px; }
.db-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid #bfdbfe; background: var(--info-bg); color: var(--info-text); border-radius: 999px; padding: 9px 12px; font-size: 13px; font-weight: 800; white-space: nowrap; }

.page-content,
.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card,
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 22px 24px;
    overflow: visible;
}
.card-title,
.panel h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; letter-spacing: -0.03em; }
.card-muted,
.panel p { margin: 0; color: var(--muted); font-size: 14px; font-weight: 500; line-height: 1.6; }
.toolbar,
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}
.stat-card {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}
.stat-card span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.stat-card strong { display: block; font-size: 24px; font-weight: 800; letter-spacing: -0.03em; color: var(--text); line-height: 1.1; }
.stat-card.warn strong { color: var(--warning-text); }
.stat-card.ok strong { color: var(--success-text); }

.btn,
.btn-primary,
.btn-soft,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    padding: 11px 17px;
    min-height: 42px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: .2s ease;
    white-space: nowrap;
}
.btn,
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 10px 20px rgba(29, 78, 216, 0.16); }
.btn:hover,
.btn-primary:hover { background: var(--primary-dark); color: #fff; transform: translateY(-1px); }
.btn-soft { background: #fff; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn-soft:hover { background: var(--surface-soft); }
.btn-danger { background: #b42318; color: #fff; box-shadow: none; }
.btn-danger:hover { background: #912018; color: #fff; }

.alert { border: none; border-radius: 12px; padding: 14px 16px; font-size: 14px; margin-bottom: 14px; font-weight: 650; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-danger { background: var(--danger-bg); color: var(--danger-text); }

.search-box,
.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
    min-height: 44px;
    outline: none;
}
.search-box { max-width: 320px; }
.search-box:focus,
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { border-color: #93c5fd; box-shadow: 0 0 0 4px rgba(29, 78, 216, .10); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-field { display: grid; gap: 8px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 13px; color: var(--muted); font-weight: 700; }
.form-field textarea { min-height: 92px; resize: vertical; }
.section-title { margin: 24px 0 14px; font-size: 15px; color: var(--text); font-weight: 800; letter-spacing: -0.02em; }
.checkbox-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.checkbox-card { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 13px; font-weight: 700; color: var(--text); }
.checkbox-card input { width: 18px; height: 18px; accent-color: var(--primary); }

.table-wrap { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
table,
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 980px; }
th { text-align: left; background: var(--surface-muted); color: #334155; font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; padding: 13px 14px; border-bottom: 1px solid var(--line); }
td { padding: 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcff; }
.small { color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.55; margin-top: 4px; }
.table-action { color: var(--primary); font-weight: 800; text-decoration: none; }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}
.badge-muted,
.badge.gray { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-success,
.badge.green { background: var(--success-bg); color: var(--success-text); }
.badge-warning,
.badge.amber { background: var(--warning-bg); color: var(--warning-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }
.badge.light { background: var(--info-bg); color: var(--info-text); }

.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check { min-width: 34px; text-align: center; border-radius: 999px; padding: 5px 8px; background: var(--neutral-bg); color: var(--neutral-text); font-size: 11px; font-weight: 800; }
.check.ok { background: var(--success-bg); color: var(--success-text); }
.empty,
.empty-state { padding: 32px; text-align: center; border: 1px dashed var(--line); border-radius: 14px; background: var(--surface-soft); color: var(--muted); font-weight: 650; }
.empty-state strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }
.empty-state p { margin: 0; }
.follow-list { display: grid; gap: 10px; margin: 12px 0 0; padding-left: 20px; color: var(--warning-text); font-weight: 650; line-height: 1.7; }
code { background: var(--surface-muted); border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; color: #334155; font-size: .92em; }

@media (max-width: 1180px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .checkbox-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
    .mobile-topbar { display: block; }
    .sidebar { transform: translateX(-105%); }
    .sidebar.show { transform: translateX(0); }
    .main { margin-left: 0; width: 100%; padding: 14px; }
    .page-hero { display: grid; padding: 18px; }
    .page-hero h1 { font-size: 26px; }
    .db-pill { width: max-content; }
    .stats-grid,
    .grid-3,
    .form-grid,
    .checkbox-row { grid-template-columns: 1fr; }
    .toolbar,
    .panel-head { display: grid; }
    .actions { width: 100%; }
    .search-box { max-width: 100%; }
    .btn,
    .btn-primary,
    .btn-soft,
    .btn-danger { width: 100%; }
}

@media (max-width: 520px) {
    .main { padding: 12px; }
    .card,
    .panel { padding: 18px; }
    .stats-grid { gap: 12px; }
    .sidebar { width: min(86vw, 270px); }
}

/* Overview page */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.overview-panel { min-height: 100%; }
.panel-head.compact { margin-bottom: 16px; }
.donut-card {
    display: grid;
    grid-template-columns: 190px 1fr;
    gap: 22px;
    align-items: center;
}
.donut {
    --value: 0;
    width: 172px;
    height: 172px;
    border-radius: 50%;
    background: conic-gradient(var(--success-text) calc(var(--value) * 1%), #e8eef5 0);
    display: grid;
    place-items: center;
    position: relative;
}
.donut::after {
    content: "";
    position: absolute;
    inset: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: inset 0 0 0 1px var(--line);
}
.donut > div { position: relative; z-index: 1; text-align: center; }
.donut strong { display: block; font-size: 30px; letter-spacing: -0.04em; }
.donut span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.legend-list { display: grid; gap: 11px; }
.legend-list div { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; font-weight: 700; }
.legend-list strong { margin-left: auto; color: var(--text); }
.legend-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--neutral-text); }
.legend-dot.ok { background: var(--success-text); }
.legend-dot.warn { background: var(--warning-text); }
.legend-dot.info { background: var(--info-text); }
.legend-dot.neutral { background: var(--neutral-text); }
.bar-list { display: grid; gap: 14px; }
.bar-row { display: grid; gap: 8px; }
.bar-row-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.bar-row-top span { color: var(--text); font-weight: 750; }
.bar-row-top strong { color: var(--muted); font-size: 13px; font-weight: 800; }
.progress-track { height: 10px; border-radius: 999px; background: #edf2f7; overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--neutral-text); min-width: 0; }
.progress-fill.ok { background: var(--success-text); }
.progress-fill.warn { background: var(--warning-text); }
.progress-fill.info { background: var(--info-text); }
.mini-chart {
    height: 230px;
    display: grid;
    grid-template-columns: repeat(6, minmax(40px, 1fr));
    gap: 12px;
    align-items: end;
    padding-top: 10px;
}
.chart-col { height: 100%; display: grid; grid-template-rows: 1fr auto; gap: 9px; align-items: end; text-align: center; }
.chart-bar { width: 100%; min-height: 12px; border-radius: 12px 12px 6px 6px; background: linear-gradient(180deg, var(--primary), var(--primary-dark)); display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; color: #fff; font-size: 11px; font-weight: 800; }
.chart-col small { color: var(--muted); font-size: 11px; font-weight: 800; white-space: nowrap; }
.rank-list { display: grid; gap: 10px; }
.rank-item { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-soft); }
.rank-item > span { width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--line); color: var(--primary); font-weight: 900; flex-shrink: 0; }
.rank-item strong { display: block; font-size: 14px; line-height: 1.25; }
.rank-item small { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin-top: 3px; }
.compact-empty { padding: 24px; }
@media (max-width: 1180px) {
    .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
    .donut-card { grid-template-columns: 1fr; justify-items: center; }
    .legend-list { width: 100%; }
    .mini-chart { grid-template-columns: repeat(3, minmax(40px, 1fr)); height: 260px; }
}
