/* ══════════════════════════════════════════════
   Aphias Internal Apps
   ══════════════════════════════════════════════ */

:root {
    --bg: #F0F2F5;
    --bg-card: #FFFFFF;
    --bg-hover: #E8EBF0;
    --bg-input: #FFFFFF;
    --border: #D0D4DC;
    --border-light: #E5E7EB;
    --text: #1A1A1A;
    --text2: #444444;
    --muted: #6B7280;
    --muted-light: #9CA3AF;
    --blue: #0066CC;
    --blue-light: #DBEAFE;
    --green: #16A34A;
    --green-light: #D1FAE5;
    --red: #DC2626;
    --red-light: #FEE2E2;
    --orange: #D97706;
    --orange-light: #FEF3C7;
    --purple: #7C3AED;
    --purple-light: #EDE9FE;
    --topbar-bg: #1A1A2E;
    --sidebar-bg: #1A1A2E;
    --sidebar-hover: #2A2A40;
    --sidebar-active: #3B82F6;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

code, pre {
    font-family: var(--mono);
    font-size: 12.5px;
}
code {
    background: rgba(0,0,0,0.04);
    padding: 1px 5px;
    border-radius: 3px;
    color: var(--text2);
}
code.small { font-size: 11.5px; }

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

/* ── Topbar ── */
.topbar {
    height: 48px;
    background: var(--topbar-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 200;
}
.topbar-left { display: flex; align-items: center; gap: 8px; overflow: hidden; min-width: 0; flex: 1; }
.topbar-logo-img { height: 28px; width: auto; max-width: 120px; margin-right: 8px; object-fit: contain; flex-shrink: 0; }
.topbar-sub { color: #A0A8B8; font-size: 11px; white-space: nowrap; letter-spacing: 0.5px; text-transform: uppercase; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.topbar-user { color: #A0A8B8; font-size: 12px; }
.topbar-logout {
    color: #A0A8B8; text-decoration: none; font-size: 16px;
    margin-left: 8px; opacity: 0.6; transition: opacity 0.2s;
}
.topbar-logout:hover { opacity: 1; }

.role-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.role-admin  { background: var(--orange-light); color: var(--orange); }
.role-viewer { background: var(--blue-light); color: var(--blue); }

/* ── Hamburger ── */
.hamburger {
    display: none; background: none; border: none; cursor: pointer;
    padding: 4px; flex-direction: column; gap: 4px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: #A0A8B8; border-radius: 2px; }

/* ── Layout ── */
.app-body {
    display: flex;
    margin-top: 48px;
    min-height: calc(100vh - 48px);
}

.sidebar {
    width: 200px;
    min-width: 200px;
    background: var(--sidebar-bg);
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 48px;
    bottom: 0;
    overflow-y: auto;
}
.sidebar-overlay { display: none; }

.sidebar-section { margin-bottom: 16px; }
.sidebar-heading {
    color: #6B7280;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 8px 16px 4px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: #C8CCD8;
    text-decoration: none;
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
    text-decoration: none;
}
.sidebar-link.active {
    background: var(--sidebar-hover);
    color: #fff;
    border-left-color: var(--sidebar-active);
}
.sidebar-icon { font-size: 15px; line-height: 1; }
.sidebar-label { flex: 1; }

.content {
    flex: 1;
    margin-left: 200px;
    padding: 24px 28px;
    max-width: 1600px;
    width: 100%;
}

/* ── Page header ── */
.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 22px; font-weight: 600; margin-bottom: 4px; }
.page-header p  { color: var(--muted); }
.page-header code { font-size: 12px; }

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}
.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.card-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.card-row .card { margin-bottom: 0; }

/* ── KPI Grid ── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}
.kpi-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.kpi-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    margin-bottom: 2px;
    font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 11px; }

.text-red { color: var(--red); }
.text-orange { color: var(--orange); }
.text-green { color: var(--green); }

/* ── Live state strip ── */
.live-strip {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 13px;
    box-shadow: var(--shadow);
}
.live-strip-warn { background: var(--orange-light); color: var(--orange); }
.live-strip .sep { color: var(--muted-light); }
.dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 2px;
}
.dot-green { background: var(--green); box-shadow: 0 0 0 3px var(--green-light); }
.dot-red   { background: var(--red); }

/* ── Tables ── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.data-table th,
.data-table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-light);
}
.data-table th {
    background: #F8F9FB;
    font-weight: 600;
    color: var(--text2);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.data-table tr:hover td { background: #FAFAFA; }
.data-table.compact th,
.data-table.compact td { padding: 6px 10px; }
.data-table td.num,
.data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.row-err td { background: #FFF7F7; }
.data-table tr.row-err:hover td { background: #FEE2E2; }
.data-table tr.row-warn td { background: #FFFBEB; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.badge-ok      { background: var(--green-light); color: var(--green); }
.badge-err     { background: var(--red-light); color: var(--red); }
.badge-warn    { background: var(--orange-light); color: var(--orange); }
.badge-neutral { background: var(--bg-hover); color: var(--text2); }

/* ── Buttons ── */
.btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn.small { padding: 4px 10px; font-size: 12px; }

.btn-primary {
    background: var(--blue);
    color: #fff;
    border-color: var(--blue);
}
.btn-primary:hover { background: #0055AA; border-color: #0055AA; color: #fff; }

.btn-warn {
    background: var(--orange);
    color: #fff;
    border-color: var(--orange);
}
.btn-warn:hover { background: #B45309; border-color: #B45309; color: #fff; }

/* ── Segmented control ── */
.seg-control {
    display: inline-flex;
    background: #F3F4F6;
    padding: 2px;
    border-radius: var(--radius);
}
.seg-control button {
    background: transparent;
    border: none;
    padding: 5px 11px;
    border-radius: 4px;
    color: var(--muted);
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s;
}
.seg-control button.active {
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow);
}

/* ── Forms ── */
.filter-form, .filter-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.filter-form select,
.filter-form input[type="text"] {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
}
.filter-form select:focus,
.filter-form input:focus { outline: none; border-color: var(--blue); }

.check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* ── Subnav (tool-level) ── */
.subnav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.subnav-left, .subnav-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.subnav-title {
    font-size: 14px;
    font-weight: 600;
    margin-right: 12px;
}
.subnav-link {
    padding: 5px 11px;
    border-radius: 4px;
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
    font-weight: 500;
}
.subnav-link:hover { background: var(--bg-hover); text-decoration: none; color: var(--text); }
.subnav-link.active { background: var(--blue); color: #fff; }
.subnav-link.active:hover { background: var(--blue); color: #fff; }

/* ── Chart ── */
.chart-card { padding-bottom: 8px; }
.chart-wrap {
    padding: 12px 16px;
    height: 260px;
    position: relative;
}
.chart-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
}
.chart-legend {
    padding: 4px 16px 12px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 12px;
    color: var(--muted);
}
.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* ── Tool grid (home page) ── */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}
.tool-card {
    display: flex;
    gap: 14px;
    padding: 18px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-decoration: none;
    color: var(--text);
    transition: transform 0.15s, box-shadow 0.15s;
    border: 1px solid transparent;
}
.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--blue-light);
    text-decoration: none;
}
.tool-icon { font-size: 32px; line-height: 1; }
.tool-body h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.tool-body p  { font-size: 13px; color: var(--muted); }

/* ── KV grid (detail pages) ── */
.kv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    padding: 16px;
}
.kv-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 2px;
}
.kv-value {
    font-size: 14px;
    color: var(--text);
}

.error-box {
    background: var(--red-light);
    border: 1px solid #FCA5A5;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin: 0 16px 16px;
}
.error-label {
    font-size: 11px;
    color: var(--red);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.error-box pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 12px;
    color: var(--text);
}

/* ── Flash messages ── */
.flash {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 12px;
}
.flash-error   { background: var(--red-light); color: var(--red); border: 1px solid #FCA5A5; }
.flash-warning { background: var(--orange-light); color: var(--orange); border: 1px solid #FCD34D; }
.flash-success { background: var(--green-light); color: var(--green); border: 1px solid #86EFAC; }
.flash-info    { background: var(--blue-light); color: var(--blue); border: 1px solid #BFDBFE; }

/* ── Empty state ── */
.empty-state {
    padding: 32px;
    text-align: center;
    color: var(--muted);
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ── Login page ── */
.login-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #1A1A2E 0%, #2D3258 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: #fff;
    padding: 36px 32px;
    border-radius: 8px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    text-align: center;
}
.login-logo {
    height: 36px;
    margin-bottom: 16px;
    filter: invert(1);
}
.login-card h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 4px;
}
.login-card p { font-size: 13px; }
.login-btn {
    display: block;
    width: 100%;
    margin: 22px 0 12px;
    padding: 11px;
    font-size: 14px;
}
.login-foot { font-size: 12px; margin-top: 8px; }

/* ── Responsive ── */
@media (max-width: 800px) {
    .hamburger { display: flex; }
    .sidebar { transform: translateX(-100%); transition: transform 0.22s; z-index: 150; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay {
        display: block;
        position: fixed;
        top: 48px;
        left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 140;
    }
    .content { margin-left: 0; padding: 16px; }
}
