:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #18212f;
    --muted: #6b7280;
    --border: #dbe3ee;
    --primary: #0d5cab;
    --primary-dark: #0a4a89;
    --primary-light: #2f78c4;
    --success: #1f9d55;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #0284c7;
    --sidebar: #1f2937;
    --sidebar-hover: #111827;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --radius: 18px;
    --radius-sm: 12px;
    --max-width: 1400px;
    --topbar-height: 88px;
    --sidebar-width: 250px;
    --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* Layout */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: #fff;
    padding: 0.9rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.85rem;
    color: #fff;
    min-width: 0;
}

.brand:hover {
    color: #fff;
}

.brand-logo {
    display: block;
    width: 52px;
    height: 52px;
    max-width: 52px;
    max-height: 52px;
    object-fit: contain;
    flex: 0 0 52px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 12px;
    padding: 0.2rem;
}

.brand-text {
    min-width: 0;
}

.brand-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.2;
    color: #fff;
}

.subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.88rem;
    opacity: 0.92;
    color: rgba(255, 255, 255, 0.94);
}

.userbox {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.12);
    padding: 0.55rem 0.85rem;
    border-radius: 999px;
    color: #fff;
}

.userbox strong {
    font-size: 0.95rem;
    font-weight: 700;
}

.userbox small {
    display: block;
    opacity: 0.9;
    font-size: 0.78rem;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.layout {
    display: flex;
    width: 100%;
    min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #273244, #151d29);
    color: #fff;
    padding: 1rem 0.85rem;
    flex: 0 0 var(--sidebar-width);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.sidebar-nav a {
    display: block;
    color: #fff;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    font-weight: 600;
    transition: background 0.18s ease, transform 0.18s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(2px);
}

.content {
    flex: 1 1 auto;
    padding: 1.25rem;
    min-width: 0;
}

.page {
    background: transparent;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.page-title {
    margin: 0;
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--text);
}

.page-subtitle {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.98rem;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
}

.card + .card {
    margin-top: 1rem;
}

.card-title {
    margin: 0 0 0.4rem;
    font-size: 1.05rem;
    font-weight: 800;
}

.card-muted {
    color: var(--muted);
    font-size: 0.95rem;
}

/* Dashboard stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem 1.1rem;
}

.stat-label {
    margin: 0 0 0.45rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.stat-value {
    margin: 0;
    font-size: 2rem;
    line-height: 1;
    font-weight: 800;
    color: var(--text);
}

/* Grid helpers */
.grid {
    display: grid;
    gap: 1rem;
}

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

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

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

/* Buttons */
.btn,
button.btn,
input[type="submit"].btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 0.72rem 1rem;
    min-height: 42px;
    cursor: pointer;
    font-weight: 700;
    transition: all 0.18s ease;
    text-decoration: none;
    white-space: nowrap;
}

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

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

.btn-primary:hover {
    background: var(--primary-dark);
    color: #fff;
}

.btn-secondary {
    background: #eef3f8;
    color: var(--text);
    border-color: var(--border);
}

.btn-secondary:hover {
    background: #e5edf6;
    color: var(--text);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}

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

.btn-sm {
    min-height: 34px;
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    font-size: 0.9rem;
}

/* Forms */
.form-card {
    max-width: 780px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

label {
    display: inline-block;
    margin-bottom: 0.45rem;
    font-weight: 700;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 12px;
    padding: 0.8rem 0.9rem;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(13, 92, 171, 0.12);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.help-text {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.88rem;
    color: var(--muted);
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

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

thead th {
    text-align: left;
    background: #f8fafc;
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 800;
    padding: 0.95rem 1rem;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 0.95rem 1rem;
    border-bottom: 1px solid #edf2f7;
    vertical-align: top;
}

tbody tr:hover {
    background: #fafcff;
}

tbody tr:last-child td {
    border-bottom: 0;
}

/* Alerts */
.alert {
    border-radius: 14px;
    padding: 0.9rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    font-weight: 600;
}

.alert-success {
    background: #ecfdf3;
    color: #166534;
    border-color: #bbf7d0;
}

.alert-danger {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.alert-warning {
    background: #fff7ed;
    color: #9a3412;
    border-color: #fed7aa;
}

.alert-info {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.38rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-muted {
    background: #e5e7eb;
    color: #374151;
}

/* Login */
.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.2rem;
    background:
        radial-gradient(circle at top left, rgba(47,120,196,0.22), transparent 30%),
        radial-gradient(circle at bottom right, rgba(13,92,171,0.18), transparent 28%),
        var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 460px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
    padding: 1.4rem;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.1rem;
}

.auth-logo {
    width: 56px;
    height: 56px;
    object-fit: contain;
    background: rgba(13, 92, 171, 0.08);
    border-radius: 14px;
    padding: 0.2rem;
}

.auth-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
}

.auth-subtitle {
    margin: 0.2rem 0 0;
    color: var(--muted);
    font-size: 0.94rem;
}

/* Footer */
.site-footer {
    margin-top: 1rem;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
    padding: 1rem;
}

/* Utility */
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.5rem !important; }
.mt-2 { margin-top: 1rem !important; }
.mt-3 { margin-top: 1.5rem !important; }

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.5rem !important; }
.mb-2 { margin-bottom: 1rem !important; }
.mb-3 { margin-bottom: 1.5rem !important; }

.text-muted { color: var(--muted) !important; }
.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

.w-100 { width: 100% !important; }
.hidden { display: none !important; }

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

    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex: 0 0 auto;
        padding: 0.85rem;
    }

    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sidebar-nav a {
        padding: 0.75rem 0.9rem;
    }
}

@media (max-width: 800px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-left,
    .topbar-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .brand {
        gap: 0.7rem;
    }

    .brand-logo {
        width: 44px;
        height: 44px;
        max-width: 44px;
        max-height: 44px;
        flex-basis: 44px;
    }

    .brand-title {
        font-size: 1.05rem;
    }

    .subtitle {
        font-size: 0.82rem;
    }

    .content {
        padding: 1rem;
    }

    .stats-grid,
    .grid-3,
    .grid-2,
    .grid-4,
    .form-row {
        grid-template-columns: 1fr;
    }

    .userbox {
        width: 100%;
        border-radius: 16px;
        justify-content: space-between;
    }
}

@media (max-width: 560px) {
    .auth-card,
    .card,
    .stat-card,
    .table-wrap {
        border-radius: 16px;
    }

    .page-title {
        font-size: 1.35rem;
    }

    .stat-value {
        font-size: 1.65rem;
    }

    .btn,
    button.btn,
    input[type="submit"].btn {
        width: 100%;
    }

    .form-actions {
        flex-direction: column;
    }
}