/* =========================================================================
   AuditTools design system — IBM Carbon design principles,
   using the project's existing green / slate palette.
   - IBM Plex Sans, sharp corners, 8px spacing grid
   - Carbon-style header, tiles, fields, buttons, data tables,
     tags, inline notifications and modals
   - Light / dark themes via body[data-theme]
   ========================================================================= */

/* ---------- Reset ---------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Tokens (light theme = default) ---------- */
:root, body {
    /* backgrounds */
    --bg: #f8fafc;
    --layer: #ffffff;
    --layer-accent: #f1f5f9;
    --layer-hover: #e6f4ea;
    --field: #f1f5f9;

    /* text */
    --text-primary: #1e293b;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-on-color: #ffffff;
    --text-inverse: #f3f4f6;

    /* borders */
    --border-subtle: #e5e7eb;
    --border-strong: #94a3b8;

    /* brand greens (kept from the original palette) */
    --green: #22c55e;
    --interactive: #16a34a;
    --interactive-hover: #047857;
    --focus: #10b981;
    --green-tint: rgba(16, 185, 129, 0.12);

    /* support */
    --support-error: #dc2626;
    --support-error-hover: #b91c1c;
    --support-warning: #f59e0b;
    --support-info: #3b82f6;

    /* notification surfaces */
    --notif-error-bg: #fef2f2;
    --notif-error-text: #b91c1c;
    --notif-success-bg: #f0fdf4;
    --notif-success-text: #15803d;
    --notif-warning-bg: #fffbeb;
    --notif-warning-text: #92400e;
    --notif-info-bg: #eff6ff;
    --notif-info-text: #1d4ed8;

    /* header is dark in both themes (Carbon UI shell) */
    --header-bg: #0f172a;
    --header-text: #d1d5db;
    --header-text-active: #f3f4f6;
    --header-hover: #1e293b;
    --header-border: #334155;

    /* charts */
    --chart-grid: #e5e7eb;
    --chart-tick: #6b7280;

    --overlay: rgba(15, 23, 42, 0.5);
    --shadow-modal: 0 8px 24px rgba(15, 23, 42, 0.2);
}

body[data-theme="dark"] {
    --bg: #0f172a;
    --layer: #1e293b;
    --layer-accent: #334155;
    --layer-hover: #3b4a64;
    --field: #334155;

    --text-primary: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;

    --border-subtle: #334155;
    --border-strong: #64748b;

    --interactive: #10b981;
    --interactive-hover: #34d399;
    --green-tint: rgba(16, 185, 129, 0.18);

    --notif-error-bg: #450a0a;
    --notif-error-text: #fca5a5;
    --notif-success-bg: #052e16;
    --notif-success-text: #86efac;
    --notif-warning-bg: #451a03;
    --notif-warning-text: #fcd34d;
    --notif-info-bg: #172554;
    --notif-info-text: #93c5fd;

    --chart-grid: #334155;
    --chart-tick: #9ca3af;

    --overlay: rgba(2, 6, 23, 0.7);
    --shadow-modal: 0 8px 24px rgba(0, 0, 0, 0.6);
}

/* ---------- Base ---------- */
html { scroll-behavior: smooth; }
body {
    font-family: 'IBM Plex Sans', 'Inter', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
    font-size: 0.875rem;
    line-height: 1.4286;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color 0.15s, color 0.15s;
}
a { color: var(--interactive); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--green-tint); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-strong); }

/* ---------- Type scale (Carbon productive set) ---------- */
h1, .heading-05 { font-size: 2rem;    font-weight: 400; line-height: 1.25;  letter-spacing: 0; }
h2, .heading-04 { font-size: 1.75rem; font-weight: 400; line-height: 1.28; }
h3, .heading-03 { font-size: 1.25rem; font-weight: 400; line-height: 1.4; }
h4, .heading-02 { font-size: 1rem;    font-weight: 600; line-height: 1.375; }
h5, .heading-01 { font-size: 0.875rem; font-weight: 600; line-height: 1.4286; }
.label-01  { font-size: 0.75rem; line-height: 1.34; letter-spacing: 0.32px; color: var(--text-secondary); }
.body-long { font-size: 0.875rem; line-height: 1.5; }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-error { color: var(--support-error); }
.text-success { color: var(--interactive); }
.mono { font-family: 'IBM Plex Mono', 'Consolas', monospace; }

/* ---------- UI Shell header ---------- */
.cds-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3rem;
    background: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    display: flex;
    align-items: center;
    z-index: 1000;
}
.cds-header__name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 100%;
    padding: 0 1rem;
    color: var(--header-text-active);
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.1px;
    text-decoration: none;
    white-space: nowrap;
}
.cds-header__name:hover { text-decoration: none; }
.cds-header__name i { color: var(--focus); }
.cds-header__name .prefix { font-weight: 400; color: var(--header-text); }
.cds-header__nav {
    display: flex;
    align-items: center;
    height: 100%;
    margin-left: 0.5rem;
    border-left: 1px solid var(--header-border);
    overflow-x: auto;
}
.cds-header__nav a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 100%;
    padding: 0 1rem;
    color: var(--header-text);
    font-size: 0.875rem;
    text-decoration: none;
    border-bottom: 3px solid transparent;
    border-top: 3px solid transparent;
    white-space: nowrap;
    transition: background-color 0.11s, color 0.11s;
}
.cds-header__nav a:hover { background: var(--header-hover); color: var(--header-text-active); text-decoration: none; }
.cds-header__nav a.active {
    color: var(--header-text-active);
    border-bottom-color: var(--focus);
    font-weight: 600;
}
.cds-header__global {
    margin-left: auto;
    display: flex;
    align-items: center;
    height: 100%;
}
.cds-header__action {
    width: 3rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--header-text);
    cursor: pointer;
    transition: background-color 0.11s;
    text-decoration: none;
    font-size: 1rem;
}
.cds-header__action:hover { background: var(--header-hover); color: var(--header-text-active); text-decoration: none; }
.cds-header__avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--green), var(--interactive-hover));
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 0.5rem;
    flex: none;
}

/* ---------- Page scaffolding ---------- */
.page {
    max-width: 82rem;
    margin: 0 auto;
    padding: 5rem 2rem 3rem;
}
.page--narrow { max-width: 42rem; }
.page-header { margin-bottom: 2rem; }
.page-header h1 { margin-bottom: 0.5rem; }
.page-header p { color: var(--text-secondary); max-width: 44rem; }
.section-title {
    font-size: 1.25rem;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.section-title i { color: var(--interactive); font-size: 1rem; }

/* ---------- Tiles ---------- */
.tile {
    background: var(--layer);
    border: 1px solid var(--border-subtle);
    padding: 1.5rem;
    transition: background-color 0.15s, border-color 0.15s;
}
.tile--clickable {
    display: block;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.11s, border-color 0.11s;
}
.tile--clickable:hover {
    background: var(--layer-hover);
    border-color: var(--focus);
    text-decoration: none;
    color: inherit;
}
.tile--clickable:focus-visible,
.btn:focus-visible, .cds-header__action:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
}
.tile--disabled { opacity: 0.55; cursor: not-allowed; }
.tile--disabled:hover { background: var(--layer); border-color: var(--border-subtle); }

/* stat tiles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: 1px;
    background: var(--border-subtle);
    border: 1px solid var(--border-subtle);
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--layer);
    padding: 1.25rem 1.5rem;
}
.stat-card .stat-label {
    font-size: 0.75rem;
    letter-spacing: 0.32px;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.stat-card .stat-label i { color: var(--interactive); }
.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 300;
    line-height: 1.2;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}
.stat-card .stat-value.small { font-size: 1.25rem; font-weight: 400; }

/* app launcher tiles */
.apps-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
    gap: 1rem;
}
.app-card { padding: 1.5rem; min-height: 11rem; display: flex; flex-direction: column; }
.app-icon {
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    background: var(--green-tint);
    color: var(--interactive);
    margin-bottom: 1rem;
}
.app-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.375rem; }
.app-description { color: var(--text-secondary); font-size: 0.875rem; flex: 1; }
.app-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    margin-top: 1rem;
    color: var(--text-secondary);
}
.status-dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--green); flex: none; }
.status-dot--pending { background: var(--support-warning); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.5rem;
    padding: 0 0.9375rem;
    border: 1px solid transparent;
    border-radius: 0;
    font-size: 0.875rem;
    font-weight: 400;
    letter-spacing: 0.16px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.11s, border-color 0.11s, color 0.11s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--interactive); color: #ffffff; }
.btn--primary:hover:not(:disabled) { background: var(--interactive-hover); }
.btn--secondary {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border-strong);
}
.btn--secondary:hover:not(:disabled) { background: var(--layer-hover); border-color: var(--interactive); color: var(--interactive-hover); }
.btn--ghost { background: transparent; color: var(--interactive); }
.btn--ghost:hover:not(:disabled) { background: var(--green-tint); }
.btn--danger { background: var(--support-error); color: #ffffff; }
.btn--danger:hover:not(:disabled) { background: var(--support-error-hover); }
.btn--danger-ghost { background: transparent; color: var(--support-error); }
.btn--danger-ghost:hover:not(:disabled) { background: var(--notif-error-bg); }
.btn--sm { min-height: 2rem; padding: 0 0.6875rem; font-size: 0.8125rem; }
.btn--lg { min-height: 3rem; padding: 0 1.5rem; }
.btn--full { width: 100%; justify-content: center; }

/* icon-only buttons (table row actions etc.) */
.icon-btn {
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.11s, color 0.11s;
    font-size: 0.875rem;
}
.icon-btn:hover { background: var(--layer-hover); color: var(--text-primary); }
.icon-btn--success:hover { color: var(--interactive); }
.icon-btn--danger:hover { color: var(--support-error); background: var(--notif-error-bg); }
.icon-btn--info:hover { color: var(--support-info); }
.icon-btn--warning:hover { color: var(--support-warning); }

/* ---------- Forms (Carbon fields: filled, bottom border) ---------- */
.form-item { margin-bottom: 1.5rem; }
.form-item > label, .form-label {
    display: block;
    font-size: 0.75rem;
    letter-spacing: 0.32px;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}
.input, .select, .textarea,
input[type="text"].cds, input[type="password"].cds, input[type="date"].cds,
input[type="email"].cds, input[type="search"].cds, input[type="file"].cds, select.cds, textarea.cds {
    width: 100%;
    height: 2.5rem;
    padding: 0 1rem;
    background: var(--field);
    color: var(--text-primary);
    border: none;
    border-bottom: 1px solid var(--border-strong);
    border-radius: 0;
    font-size: 0.875rem;
    transition: background-color 0.11s, outline 0.11s;
}
.textarea, textarea.cds { height: auto; min-height: 5rem; padding: 0.75rem 1rem; resize: vertical; }
input[type="file"].cds { padding: 0.4rem 1rem; }
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus,
.cds:focus {
    outline: 2px solid var(--focus);
    outline-offset: -2px;
    border-bottom-color: transparent;
}
.select, select.cds {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%236b7280' d='M5 6 0 1l.7-.7L5 4.6 9.3.3l.7.7z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }
.form-error-text { font-size: 0.75rem; color: var(--support-error); margin-top: 0.25rem; display: none; }
.form-item.invalid .form-error-text { display: block; }
.form-item.invalid .input, .form-item.invalid .select { outline: 2px solid var(--support-error); outline-offset: -2px; }

/* search box with leading icon */
.search-box { position: relative; }
.search-box .input { padding-left: 2.75rem; }
.search-box > i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

/* filter toolbar above tables */
.toolbar {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 1rem;
}
.toolbar .form-item { margin-bottom: 0; flex: 1 1 10rem; }
.toolbar .search-box { flex: 2 1 16rem; }

/* ---------- Data tables ---------- */
.table-container {
    background: var(--layer);
    border: 1px solid var(--border-subtle);
    overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
    background: var(--layer-accent);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.875rem;
    text-align: left;
    padding: 0 1rem;
    height: 3rem;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { background: var(--layer-hover); }
.data-table th .sort-icon { color: var(--text-muted); margin-left: 0.375rem; }
.data-table td {
    padding: 0.6875rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    vertical-align: middle;
}
.data-table td:first-child { color: var(--text-primary); }
.data-table tbody tr { transition: background-color 0.11s; }
.data-table tbody tr:hover { background: var(--layer-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 0.25rem; }

/* ---------- Tags ---------- */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    height: 1.5rem;
    padding: 0 0.625rem;
    border-radius: 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.tag--green  { background: var(--notif-success-bg); color: var(--notif-success-text); }
.tag--red    { background: var(--notif-error-bg);   color: var(--notif-error-text); }
.tag--amber  { background: var(--notif-warning-bg); color: var(--notif-warning-text); }
.tag--blue   { background: var(--notif-info-bg);    color: var(--notif-info-text); }
.tag--gray   { background: var(--layer-accent);     color: var(--text-secondary); }

/* ---------- Inline notifications ---------- */
.notification {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9375rem 1rem;
    border-left: 3px solid;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    position: relative;
}
.notification i.lead { margin-top: 0.125rem; }
.notification .dismiss {
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.25rem;
}
.notification--error   { background: var(--notif-error-bg);   color: var(--notif-error-text);   border-color: var(--support-error); }
.notification--success { background: var(--notif-success-bg); color: var(--notif-success-text); border-color: var(--green); }
.notification--warning { background: var(--notif-warning-bg); color: var(--notif-warning-text); border-color: var(--support-warning); }
.notification--info    { background: var(--notif-info-bg);    color: var(--notif-info-text);    border-color: var(--support-info); }

/* ---------- Modals ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal {
    background: var(--layer);
    border-top: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-modal);
    width: 100%;
    max-width: 30rem;
    max-height: 90vh;
    overflow-y: auto;
}
.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.5rem 1rem;
}
.modal__header h3 { font-size: 1.25rem; font-weight: 400; }
.modal__body { padding: 0.5rem 1rem 1.5rem; }
.modal__footer { display: flex; }
.modal__footer .btn { flex: 1; min-height: 3rem; justify-content: flex-start; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 1px; margin-top: 1rem; flex-wrap: wrap; }
.pagination a {
    min-width: 2.5rem;
    height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--layer);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
}
.pagination a:hover { background: var(--layer-hover); text-decoration: none; }
.pagination a.active { border-bottom: 2px solid var(--interactive); color: var(--text-primary); font-weight: 600; }

/* ---------- Misc ---------- */
.chart-container { background: var(--layer); border: 1px solid var(--border-subtle); padding: 1.5rem; }
.avatar-sm {
    width: 2rem; height: 2rem; border-radius: 50%;
    object-fit: cover; border: 1px solid var(--border-subtle);
    background: var(--layer-accent);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.8125rem; font-weight: 600; color: var(--text-primary);
    flex: none;
}
.avatar-lg {
    width: 5rem; height: 5rem; border-radius: 50%;
    object-fit: cover; border: 1px solid var(--border-subtle);
    background: var(--layer-accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 600; color: var(--text-primary);
}
.spinner {
    width: 1rem; height: 1rem;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
}
.loading .spinner { display: inline-block; }
.spinner--accent { border-color: var(--border-subtle); border-top-color: var(--interactive); }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--text-secondary); }
.empty-state i { font-size: 2.5rem; color: var(--text-muted); margin-bottom: 1rem; display: block; }
.empty-state h3 { color: var(--text-primary); margin-bottom: 0.375rem; }
.skip-fade { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Utilities ---------- */
.flex { display: flex; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.gap-1 { gap: 0.25rem; } .gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.75rem; } .gap-4 { gap: 1rem; } .gap-6 { gap: 1.5rem; }
.mb-1 { margin-bottom: 0.25rem; } .mb-2 { margin-bottom: 0.5rem; } .mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; } .mb-6 { margin-bottom: 1.5rem; } .mb-8 { margin-bottom: 2rem; }
.mt-2 { margin-top: 0.5rem; } .mt-4 { margin-top: 1rem; } .mt-6 { margin-top: 1.5rem; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); border: 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .page { padding: 4.5rem 1rem 2rem; }
    .cds-header__nav a span { display: none; }
    .cds-header__nav a { padding: 0 0.75rem; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .form-item, .toolbar .search-box { flex: 1 1 auto; }
}
@media print {
    .cds-header, .btn, .icon-btn, .toolbar { display: none !important; }
    .page { padding-top: 0; }
}
