/* =========================================================================
   PharmaFlow — design system
   A calm, clinical aesthetic: deep ink + slate surfaces, a precise
   medicinal teal accent, and typography tuned for dense operational data.
   ========================================================================= */

:root {
    /* Palette */
    --ink: #0f1b2d;          /* near-black navy for the sidebar & headings */
    --ink-2: #16263d;
    --slate-900: #1e293b;
    --slate-700: #334155;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-300: #cbd5e1;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --slate-50: #f8fafc;
    --paper: #ffffff;

    --teal: #0d9488;         /* primary accent — medicinal green-teal */
    --teal-dark: #0f766e;
    --teal-soft: #ccfbf1;
    --teal-50: #f0fdfa;

    --amber: #d97706;
    --amber-soft: #fef3c7;
    --red: #dc2626;
    --red-soft: #fee2e2;
    --green: #16a34a;
    --green-soft: #dcfce7;
    --blue: #2563eb;
    --blue-soft: #dbeafe;
    --violet: #7c3aed;
    --violet-soft: #ede9fe;

    /* Type */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

    /* Shape & depth */
    --radius: 10px;
    --radius-sm: 7px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.06), 0 1px 3px rgba(15, 27, 45, 0.05);
    --shadow: 0 4px 12px rgba(15, 27, 45, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 27, 45, 0.14);

    --sidebar-w: 256px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--slate-700);
    background: var(--slate-100);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--teal-dark); text-decoration: none; }
a:hover { color: var(--teal); }

h1, h2, h3, h4, h5 { color: var(--ink); font-weight: 650; letter-spacing: -0.01em; margin: 0; }

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

.sidebar {
    width: var(--sidebar-w);
    background: var(--ink);
    color: var(--slate-300);
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform 0.25s ease;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.sidebar__mark {
    width: 34px; height: 34px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--teal), var(--teal-dark));
    display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 16px;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.4);
}

.sidebar__brand-name { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.sidebar__brand-sub { font-size: 11px; color: var(--slate-400); letter-spacing: 0.04em; text-transform: uppercase; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.sidebar__group-label {
    font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--slate-500); padding: 16px 12px 8px;
}
.sidebar__group-label:first-child { padding-top: 4px; }

.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--slate-300); font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link.is-active { background: var(--teal); color: #fff; box-shadow: var(--shadow-sm); }
.nav-link.is-active:hover { color: #fff; }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }

.sidebar__footer { padding: 14px 18px; border-top: 1px solid rgba(255, 255, 255, 0.07); font-size: 12px; color: var(--slate-500); }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 62px;
    background: var(--paper);
    border-bottom: 1px solid var(--slate-200);
    display: flex; align-items: center; gap: 16px;
    padding: 0 26px;
    position: sticky; top: 0; z-index: 30;
}
.topbar__title { font-size: 17px; font-weight: 650; }
.topbar__spacer { flex: 1; }

.topbar__user { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--teal-soft); color: var(--teal-dark);
    display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.topbar__user-meta { line-height: 1.25; }
.topbar__user-name { font-weight: 600; color: var(--ink); font-size: 13px; }
.topbar__user-role { font-size: 11px; color: var(--slate-500); }

.content { padding: 26px; max-width: 1440px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head__title { font-size: 22px; }
.page-head__sub { color: var(--slate-500); margin-top: 3px; font-size: 13px; }
.page-head__actions { display: flex; gap: 10px; }

/* mobile menu */
.menu-toggle { display: none; background: none; border: none; padding: 6px; color: var(--slate-700); cursor: pointer; }
.scrim { display: none; }

/* ------------------------------------------------------------------ cards */
.card {
    background: var(--paper);
    border: 1px solid var(--slate-200);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__head { padding: 16px 20px; border-bottom: 1px solid var(--slate-200); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card__title { font-size: 15px; }
.card__body { padding: 20px; }
.card__body--flush { padding: 0; }

/* ------------------------------------------------------------------ stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat {
    background: var(--paper); border: 1px solid var(--slate-200); border-radius: var(--radius);
    padding: 18px 20px; box-shadow: var(--shadow-sm);
    position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--teal); }
.stat--amber::before { background: var(--amber); }
.stat--red::before { background: var(--red); }
.stat--blue::before { background: var(--blue); }
.stat__label { font-size: 12px; color: var(--slate-500); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.stat__value { font-size: 30px; font-weight: 720; color: var(--ink); line-height: 1.1; margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat__meta { font-size: 12px; color: var(--slate-400); margin-top: 4px; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
    text-align: left; padding: 11px 16px; font-size: 11px; font-weight: 650;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--slate-500);
    background: var(--slate-50); border-bottom: 1px solid var(--slate-200); white-space: nowrap;
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--slate-100); color: var(--slate-700); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--teal-50); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); font-size: 12.5px; }
table.data .mono { font-family: var(--font-mono); font-size: 12.5px; }
.cell-strong { color: var(--ink); font-weight: 600; }
.cell-sub { color: var(--slate-400); font-size: 12px; }

/* ------------------------------------------------------------------ badges */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; line-height: 1.4;
    background: var(--slate-100); color: var(--slate-700);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--green { background: var(--green-soft); color: #15803d; }
.badge--amber { background: var(--amber-soft); color: #b45309; }
.badge--red { background: var(--red-soft); color: #b91c1c; }
.badge--blue { background: var(--blue-soft); color: #1d4ed8; }
.badge--teal { background: var(--teal-soft); color: var(--teal-dark); }
.badge--violet { background: var(--violet-soft); color: #6d28d9; }
.badge--slate { background: var(--slate-200); color: var(--slate-700); }
.badge--plain::before { display: none; }

/* ------------------------------------------------------------------ buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 600; cursor: pointer;
    border: 1px solid transparent; transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    white-space: nowrap; line-height: 1;
}
.btn svg { width: 16px; height: 16px; }
.btn--primary { background: var(--teal); color: #fff; box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--teal-dark); color: #fff; }
.btn--ghost { background: var(--paper); color: var(--slate-700); border-color: var(--slate-300); }
.btn--ghost:hover { border-color: var(--slate-400); background: var(--slate-50); color: var(--ink); }
.btn--danger { background: var(--red); color: #fff; }
.btn--danger:hover { background: #b91c1c; color: #fff; }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------------------------------------------ forms */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.form-grid--3 { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--slate-700); }
.field label .req { color: var(--red); }
.field .hint { font-size: 11.5px; color: var(--slate-400); }

.input, .select, .textarea {
    width: 100%; padding: 9px 12px; font-size: 13.5px; font-family: inherit;
    color: var(--ink); background: var(--paper);
    border: 1px solid var(--slate-300); border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.14);
}
.textarea { resize: vertical; min-height: 84px; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--red); }
.field-error { color: var(--red); font-size: 12px; margin-top: 2px; }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--teal); }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--slate-200); }

/* ------------------------------------------------------------------ alerts */
.alert {
    display: flex; align-items: flex-start; gap: 11px;
    padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 13.5px;
    border: 1px solid transparent;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert--success { background: var(--green-soft); color: #15803d; border-color: #bbf7d0; }
.alert--error { background: var(--red-soft); color: #b91c1c; border-color: #fecaca; }
.alert--info { background: var(--blue-soft); color: #1d4ed8; border-color: #bfdbfe; }
.alert--warn { background: var(--amber-soft); color: #b45309; border-color: #fde68a; }

/* ------------------------------------------------------------------ empty state */
.empty { text-align: center; padding: 54px 20px; color: var(--slate-500); }
.empty__icon {
    width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 14px;
    background: var(--slate-100); display: grid; place-items: center; color: var(--slate-400);
}
.empty__icon svg { width: 26px; height: 26px; }
.empty h3 { font-size: 16px; margin-bottom: 5px; }
.empty p { max-width: 380px; margin: 0 auto 16px; }

/* ------------------------------------------------------------------ misc */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search { flex: 1; min-width: 200px; max-width: 340px; position: relative; }
.toolbar .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--slate-400); }
.toolbar .search .input { padding-left: 34px; }

.pagination { display: flex; gap: 4px; list-style: none; padding: 16px 20px; margin: 0; justify-content: flex-end; }
.pagination li { }
.pagination a, .pagination span {
    display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 8px;
    border-radius: var(--radius-sm); font-size: 13px; color: var(--slate-600);
    border: 1px solid var(--slate-200); background: var(--paper);
}
.pagination .active span { background: var(--teal); color: #fff; border-color: var(--teal); }
.pagination .disabled span { color: var(--slate-300); }

.meta-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px 24px; }
.meta-item .meta-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--slate-500); font-weight: 600; }
.meta-item .meta-value { font-size: 14px; color: var(--ink); margin-top: 3px; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; align-items: start; }
.section-gap { margin-bottom: 22px; }

/* stage timeline */
.stage-list { list-style: none; margin: 0; padding: 0; }
.stage-item { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--slate-100); }
.stage-item:last-child { border-bottom: none; }
.stage-dot { width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-weight: 700; font-size: 12px; background: var(--slate-100); color: var(--slate-500); }
.stage-dot.done { background: var(--green-soft); color: #15803d; }
.stage-dot.active { background: var(--teal); color: #fff; }
.stage-body { flex: 1; }
.stage-name { font-weight: 600; color: var(--ink); }

/* login / install */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-aside { background: var(--ink); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside::after { content: ""; position: absolute; right: -120px; bottom: -120px; width: 380px; height: 380px; border-radius: 50%; background: radial-gradient(circle, rgba(13,148,136,0.35), transparent 70%); }
.auth-aside__brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.auth-aside__pitch { position: relative; z-index: 1; }
.auth-aside__pitch h2 { color: #fff; font-size: 30px; line-height: 1.2; letter-spacing: -0.02em; }
.auth-aside__pitch p { color: var(--slate-400); margin-top: 14px; font-size: 15px; max-width: 380px; }
.auth-features { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 12px; position: relative; z-index: 1; }
.auth-features li { display: flex; align-items: center; gap: 10px; color: var(--slate-300); font-size: 14px; }
.auth-features svg { width: 18px; height: 18px; color: var(--teal); }
.auth-main { display: grid; place-items: center; padding: 40px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card__sub { color: var(--slate-500); margin-bottom: 26px; }

.demo-note { margin-top: 18px; padding: 12px 14px; background: var(--teal-50); border: 1px solid var(--teal-soft); border-radius: var(--radius-sm); font-size: 12.5px; color: var(--teal-dark); }
.demo-note strong { color: var(--teal-dark); }

/* progress steps for installer */
.steps { display: flex; gap: 8px; margin-bottom: 30px; }
.steps li { flex: 1; list-style: none; text-align: center; font-size: 12px; color: var(--slate-400); }
.steps li .dot { width: 28px; height: 28px; border-radius: 50%; background: var(--slate-200); color: var(--slate-500); display: grid; place-items: center; margin: 0 auto 6px; font-weight: 700; }
.steps li.done .dot { background: var(--green); color: #fff; }
.steps li.current .dot { background: var(--teal); color: #fff; }
.steps li.current { color: var(--ink); font-weight: 600; }

.req-list { list-style: none; padding: 0; margin: 0; }
.req-list li { display: flex; align-items: center; justify-content: space-between; padding: 11px 4px; border-bottom: 1px solid var(--slate-100); }
.req-list li:last-child { border-bottom: none; }

.progress-bar { height: 8px; background: var(--slate-200); border-radius: 999px; overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: var(--teal); border-radius: 999px; }

/* trace tree */
.trace-col h4 { font-size: 13px; margin-bottom: 10px; color: var(--slate-600); }

@media (max-width: 1080px) {
    .grid-2 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
    .auth-wrap { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.is-open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex; }
    .scrim.is-open { display: block; position: fixed; inset: 0; background: rgba(15, 27, 45, 0.5); z-index: 35; }
    .stat-grid { grid-template-columns: 1fr; }
    .content { padding: 18px; }
    .page-head { flex-direction: column; align-items: stretch; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* focus visibility everywhere */
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* Permission checkbox groups (roles form) */
.perm-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.perm-group { border: 1px solid var(--slate-200); border-radius: 10px; padding: 14px 16px; background: var(--slate-50); }
.perm-group__title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--slate-500); margin-bottom: 10px; }
.perm-group .check { margin-bottom: 8px; }
.perm-group .check:last-child { margin-bottom: 0; }

/* Prose block for longer text */
.prose { color: var(--slate-700); line-height: 1.6; white-space: pre-wrap; margin: 0; }

/* Report launcher tiles */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.report-tile { display: flex; gap: 14px; align-items: flex-start; padding: 20px; border: 1px solid var(--slate-200); border-radius: 12px; background: var(--paper); text-decoration: none; color: inherit; transition: border-color .15s, transform .15s, box-shadow .15s; }
.report-tile:hover { border-color: var(--teal); transform: translateY(-2px); box-shadow: var(--shadow); }
.report-tile__icon { width: 40px; height: 40px; border-radius: 10px; background: var(--teal-soft); color: var(--teal-dark); display: grid; place-items: center; flex: none; }
.report-tile__icon svg { width: 20px; height: 20px; }
.report-tile h3 { margin: 0 0 4px; font-size: 15px; color: var(--ink); }
.report-tile p { margin: 0; font-size: 13px; color: var(--slate-500); line-height: 1.45; }

/* Inline field for filter toolbars */
.field--inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field--inline .label { margin: 0; font-size: 12px; color: var(--slate-500); white-space: nowrap; }
.field--inline .input { max-width: 170px; }
