:root {
    --sidebar-bg: #0a1628;
    --sidebar-hover: rgba(255,255,255,0.06);
    --sidebar-active: rgba(27,125,94,0.18);
    --sidebar-w: 260px;
    --accent: #1B7D5E;
    --accent-light: #22a078;
    --accent-glow: rgba(27,125,94,0.25);
    --gold: #C9A227;
    --bg: #eef1f6;
    --surface: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --danger: #dc2626;
    --warning: #d97706;
    --info: #2563eb;
    --success: #16a34a;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(15,23,42,0.06), 0 4px 12px rgba(15,23,42,0.04);
    --shadow-lg: 0 8px 30px rgba(15,23,42,0.08);
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --header-h: 64px;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-light); }

/* ── Layout ── */
.admin-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand {
    padding: 22px 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand .logo {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #fff;
}
.sidebar-brand .logo span { color: var(--gold); }
.sidebar-brand .sub {
    font-size: 0.6875rem;
    color: rgba(255,255,255,0.45);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-section {
    padding: 16px 12px 8px;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255,255,255,0.35);
}

.sidebar nav { flex: 1; padding: 8px 0 16px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    margin: 2px 10px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 8px;
    transition: all 0.15s ease;
    position: relative;
}
.nav-item:hover {
    color: #fff;
    background: var(--sidebar-hover);
}
.nav-item.active {
    color: #fff;
    background: var(--sidebar-active);
    box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.75;
}
.nav-item.active svg { opacity: 1; color: var(--accent-light); }

.nav-badge {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 100px;
    background: var(--danger);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.nav-badge.warn { background: var(--warning); }
.nav-badge.info { background: var(--info); }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    margin-bottom: 8px;
}
.sidebar-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #0d4d3a);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: #fff;
    flex-shrink: 0;
}
.sidebar-user .info { min-width: 0; }
.sidebar-user .name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user .role {
    font-size: 0.6875rem;
    color: rgba(255,255,255,0.45);
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: rgba(255,255,255,0.5);
    font-size: 0.8125rem;
    border-radius: 6px;
    transition: color 0.15s;
}
.sidebar-footer a:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar-footer a svg { width: 16px; height: 16px; }

/* ── Main area ── */
.main-wrap {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.top-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.top-header .page-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
}
.top-header .page-title small {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 1px;
}
.top-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.top-header-actions .time {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.main-content { padding: 24px 28px 40px; flex: 1; }

/* ── Page header (inside content) ── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.page-header .desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 4px;
}
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

/* ── Stats grid ── */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    box-shadow: var(--shadow);
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.green { background: rgba(27,125,94,0.12); color: var(--accent); }
.stat-icon.blue { background: rgba(37,99,235,0.12); color: var(--info); }
.stat-icon.amber { background: rgba(217,119,6,0.12); color: var(--warning); }
.stat-icon.purple { background: rgba(124,58,237,0.12); color: #7c3aed; }
.stat-icon.red { background: rgba(220,38,38,0.12); color: var(--danger); }

.stat-body { min-width: 0; }
.stat-body .num {
    font-size: 1.625rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.stat-body .lbl {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.stat-body .hint {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Grid layouts ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.grid-main-side { display: grid; grid-template-columns: 1fr 340px; gap: 20px; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    gap: 12px;
}
.card-header h3 {
    font-size: 0.9375rem;
    font-weight: 600;
}
.card-header .link {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--accent);
}
.card-body { padding: 20px; }
.card > h3 { padding: 16px 20px 0; font-size: 0.9375rem; font-weight: 600; }
.card > table { margin-top: 0; }

/* ── Quick actions ── */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 18px 12px;
    background: var(--border-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s;
    text-align: center;
}
.quick-action:hover {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.quick-action svg { width: 24px; height: 24px; color: var(--accent); }
.quick-action span { font-size: 0.8125rem; font-weight: 500; }
.quick-action .count {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* ── Todo list ── */
.todo-list { list-style: none; }
.todo-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}
.todo-item:last-child { border-bottom: none; }
.todo-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.todo-dot.urgent { background: var(--danger); }
.todo-dot.normal { background: var(--warning); }
.todo-dot.low { background: var(--info); }
.todo-item .text { flex: 1; min-width: 0; font-size: 0.875rem; }
.todo-item .meta { font-size: 0.75rem; color: var(--text-muted); }
.todo-item .action { flex-shrink: 0; }

/* ── Status distribution ── */
.status-bars { display: flex; flex-direction: column; gap: 10px; }
.status-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8125rem;
}
.status-bar-row .label { width: 100px; color: var(--text-muted); flex-shrink: 0; }
.status-bar-row .bar-wrap {
    flex: 1;
    height: 8px;
    background: var(--border-light);
    border-radius: 100px;
    overflow: hidden;
}
.status-bar-row .bar {
    height: 100%;
    border-radius: 100px;
    transition: width 0.4s ease;
}
.status-bar-row .count {
    width: 32px;
    text-align: right;
    font-weight: 600;
    font-size: 0.8125rem;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
thead { background: var(--border-light); }
th {
    padding: 11px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}
tbody tr:hover { background: rgba(27,125,94,0.03); }
tbody tr:last-child td { border-bottom: none; }

.mono {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.8125rem;
}
.truncate { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font);
    transition: all 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-outline {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); background: rgba(27,125,94,0.04); }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; }
.btn-ghost:hover { color: var(--accent); background: var(--border-light); }
.btn-sm { padding: 5px 12px; font-size: 0.75rem; border-radius: 6px; }
.btn-lg { padding: 12px 24px; font-size: 0.9375rem; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.badge-pending, .badge-submitted, .badge-reviewing, .badge-supplement_required {
    background: #fef3c7; color: #92400e;
}
.badge-approved, .badge-active, .badge-confirmed {
    background: #dcfce7; color: #166534;
}
.badge-rejected, .badge-failed, .badge-revoked {
    background: #fee2e2; color: #991b1b;
}
.badge-pending-chain { background: #dbeafe; color: #1e40af; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-expired { background: #f1f5f9; color: #64748b; }

/* ── Filter tabs ── */
.filter-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    background: var(--border-light);
}
.filter-tab {
    padding: 6px 14px;
    border-radius: 100px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid transparent;
    transition: all 0.15s;
}
.filter-tab:hover { color: var(--text); background: var(--surface); }
.filter-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.form-group .hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-section {
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    background: var(--border-light);
}
.form-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

/* ── Detail grid ── */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 20px;
}
.detail-grid dt {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 10px;
}
.detail-grid dd {
    font-size: 0.9375rem;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
    word-break: break-word;
}
.detail-grid dd:last-of-type { border-bottom: none; }

/* ── Actions panel ── */
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.action-panel {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--border-light);
    margin-top: 16px;
}
.action-panel h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.action-panel + .action-panel { margin-top: 12px; }

/* ── Flash messages ── */
.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.875rem;
    font-weight: 500;
}
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ── Pagination ── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-light);
}
.pagination-info { font-size: 0.8125rem; color: var(--text-muted); }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; opacity: 0.3; margin-bottom: 12px; }
.empty-state p { font-size: 0.875rem; }
.empty-row { text-align: center; color: var(--text-muted); padding: 32px !important; }

/* ── Inline forms ── */
.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input[type=text] {
    width: 140px;
    padding: 5px 10px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.search-bar { display: flex; gap: 8px; margin-bottom: 0; padding: 16px 20px; border-bottom: 1px solid var(--border-light); }
.search-bar input { flex: 1; max-width: 360px; }
.doc-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ── Login page ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0a1628 0%, #0d2137 50%, #0a2820 100%);
    padding: 24px;
}
.login-wrap {
    display: grid;
    grid-template-columns: 1fr 400px;
    max-width: 900px;
    width: 100%;
    background: var(--surface);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 80px rgba(0,0,0,0.4);
}
.login-brand {
    background: linear-gradient(160deg, #0a1628, #1B7D5E);
    padding: 48px 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
}
.login-brand h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 8px; }
.login-brand h1 span { color: var(--gold); }
.login-brand p { font-size: 0.9375rem; color: rgba(255,255,255,0.7); line-height: 1.6; margin-bottom: 32px; }
.login-features { list-style: none; }
.login-features li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    color: rgba(255,255,255,0.8);
    margin-bottom: 12px;
}
.login-features li svg { width: 18px; height: 18px; color: var(--gold); flex-shrink: 0; }

.login-box { padding: 48px 40px; }
.login-box h2 { font-size: 1.375rem; font-weight: 700; margin-bottom: 6px; }
.login-box .sub { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 28px; }
.error {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 16px;
    border: 1px solid #fecaca;
}

/* ── Settings ── */
.settings-grid { display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
.settings-nav a {
    display: block;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}
.settings-nav a.active, .settings-nav a:hover {
    background: var(--border-light);
    color: var(--accent);
}

/* ── Responsive ── */
@media (max-width: 1200px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
    .quick-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-3, .grid-main-side { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.25s; }
    .sidebar.open { transform: translateX(0); }
    .main-wrap { margin-left: 0; }
    .stats, .grid-2, .quick-grid { grid-template-columns: 1fr; }
    .login-wrap { grid-template-columns: 1fr; }
    .login-brand { display: none; }
    .main-content { padding: 16px; }
    .form-row, .detail-grid { grid-template-columns: 1fr; }
}
