:root {
    --primary: #1d6f5c;
    --primary-dark: #0f5041;
    --bg: #f4f5f3;
    --surface: #ffffff;
    --border: #e1e3df;
    --text: #22261f;
    --text-muted: #6b6f66;
    --danger: #b3261e;
    --danger-bg: #fbe9e7;
    --success: #1d6f5c;
    --success-bg: #e6f1ec;
    --warning: #8a5a00;
    --warning-bg: #fdf1de;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

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

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: 230px;
    background: var(--primary-dark);
    color: #eef4f1;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    padding: 14px 18px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    flex-shrink: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 6px 0;
    overflow-y: auto;
}

.sidebar-nav a {
    display: block;
    padding: 6px 18px;
    color: #cfe3db;
    font-size: 13px;
    line-height: 1.3;
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.sidebar-nav a.active {
    background: rgba(255,255,255,0.14);
    color: #fff;
    font-weight: 600;
    border-left: 3px solid #fff;
}

.sidebar-divider {
    margin: 8px 18px 3px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255,255,255,0.45);
}

.sidebar-footer {
    padding: 10px 18px;
    border-top: 1px solid rgba(255,255,255,0.12);
    flex-shrink: 0;
}

.sidebar-user-name { font-weight: 600; color: #fff; }
.sidebar-user-role { font-size: 12px; color: rgba(255,255,255,0.6); margin-bottom: 4px; }
.logout-link { font-size: 13px; color: #ffd7d0; }

/* ---------- Main content ---------- */
.main-content {
    flex: 1;
    padding: 28px 32px;
    max-width: 1200px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.page-header h1 { font-size: 20px; margin: 0; font-weight: 600; }
.page-subtitle { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

/* ---------- Cards / panels ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-card .value { font-size: 24px; font-weight: 700; color: var(--primary-dark); }
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text); }

input[type="text"], input[type="password"], input[type="date"], input[type="number"],
input[type="search"], input[type="email"], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29,111,92,0.12);
}

.form-row { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.checkbox-row input { width: auto; }

.permission-group { margin-bottom: 12px; }
.permission-group-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 6px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    box-sizing: border-box;
    padding: 9px 16px;
    border-radius: 6px;
    border: 1px solid var(--primary);
    background: var(--primary);
    color: #fff;
    font-size: 14px;
    line-height: 1.3;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    text-align: center;
    vertical-align: middle;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f0f1ee; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #8f1e18; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fafaf8; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-neutral { background: #eceeea; color: var(--text-muted); }

/* ---------- Alerts ---------- */
.alert { padding: 11px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13.5px; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }

/* ---------- Login page ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-dark);
}
.login-box {
    background: var(--surface);
    padding: 36px 32px;
    border-radius: 12px;
    width: 100%;
    max-width: 360px;
}
.login-box h1 { font-size: 19px; text-align: center; margin: 0 0 4px; }
.login-box .sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 22px; }
.login-box .btn { width: 100%; margin-top: 6px; }

.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Mobile top bar (hidden on desktop) ---------- */
.mobile-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    background: var(--primary-dark);
    color: #fff;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 1001;
}
.mobile-menu-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
}
.mobile-topbar-brand { font-weight: 600; font-size: 15px; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1002;
}
.sidebar-overlay.open { display: block; }

/* ---------- Responsive layout ---------- */
@media (max-width: 860px) {
    .app-shell { flex-direction: column; min-height: auto; }

    .mobile-topbar { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: -260px;
        width: 230px;
        height: 100vh;
        z-index: 1003;
        transition: left 0.22s ease;
    }
    .sidebar.open { left: 0; }

    .main-content {
        max-width: 100%;
        padding: 16px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
    }

    /* Tables scroll horizontally instead of squeezing/breaking the layout */
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .card { padding: 16px; }

    /* Give buttons and inputs a touch-friendly minimum height */
    .btn, input[type="text"], input[type="password"], input[type="date"],
    input[type="number"], select, textarea {
        min-height: 40px;
    }

    .login-box { padding: 28px 20px; max-width: 100%; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .card h2 { font-size: 14px; }
}
