/* ============================================================
   K-Source StaffingLedger — design system
   Palette derived from the K-Source logo green (#136a59)
   ============================================================ */

:root {
    /* Brand — sampled from the K-Source logo (#136a59) */
    --primary: #136a59;
    --primary-dark: #0c4e41;
    --primary-light: #e6f5f1;
    --accent: #2fbfa0;
    --gradient: linear-gradient(135deg, #136a59 0%, #1f9c81 100%);

    /* Surfaces */
    --bg: #f4f7f6;
    --surface: #ffffff;
    --surface-2: #f2f7f6;
    --border: #e1e8e6;

    /* Sidebar */
    --side-bg: #0b1d1b;
    --side-bg-2: #12302b;
    --side-text: #9cb7b0;
    --side-active: #ffffff;

    /* Text */
    --text: #16211e;
    --muted: #647570;

    /* Semantic */
    --danger: #e11d48;
    --danger-soft: #fff1f2;
    --success: #1f8a4c;
    --success-soft: #eaf7ef;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --info-soft: #e6f5f1;

    /* Shape & depth */
    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(23, 26, 46, 0.05);
    --shadow: 0 1px 3px rgba(23, 26, 46, 0.06), 0 6px 20px -6px rgba(23, 26, 46, 0.1);
    --shadow-lg: 0 8px 16px -4px rgba(23, 26, 46, 0.14), 0 20px 40px -12px rgba(23, 26, 46, 0.18);

    --sidebar-w: 254px;
    --topbar-h: 64px;
}

* { box-sizing: border-box; }

[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

/* ============================================================
   App shell
   ============================================================ */

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

.main-col {
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%);
    display: flex;
    flex-direction: column;
    z-index: 50;
    transition: transform 0.25s ease;
}

.sidebar::after {
    /* subtle aurora glow */
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(420px 220px at 20% -5%, rgba(19, 106, 89, 0.38), transparent 65%),
        radial-gradient(340px 200px at 110% 105%, rgba(47, 191, 160, 0.16), transparent 60%);
}

.sidebar > * { position: relative; z-index: 1; }

.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 1.15rem 1.25rem;
    text-decoration: none;
}

.brand-mark {
    display: block;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex: none;
    box-shadow: 0 6px 16px -4px rgba(13, 148, 120, 0.55);
}

.brand-text {
    color: #fff;
    font-weight: 700;
    font-size: 1.0rem;
    letter-spacing: 0.01em;
    line-height: 1.15;
}

.brand-text em {
    font-style: normal;
    background: linear-gradient(90deg, #8fe0cb, #c8f7e6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0.85rem 1rem;
    overflow-y: auto;
}

.nav-heading {
    display: block;
    padding: 1.05rem 0.6rem 0.45rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #6a8a83;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 2px;
    border-radius: 10px;
    color: var(--side-text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.nav-icon { width: 20px; height: 20px; flex: none; opacity: 0.9; }

.nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #e4e7f7;
    transform: translateX(2px);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(19, 106, 89, 0.34), rgba(47, 191, 160, 0.14));
    color: var(--side-active);
    box-shadow: inset 2.5px 0 0 var(--accent);
    font-weight: 600;
}

.sidebar-foot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.9rem 1.35rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    color: #6a8a83;
    font-size: 0.76rem;
}

.sidebar-foot-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 16, 38, 0.55);
    backdrop-filter: blur(2px);
    z-index: 40;
}

/* ---------- Topbar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 1rem;
    height: var(--topbar-h);
    padding: 0 1.4rem;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.topbar-spacer { flex: 1; }

.hamburger {
    display: none;
    background: none;
    border: none;
    padding: 0.4rem;
    cursor: pointer;
    color: var(--text);
    border-radius: var(--radius-sm);
}

.hamburger svg { width: 22px; height: 22px; display: block; }
.hamburger:hover { background: var(--surface-2); }

/* ---------- Profile ---------- */

.profile { position: relative; }

.profile-chip {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.35rem 0.6rem 0.35rem 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.profile-chip:hover { border-color: #bcd2cc; box-shadow: var(--shadow-sm); }

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    flex: none;
}

.avatar-lg { width: 44px; height: 44px; font-size: 0.95rem; }

.profile-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}

.profile-name { font-size: 0.86rem; font-weight: 600; white-space: nowrap; }
.profile-role { font-size: 0.72rem; color: var(--muted); }

.chevron { width: 16px; height: 16px; color: var(--muted); transition: transform 0.2s ease; }
.chevron.is-flipped { transform: rotate(180deg); }

.profile-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.45rem;
    z-index: 60;
    transform-origin: top right;
}

.menu-enter { transition: opacity 0.14s ease, transform 0.14s ease; }
.menu-enter-start { opacity: 0; transform: scale(0.95) translateY(-4px); }
.menu-enter-end { opacity: 1; transform: scale(1) translateY(0); }
.menu-leave { transition: opacity 0.1s ease, transform 0.1s ease; }
.menu-leave-start { opacity: 1; transform: scale(1) translateY(0); }
.menu-leave-end { opacity: 0; transform: scale(0.95) translateY(-4px); }

.profile-menu-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.4rem;
}

.profile-menu form { margin: 0; }

.profile-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.55rem 0.6rem;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.profile-menu-item svg { width: 17px; height: 17px; color: var(--muted); }
.profile-menu-item:hover { background: var(--surface-2); }
.profile-menu-item.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.profile-menu-item.is-danger:hover svg { color: var(--danger); }

.role-badge-admin  { background: var(--danger-soft); color: var(--danger); }
.role-badge-ops    { background: var(--info-soft); color: var(--primary-dark); }
.role-badge-viewer { background: var(--bg); color: var(--muted); }

/* ============================================================
   Content
   ============================================================ */

.container {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

h1 {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin: 0 0 1.2rem;
}

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

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

.page-header h1 { margin: 0; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.05rem;
    border: none;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
}

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

.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 4px 12px -3px rgba(19, 106, 89, 0.5);
}

.btn-primary:hover { box-shadow: 0 6px 18px -3px rgba(19, 106, 89, 0.6); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover { background: var(--surface-2); border-color: #bcd2cc; }

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

.btn-link {
    background: none;
    color: var(--muted);
    padding: 0.35rem 0.5rem;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.btn-link:hover { color: var(--text); }

.btn-small { padding: 0.34rem 0.68rem; font-size: 0.78rem; border-radius: 7px; }

/* ---------- Alerts ---------- */

.alert {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #fecdd3;
}

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

.error-list { margin: 0; padding-left: 1.2rem; }

/* ---------- Search & filter bars ---------- */

.search-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.1rem;
}

.filter-wrap { flex-wrap: wrap; }

.search-form input,
.search-form select {
    padding: 0.52rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.88rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-form input { flex: 0 1 320px; }

.search-form input:focus,
.search-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(19, 106, 89, 0.18);
}

/* ---------- Tables ---------- */

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.885rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.72rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table thead th {
    font-size: 0.71rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-weight: 700;
    color: var(--muted);
    background: var(--surface-2);
    white-space: nowrap;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.12s ease; }
.data-table tbody tr:hover { background: var(--surface-2); }

.col-notes { max-width: 280px; color: var(--muted); }
.col-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.col-nowrap { white-space: nowrap; }

.col-actions { white-space: nowrap; width: 1%; }
.col-actions form { display: inline-block; margin-left: 0.25rem; }

.table-empty { padding: 1.4rem 0.2rem; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 0.18rem 0.58rem;
    border-radius: 999px;
    background: var(--info-soft);
    color: var(--primary-dark);
    font-size: 0.74rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: var(--success-soft); color: var(--success); }
.badge-muted   { background: var(--bg); color: var(--muted); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); }

/* ---------- Forms ---------- */

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.6rem;
    max-width: 580px;
}

.form-card label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text);
}

.form-card input,
.form-card select,
.form-card textarea {
    width: 100%;
    padding: 0.58rem 0.75rem;
    margin-bottom: 1.05rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.92rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-card input:focus,
.form-card select:focus,
.form-card textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(19, 106, 89, 0.18);
}

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

.field-hint {
    margin: -0.65rem 0 1.05rem;
    font-size: 0.78rem;
    color: var(--muted);
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.4rem;
}

/* ---------- Dashboard ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.05rem;
    margin-top: 0.4rem;
}

.stat-card {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.2rem 1.3rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: var(--gradient);
    opacity: 0.85;
}

a.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: #bcd2cc;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.09em;
    font-weight: 700;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-sub { font-size: 0.78rem; }

.stat-alert::before { background: linear-gradient(90deg, #f43f5e, #fb7185); }
.stat-alert .stat-value { color: var(--danger); }

.stat-warn::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.stat-warn .stat-value { color: var(--warning); }

/* ---------- Audit log diffs ---------- */

.diff-cell { max-width: 420px; }

.diff-list {
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.8rem;
}

.diff-list li { margin-bottom: 0.18rem; }
.diff-field { font-weight: 600; }

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    gap: 0.3rem;
    list-style: none;
    padding: 0;
    margin: 1.1rem 0 0;
}

.pagination a,
.pagination .active span {
    display: inline-block;
    padding: 0.38rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    font-size: 0.84rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.pagination .active span {
    background: var(--gradient);
    border-color: transparent;
    color: #fff;
}

.pagination a:hover { background: var(--surface-2); }

/* ============================================================
   Login
   ============================================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(900px 480px at 15% -10%, rgba(19, 106, 89, 0.4), transparent 60%),
        radial-gradient(700px 420px at 110% 110%, rgba(47, 191, 160, 0.24), transparent 55%),
        linear-gradient(160deg, #0b1d1b 0%, #12302b 100%);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.55);
    padding: 2.3rem 2.2rem 2.1rem;
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.6rem;
}

.login-brand .brand-mark {
    width: 64px;
    height: 64px;
    box-shadow: 0 10px 24px -6px rgba(13, 148, 120, 0.45);
}

.login-card h1 {
    margin: 0;
    font-size: 1.3rem;
    text-align: center;
}

.login-sub {
    margin: 0.2rem 0 0;
    text-align: center;
    color: var(--muted);
    font-size: 0.86rem;
}

.login-card label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.login-card input {
    width: 100%;
    padding: 0.62rem 0.8rem;
    margin-bottom: 1.05rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-card input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(19, 106, 89, 0.18);
}

.login-card .btn { width: 100%; padding: 0.68rem; font-size: 0.95rem; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 920px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    .sidebar.is-open { transform: translateX(0); }

    .main-col { margin-left: 0; }

    .hamburger { display: block; }

    .container { padding: 1.25rem 1rem 2.5rem; }

    .profile-meta { display: none; }

    .page-header { flex-wrap: wrap; }

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

@media (max-width: 560px) {
    .search-form { flex-wrap: wrap; }
    .search-form input { flex: 1 1 100%; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
}
