:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --border: #dfe5ec;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #1447e6;
    --primary-dark: #1039b9;
    --danger: #c62828;
    --danger-bg: #fee2e2;
    --success: #0f8b53;
    --success-bg: #def7ec;
    --warning: #946200;
    --warning-bg: #fff4ce;
    --sidebar: #0f172a;
    --sidebar-soft: #1e293b;
    --radius: 18px;
    --shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

code {
    background: #f1f5f9;
    border-radius: 8px;
    padding: 0.15rem 0.35rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92em;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 270px;
    background: var(--sidebar);
    color: #fff;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 24px;
}

.brand-badge,
.login-logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #0f172a);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.brand-title {
    font-size: 1rem;
    font-weight: 700;
}

.brand-subtitle {
    color: rgba(255,255,255,0.72);
    font-size: 0.85rem;
}

.nav {
    display: grid;
    gap: 8px;
}

.nav-link {
    padding: 11px 14px;
    border-radius: 12px;
    color: rgba(255,255,255,0.85);
    transition: 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
    background: var(--sidebar-soft);
    color: #fff;
}

.user-card {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.08);
    padding: 14px;
    border-radius: 14px;
    margin-bottom: 12px;
}

.user-name {
    font-weight: 700;
}

.user-email,
.user-role {
    color: rgba(255,255,255,0.75);
    font-size: 0.88rem;
}

.content-area {
    flex: 1;
    min-width: 0;
}

.topbar {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    padding: 24px 28px 10px;
}

.topbar h1 {
    margin: 0;
    font-size: 1.7rem;
    line-height: 1.2;
}

.topbar p {
    margin: 6px 0 0;
    color: var(--muted);
}

.sidebar-toggle {
    display: none;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 12px;
    width: 42px;
    height: 42px;
    font-size: 18px;
    cursor: pointer;
}

.page-content {
    padding: 0 28px 28px;
}

.panel,
.stat-card,
.login-card,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    padding: 20px;
    margin-bottom: 20px;
    width:100%;
}

.form-panel {
    max-width: 980px;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.panel-head h3 {
    margin: 0;
    font-size: 1.05rem;
}

.panel-head p {
    margin: 5px 0 0;
    color: var(--muted);
}

.stack-mobile {
    flex-wrap: wrap;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 20px;
}

.stat-card {
    padding: 20px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    margin-bottom: 12px;
}

.stat-card strong {
    font-size: 1.9rem;
    display: block;
    line-height: 1;
}

.stat-card small {
    display: block;
    margin-top: 10px;
    color: var(--muted);
}

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

.table-wrap {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
    background: #fff;
}

th,
td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    background: var(--surface-soft);
    font-size: 0.84rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}

tbody tr:hover {
    background: #f8fbff;
}

.empty-cell {
    text-align: center;
    color: var(--muted);
    padding: 28px 16px;
}

.button,
button.button {
    appearance: none;
    border: 1px solid transparent;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 15px;
    border-radius: 12px;
    font-weight: 600;
    transition: 0.18s ease;
    white-space: nowrap;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    background: var(--primary);
    color: #fff;
}

.button-primary:hover {
    background: var(--primary-dark);
}

.button-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}

.button-ghost {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}

.button-danger {
    background: var(--danger);
    color: #fff;
}

.button-small {
    padding: 8px 11px;
    font-size: 0.85rem;
}

.button-lg {
    padding: 14px 18px;
    font-size: 1rem;
}

.button-block {
    width: 100%;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.button-row.compact {
    gap: 8px;
}

.filter-grid,
.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.compact-grid {
    grid-template-columns: minmax(0, 1fr) auto;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-span-2 {
    grid-column: span 2;
}

.field.actions {
    align-self: end;
}

label {
    font-weight: 600;
    color: var(--text);
}

.required {
    color: var(--danger);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 13px;
    font: inherit;
    color: var(--text);
    background: #fff;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.form-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.alert {
    padding: 14px 16px;
    border-radius: 14px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}

.alert-success {
    color: #0f5132;
    background: var(--success-bg);
    border-color: #a7f3d0;
}

.alert-danger {
    color: #7f1d1d;
    background: var(--danger-bg);
    border-color: #fecaca;
}

.alert-warning {
    color: #6b4f00;
    background: var(--warning-bg);
    border-color: #fde68a;
}

.pagination {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 18px;
}

.page-link {
    min-width: 40px;
    text-align: center;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
}

.page-link.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.status-pill {
    display: inline-flex;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.status-success,
.status-logout {
    background: #dcfce7;
    color: #166534;
}

.status-denied,
.status-error {
    background: #fee2e2;
    color: #991b1b;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-shell {
    width: 100%;
    display: grid;
    place-items: center;
}

.login-card {
    width: min(460px, 100%);
    padding: 28px;
    text-align: center;
}

.login-card h2 {
    margin: 18px 0 8px;
    font-size: 1.5rem;
}

.muted {
    color: var(--muted);
}

.notice-box,
.login-notes {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    padding: 14px;
    border-radius: 14px;
    margin-top: 16px;
    text-align: left;
}

.empty-state {
    padding: 36px 24px;
    text-align: center;
}

.simple-list {
    margin: 10px 0 0 18px;
    padding: 0;
}

.auth-alert {
    position: fixed;
    top: 24px;
    right: 24px;
    width: min(420px, calc(100% - 48px));
    z-index: 50;
}

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

    .field-span-2 {
        grid-column: span 2;
    }
}

@media (max-width: 820px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 40;
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .content-area {
        width: 100%;
    }

    .sidebar-toggle {
        display: inline-grid;
        place-items: center;
        flex: 0 0 auto;
    }

    .topbar,
    .page-content {
        padding-left: 18px;
        padding-right: 18px;
    }
}

@media (max-width: 640px) {
    .stats-grid,
    .grid-2,
    .filter-grid,
    .form-grid,
    .compact-grid {
        grid-template-columns: 1fr;
    }

    .field-span-2 {
        grid-column: auto;
    }

    .topbar h1 {
        font-size: 1.35rem;
    }

    .panel,
    .stat-card {
        padding: 16px;
        width:100%;
    }

    .auth-alert {
        position: static;
        width: 100%;
        margin-bottom: 16px;
    }
}
