:root {
    color-scheme: light;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bg-main: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --border: #e2e8f0;
    --radius: 14px;
}

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

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

body {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(28px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
}

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

.page {
    width: 100%;
    max-width: 1140px;
    margin: 0 auto;
}

/* Header & Topbar */
.topbar {
    background: #ffffff;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    margin-bottom: 20px;
    padding: 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.topbar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: 100%;
    flex-wrap: nowrap;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    min-width: 0;
}

.topbar-brand .brand-name {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.topbar-brand .brand-divider {
    color: #cbd5e1;
    font-weight: 300;
    font-size: 1.1rem;
}

.topbar-brand .page-title {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: auto;
}

.topbar-user .user-details {
    display: flex;
    flex-direction: column;
    text-align: right;
    line-height: 1.25;
}

.topbar-user .user-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-main);
}

.topbar-user .user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.topbar-user .logout-form {
    display: inline-flex;
    margin: 0;
}

.topbar-user .btn-logout {
    background: #f1f5f9;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
}

.topbar-user .btn-logout:hover {
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fca5a5;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    width: 100%;
    overflow: visible;
}

.topbar-nav a,
.nav-dropdown-btn {
    white-space: nowrap;
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--text-muted);
    background: #f8fafc;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
    line-height: 1.4;
}

.topbar-nav a:hover,
.nav-dropdown-btn:hover {
    color: var(--primary);
    background: #eff6ff;
}

.topbar-nav a.active,
.nav-dropdown-btn.active {
    color: #ffffff;
    background: var(--primary);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.nav-dropdown {
    position: relative;
    display: inline-block;
}

.nav-dropdown-btn .caret {
    font-size: 0.72rem;
    transition: transform 0.2s ease;
    margin-left: 2px;
}

.nav-dropdown.open .nav-dropdown-btn .caret {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 190px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    display: none;
    flex-direction: column;
    padding: 6px;
    z-index: 999;
}

.nav-dropdown.open .nav-dropdown-menu {
    display: flex;
}

.nav-dropdown-menu a {
    border-radius: 6px;
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.86rem;
    color: var(--text-main);
    background: transparent;
    box-shadow: none;
}

.nav-dropdown-menu a:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.nav-dropdown-menu a.active {
    background: #eff6ff;
    color: var(--primary);
    font-weight: 700;
    box-shadow: none;
}

.nav-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.nav-toggle {
    display: none;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
    color: var(--text-main);
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* Mobile responsive styles */
@media (max-width: 900px) {
    .topbar {
        position: relative;
        padding: 12px 14px;
        gap: 0;
    }

    .topbar-brand .brand-name,
    .topbar-brand .brand-divider {
        display: none;
    }

    .topbar-brand .page-title {
        font-size: 1.1rem;
    }

    .topbar-user .user-details {
        display: none;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .topbar-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #ffffff;
        border: 1px solid var(--border);
        border-radius: 0 0 var(--radius) var(--radius);
        box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
        padding: 12px;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        z-index: 100;
        border-top: none;
    }

    .topbar-nav.nav-open {
        display: flex;
    }

    .nav-dropdown {
        display: block;
        width: 100%;
    }

    .nav-dropdown-btn {
        display: none;
    }

    .nav-dropdown-menu {
        position: static;
        display: flex;
        box-shadow: none;
        border: none;
        padding: 0;
        gap: 6px;
        background: transparent;
    }

    .nav-dropdown-divider {
        display: none;
    }

    .topbar-nav a {
        padding: 10px 14px;
        border-radius: 8px;
        font-size: 0.9rem;
        background: #f8fafc;
    }

    .topbar-nav a.active {
        background: var(--primary);
        color: #ffffff;
    }
}

@media (max-width: 500px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Grids & Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

@media (min-width: 768px) {
    .card { padding: 24px; }
}

.form-card {
    max-width: 420px;
    margin: 60px auto 20px auto;
    padding: 28px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

@media (max-width: 480px) {
    .form-card {
        margin: 20px auto;
        padding: 20px;
    }
}

.card-urgent {
    border: 2px solid #ef4444;
    background: #fef2f2;
}

.grid-two {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 768px) {
    .grid-two {
        grid-template-columns: repeat(2, 1fr);
    }
}

.split {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

@media (min-width: 480px) {
    .split {
        grid-template-columns: repeat(2, 1fr);
    }
    .split:has(label:nth-child(3)) {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Forms & Inputs */
form {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #334155;
}

input, select, textarea {
    font-size: 16px !important; /* Prevents iOS Auto-Zoom */
    font-family: inherit;
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: var(--text-main);
    appearance: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2523475569'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 38px;
}

button, .button-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    padding: 0 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    background: var(--primary);
    color: #ffffff;
    transition: all 0.15s ease;
}

button:hover, .button-link:hover {
    background: var(--primary-hover);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

button.secondary, .button-link.secondary {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}

button.secondary:hover, .button-link.secondary:hover {
    background: #e2e8f0;
    box-shadow: none;
}

button.danger {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
}

button.danger:hover {
    background: #fecaca;
    box-shadow: none;
}

.alert {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #991b1b;
    background: #fee2e2;
    margin-bottom: 20px;
}

.alert.success {
    color: #166534;
    background: #dcfce7;
}

/* Stats Cards - Forced 3 Equal Columns on Desktop */
.stats {
    display: grid;
    grid-template-columns: repeat(1, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

@media (min-width: 600px) {
    .stats {
        grid-template-columns: repeat(3, 1fr);
    }
}

.stats article {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 14px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.stats span {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.03em;
}

.stats strong {
    display: block;
    font-size: 2.2rem;
    font-weight: 800;
    margin-top: 4px;
    line-height: 1.1;
}

/* Item lists */
.item-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    background: #ffffff;
    transition: border-color 0.15s ease;
}

@media (min-width: 640px) {
    .item-card {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}
