/*
 * AploMark Design System — Aplo green, clean modern.
 * Hue 150 (forest green) + soft neutrals.
 * NO Bootstrap dependency. Hand-written, self-contained.
 */

/* ── Custom properties ─────────────────────────────────────────────── */
:root {
    /* Brand colours */
    --green:        #1a7a4a;
    --green-dark:   #145e38;
    --green-light:  #d6f0e3;
    --green-mid:    #2ea068;
    --green-tint:   #f0faf5;
    --green-border: #a8dfc2;

    /* Neutrals */
    --ink:    #111;
    --ink-2:  #555;
    --ink-3:  #888;
    --bg:     #f5f6f8;
    --white:  #fff;
    --border: #e2e5e9;

    /* Status tones */
    --tone-ok-bg:       #e6f7ee;
    --tone-ok-fg:       #1a7a4a;
    --tone-pending-bg:  #fff8e1;
    --tone-pending-fg:  #c78b00;
    --tone-reject-bg:   #fdecea;
    --tone-reject-fg:   #c0392b;
    --tone-partial-bg:  #e8f0fe;
    --tone-partial-fg:  #1a56a0;
    --tone-muted-bg:    #f2f2f2;
    --tone-muted-fg:    #777;
    --tone-info-bg:     #eef7ff;
    --tone-info-fg:     #1565c0;

    /* Layout */
    --sidebar-w:    240px;
    --header-h:     56px;

    /* Typography */
    --font:         'Inter', 'Segoe UI', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', 'Fira Mono', monospace;

    /* Shadows */
    --shadow-card:  0 2px 8px rgba(0,0,0,.08);
    --shadow-pop:   0 4px 16px rgba(0,0,0,.14);

    /* Radius */
    --r-sm:  6px;
    --r-md:  10px;
    --r-lg:  16px;
}

/* ── Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.55;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout: app-root ────────────────────────────────────────────────── */
.app-root {
    display: flex;
    min-height: 100vh;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 28px 32px;
    margin-left: var(--sidebar-w);
}

@media (max-width: 920px) {
    .main { margin-left: 0; padding: 16px; }
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--green-dark);
    color: #d4ede0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 60;
    overflow: hidden;
    transition: transform .25s ease;
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo {
    font-size: 28px;
    line-height: 1;
}
.brand-name { font-size: .95rem; font-weight: 700; color: #fff; }
.brand-sub  { font-size: .72rem; color: rgba(255,255,255,.55); }

/* Org switcher */
.org-switch-wrap {
    position: relative;
    margin: 10px 12px 6px;
}
.org-switch {
    width: 100%;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    border-radius: var(--r-sm);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #e0f2e9;
    font-family: var(--font);
    font-size: .82rem;
    cursor: pointer;
    text-align: left;
}
.org-switch:hover { background: rgba(255,255,255,.13); }
.org-switch-main { flex: 1; min-width: 0; }
.org-switch-label { font-size: .68rem; color: rgba(255,255,255,.5); display: block; line-height: 1.2; }
.org-switch-name {
    font-weight: 600; color: #fff; display: block;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.org-chevron { font-size: .75rem; color: rgba(255,255,255,.4); }
.org-env {
    font-size: .62rem; font-weight: 700; padding: 2px 5px; border-radius: 3px;
    text-transform: uppercase; white-space: nowrap;
}
.org-env.env-prod    { background: #e74c3c; color: #fff; }
.org-env.env-sandbox { background: #f39c12; color: #fff; }
.org-env.env-test    { background: #3498db; color: #fff; }

/* Menu pop */
.menu-pop {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px);
    background: #1e5c38; border: 1px solid rgba(255,255,255,.15);
    border-radius: var(--r-sm); z-index: 100;
    box-shadow: var(--shadow-pop);
    max-height: 220px; overflow-y: auto;
}
.menu-pop button {
    width: 100%; background: none; border: none; padding: 9px 12px;
    color: #d4ede0; font-family: var(--font); font-size: .83rem;
    text-align: left; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.menu-pop button:hover { background: rgba(255,255,255,.1); }
.menu-empty { padding: 9px 12px; font-size: .82rem; color: rgba(255,255,255,.4); }
.menu-manage { border-top: 1px solid rgba(255,255,255,.1) !important; margin-top: 4px; color: rgba(255,255,255,.5) !important; }

/* Nav */
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-group { margin-bottom: 2px; }
.nav-section {
    font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: rgba(255,255,255,.4); padding: 10px 16px 4px; cursor: pointer;
    user-select: none;
}
.nav-section:hover { color: rgba(255,255,255,.65); }
.nav-group-items { overflow: hidden; transition: max-height .25s ease; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px 8px 14px;
    font-size: .855rem; color: rgba(255,255,255,.7);
    border-left: 3px solid transparent;
    transition: background .12s, color .12s, border-color .12s;
    text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active {
    background: rgba(255,255,255,.12);
    border-left-color: var(--green-mid);
    color: #fff; font-weight: 600;
}
.nav-icon { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; }
.nav-badge {
    background: #e74c3c; color: #fff;
    font-size: .68rem; font-weight: 700;
    padding: 1px 5px; border-radius: 10px; min-width: 18px; text-align: center;
}
.nav-group.nav-collapsed .nav-group-items { max-height: 0 !important; }

/* User footer */
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255,255,255,.08);
}
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--green-mid); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: .82rem; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: rgba(255,255,255,.45); }
.user-logout {
    color: rgba(255,255,255,.45); font-size: 1.1rem; text-decoration: none;
    padding: 4px;
}
.user-logout:hover { color: #fff; text-decoration: none; }

/* Mobile sidebar */
.mobile-menu-btn {
    display: none; position: fixed; top: 12px; left: 12px; z-index: 62;
    background: var(--green); color: #fff; border: none;
    border-radius: var(--r-sm); padding: 8px 12px;
    font-size: 1.1rem; cursor: pointer;
    align-items: center; justify-content: center;
}
@media (max-width: 920px) {
    .mobile-menu-btn { display: flex; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: var(--shadow-pop); }
}
.sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 59;
    background: rgba(0,0,0,.4);
}
.sidebar-overlay.visible { display: block; }

/* ── Demo banner ─────────────────────────────────────────────────────── */
.demo-banner {
    position: fixed; top: 0; left: var(--sidebar-w); right: 0;
    background: var(--tone-pending-fg); color: #fff;
    font-size: .8rem; font-weight: 700;
    text-align: center; padding: 4px;
    z-index: 50;
}
@media (max-width: 920px) { .demo-banner { left: 0; } }

/* ── Page chrome ──────────────────────────────────────────────────────── */
.page-head {
    margin-bottom: 20px;
    display: flex; align-items: flex-start; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
}
.page-head h1.page-title, .page-title {
    font-size: 1.5rem; font-weight: 700; color: var(--ink);
}
.page-desc { font-size: .9rem; color: var(--ink-2); margin-top: 2px; }

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--r-lg);
    padding: 20px 24px;
    box-shadow: var(--shadow-card);
    margin-bottom: 20px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 700; }

/* ── KPI stats row ──────────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--white);
    border-radius: var(--r-md);
    padding: 16px 18px;
    box-shadow: var(--shadow-card);
    display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: .75rem; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.7rem; font-weight: 700; color: var(--green); }
.stat-sub   { font-size: .78rem; color: var(--ink-3); }

/* ── Table ───────────────────────────────────────────────────────────── */
.table-wrap {
    background: var(--white);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}
.mark-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.mark-table th {
    background: var(--green-tint);
    color: var(--green-dark);
    font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    padding: 11px 14px;
    text-align: left;
    border-bottom: 2px solid var(--green-border);
    white-space: nowrap;
}
.mark-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--ink);
}
.mark-table tr:last-child td { border-bottom: none; }
.mark-table tr:hover td { background: var(--green-tint); }

/* Monospace CIS codes */
.cis-code {
    font-family: var(--font-mono);
    font-size: .78rem;
    color: var(--ink-2);
    max-width: 160px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    display: block;
}

/* ── Status pills ────────────────────────────────────────────────────── */
.pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px; border-radius: 20px;
    font-size: .75rem; font-weight: 700; white-space: nowrap;
}
.tone-ok      { background: var(--tone-ok-bg);      color: var(--tone-ok-fg); }
.tone-pending { background: var(--tone-pending-bg);  color: var(--tone-pending-fg); }
.tone-reject  { background: var(--tone-reject-bg);   color: var(--tone-reject-fg); }
.tone-partial { background: var(--tone-partial-bg);  color: var(--tone-partial-fg); }
.tone-muted   { background: var(--tone-muted-bg);    color: var(--tone-muted-fg); }
.tone-info    { background: var(--tone-info-bg);     color: var(--tone-info-fg); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 18px; border-radius: var(--r-sm);
    font-family: var(--font); font-size: .875rem; font-weight: 600;
    cursor: pointer; border: 2px solid transparent;
    text-decoration: none; line-height: 1.2;
    transition: background .12s, border-color .12s, color .12s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
    background: var(--green); color: #fff;
    border-color: var(--green);
}
.btn-primary:hover { background: var(--green-dark); border-color: var(--green-dark); text-decoration: none; }
.btn-outline {
    background: transparent; color: var(--green);
    border-color: var(--green);
}
.btn-outline:hover { background: var(--green-tint); text-decoration: none; }
.btn-ghost {
    background: transparent; color: var(--ink-2);
    border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); text-decoration: none; }
.btn-danger {
    background: #c0392b; color: #fff; border-color: #c0392b;
}
.btn-danger:hover { background: #a93226; border-color: #a93226; text-decoration: none; }
.btn-lg { padding: 11px 24px; font-size: 1rem; border-radius: var(--r-md); }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-spin {
    display: inline-block; width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ───────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; }
.field input, .field select, .field textarea {
    width: 100%; padding: 9px 12px;
    border: 1.5px solid var(--border); border-radius: var(--r-sm);
    font-family: var(--font); font-size: .9rem; color: var(--ink);
    background: var(--white);
    transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(26,122,74,.15);
}
.field textarea { min-height: 80px; resize: vertical; }
.field-hint { font-size: .77rem; color: var(--ink-3); margin-top: 4px; }
.field-error { font-size: .77rem; color: var(--tone-reject-fg); margin-top: 4px; }
.input-suffix {
    position: relative;
}
.input-suffix input { padding-right: 40px; }
.suffix-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; color: var(--ink-3); font-size: 1rem;
}

/* Filter bar */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
    margin-bottom: 18px;
    background: var(--white);
    padding: 14px 18px; border-radius: var(--r-md);
    box-shadow: var(--shadow-card);
}
.filter-bar .field { margin-bottom: 0; }
.filter-bar .field label { font-size: .75rem; }
.filter-bar .field input,
.filter-bar .field select { padding: 6px 10px; font-size: .85rem; }

/* ── Alerts / callouts ────────────────────────────────────────────────── */
.callout {
    padding: 12px 16px; border-radius: var(--r-sm);
    margin-bottom: 16px; font-size: .875rem;
    display: flex; gap: 10px; align-items: flex-start;
}
.callout-success { background: var(--tone-ok-bg);      color: var(--tone-ok-fg);      border-left: 3px solid var(--tone-ok-fg); }
.callout-warning { background: var(--tone-pending-bg);  color: var(--tone-pending-fg); border-left: 3px solid var(--tone-pending-fg); }
.callout-danger  { background: var(--tone-reject-bg);   color: var(--tone-reject-fg);  border-left: 3px solid var(--tone-reject-fg); }
.callout-info    { background: var(--tone-info-bg);     color: var(--tone-info-fg);    border-left: 3px solid var(--tone-info-fg); }

/* ── Stub (empty state) ────────────────────────────────────────────────── */
.stub {
    text-align: center; padding: 48px 24px;
}
.stub-icon { font-size: 3rem; margin-bottom: 12px; }
.stub h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 6px; }
.stub p { font-size: .9rem; color: var(--ink-2); }

/* ── Toast notifications ────────────────────────────────────────────────── */
.toast-stack {
    position: fixed; bottom: 20px; right: 20px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast-card {
    background: var(--white); border-radius: var(--r-sm);
    box-shadow: var(--shadow-pop);
    padding: 12px 14px;
    display: flex; align-items: flex-start; gap: 10px;
    animation: toast-in .2s ease;
    border-left: 4px solid var(--green);
}
.toast-card.toast-success { border-left-color: var(--tone-ok-fg); }
.toast-card.toast-error   { border-left-color: var(--tone-reject-fg); }
.toast-card.toast-progress { border-left-color: var(--tone-partial-fg); }
.toast-icon { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.toast-body { flex: 1; font-size: .875rem; line-height: 1.4; }
.toast-x {
    background: none; border: none; cursor: pointer;
    color: var(--ink-3); font-size: 1.1rem; padding: 0; line-height: 1;
    flex-shrink: 0;
}
.toast-x:hover { color: var(--ink); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Login page ─────────────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--green-dark) 0%, #0d3d24 100%);
    padding: 20px;
}
.login-card {
    background: var(--white); border-radius: var(--r-lg);
    padding: 40px 40px 32px; max-width: 400px; width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .brand-icon { font-size: 3rem; }
.login-brand h1 { font-size: 1.6rem; font-weight: 800; color: var(--ink); margin-top: 8px; }
.login-brand p { font-size: .85rem; color: var(--ink-2); margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 4px; }
.login-foot { text-align: center; font-size: .78rem; color: var(--ink-3); margin-top: 20px; }

/* ── Access matrix (settings/access.php) ───────────────────────────── */
.access-matrix { border-collapse: collapse; width: 100%; font-size: .85rem; }
.access-matrix th, .access-matrix td {
    padding: 9px 12px; border: 1px solid var(--border); text-align: center;
}
.access-matrix thead th { background: var(--green-tint); color: var(--green-dark); font-weight: 700; }
.access-matrix thead th:first-child { text-align: left; }
.access-matrix tbody td:first-child { text-align: left; font-weight: 500; }
.access-matrix input[type=checkbox] {
    width: 16px; height: 16px; cursor: pointer; accent-color: var(--green);
}

/* ── Utility ─────────────────────────────────────────────────────────── */
.text-muted   { color: var(--ink-3); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.d-flex       { display: flex; }
.gap-2        { gap: 8px; }
.gap-3        { gap: 12px; }
.align-center { align-items: center; }
.flex-wrap    { flex-wrap: wrap; }
.flex-1       { flex: 1; }
.mt-2         { margin-top: 8px; }
.mt-3         { margin-top: 14px; }
.mb-3         { margin-bottom: 14px; }
.w-100        { width: 100%; }
.hidden       { display: none !important; }

/* ── Checkbox list (org access grants) ─────────────────────────────── */
.check-list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.check-list li label {
    display: flex; align-items: center; gap: 6px; cursor: pointer;
    background: var(--bg); border: 1.5px solid var(--border);
    border-radius: var(--r-sm); padding: 5px 10px;
    font-size: .83rem; font-weight: 500;
    transition: border-color .12s, background .12s;
}
.check-list li label:hover { border-color: var(--green); }
.check-list li input:checked + span { color: var(--green); }
.check-list li label:has(input:checked) {
    border-color: var(--green); background: var(--green-tint);
}

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.page-link {
    padding: 5px 10px; border: 1.5px solid var(--border);
    border-radius: var(--r-sm); font-size: .82rem;
    background: var(--white); color: var(--ink);
    cursor: pointer; text-decoration: none;
}
.page-link:hover { border-color: var(--green); color: var(--green); text-decoration: none; }
.page-link.active { background: var(--green); border-color: var(--green); color: #fff; }
