/* Admin theme. Layered over Bootstrap 5.3, which supplies the grid and the
   utility classes; everything below is the part that makes it look like one
   product rather than a default template. */

/* Padding counts inside a declared width or height. Without this the rail's
   100vh becomes 100vh plus its padding and slips out of its sticky slot, and
   a full-width input overflows the panel holding it. */
*, *::before, *::after { box-sizing: border-box; }

/* ============ PHARMACEUTICAL UI ENHANCEMENTS ============ */
@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-12px); }
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 15px rgba(96, 165, 250, 0.3); }
    50% { box-shadow: 0 0 30px rgba(96, 165, 250, 0.6); }
}

@keyframes shimmer-gradient {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes card-hover {
    0% { transform: translateY(0); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); }
    100% { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(96, 165, 250, 0.2); }
}

/* Smooth transitions for all admin elements */
.admin-shell, .admin-rail, .nav-item, button, input, select, textarea {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Enhance card and panel elements with glassmorphism */
.card, [class*="panel"], [class*="card"], [class*="box"], .stat {
    background: var(--admin-surface) !important;
    border: 1px solid var(--admin-border) !important;
    border-radius: 12px !important;
    backdrop-filter: blur(10px) !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2) !important;
    animation: slide-up 0.5s ease-out;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover, [class*="panel"]:hover, .stat:hover {
    transform: translateY(-4px);
    background: var(--admin-surface-2) !important;
    border-color: #60a5fa !important;
    box-shadow: 0 25px 70px rgba(96, 165, 250, 0.2) !important;
}

/* Buttons with gradient */
button, input[type="submit"], .btn {
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%) !important;
    border: none !important;
    color: #ffffff !important;
    transition: all 0.3s ease;
    border-radius: 8px !important;
}

button:hover, input[type="submit"]:hover, .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(74, 144, 226, 0.4) !important;
}

:root {
    --admin-bg: #f4f6fb;
    --admin-surface: #ffffff;
    --admin-surface-2: #f8fafc;
    --admin-border: #e2e8f0;
    --admin-text: #0f172a;
    --admin-muted: #64748b;
    --admin-accent: #2563eb;
    --admin-accent-soft: #dbeafe;
    --admin-rail: #0f172a;
    --admin-rail-text: #cbd5e1;
    --admin-rail-active: #1e293b;
    --admin-good: #059669;
    --admin-warn: #d97706;
    --admin-bad: #dc2626;
    --admin-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
    --admin-radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --admin-bg: linear-gradient(135deg, #1a1f3a 0%, #0f1419 100%);
        --admin-surface: rgba(255, 255, 255, 0.08);
        --admin-surface-2: rgba(255, 255, 255, 0.05);
        --admin-border: rgba(74, 144, 226, 0.2);
        --admin-text: #e5e7eb;
        --admin-muted: #94a3b8;
        --admin-accent: #60a5fa;
        --admin-accent-soft: #1e3a8a;
        --admin-rail: linear-gradient(180deg, #060b16 0%, #0a0f1e 100%);
        --admin-rail-text: #94a3b8;
        --admin-rail-active: rgba(96, 165, 250, 0.2);
        --admin-good: #34d399;
        --admin-warn: #fbbf24;
        --admin-bad: #f87171;
        --admin-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }
}

body.admin {
    background: var(--admin-bg);
    color: var(--admin-text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    min-height: 100vh;
    position: relative;
}

body.admin::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 20% 50%, rgba(74, 144, 226, 0.1) 0%, transparent 50%),
                radial-gradient(circle at 80% 50%, rgba(16, 185, 129, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* ---- shell ---------------------------------------------------------- */

.admin-shell { display: flex; min-height: 100vh; }

.admin-rail {
    background: var(--admin-rail);
    color: var(--admin-rail-text);
    width: 232px;
    flex: 0 0 232px;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    /* Pinned to the viewport: these pages run to several screens, and the way
       back to the rest of the admin must not scroll away with the content.
       align-self stops the flex row stretching it, which would break sticky. */
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
    z-index: 20;
}

.admin-rail .brand {
    color: #fff;
    font-weight: 650;
    font-size: 1.05rem;
    letter-spacing: -.01em;
    padding: 4px 10px 16px;
    display: flex;
    align-items: center;
    gap: 9px;
}

.admin-rail .brand .dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--admin-good);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, .22);
}

.admin-rail a.nav-item {
    color: var(--admin-rail-text);
    text-decoration: none;
    padding: 9px 11px;
    border-radius: 9px;
    font-size: .89rem;
    display: block;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.admin-rail a.nav-item:hover {
    background: linear-gradient(135deg, rgba(96, 165, 250, 0.2), rgba(34, 197, 94, 0.1));
    color: #60a5fa;
    border-color: rgba(96, 165, 250, 0.3);
    transform: translateX(4px);
}

.admin-rail a.nav-item.active {
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
    color: #fff;
    font-weight: 550;
    border-color: #60a5fa;
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.3);
}

.admin-rail a.search-app-link {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(96, 165, 250, 0.15));
    border: 1px solid rgba(34, 197, 94, 0.3) !important;
    color: #34d399 !important;
    font-weight: 600;
    margin-top: 8px;
}

.admin-rail a.search-app-link:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.3), rgba(96, 165, 250, 0.2));
    color: #6ee7b7 !important;
    border-color: #34d399 !important;
    box-shadow: 0 8px 20px rgba(52, 211, 153, 0.2);
    transform: translateX(4px);
}

.admin-rail .rail-foot {
    margin-top: auto;
    border-top: 1px solid rgba(96, 165, 250, 0.15);
    padding-top: 14px;
    font-size: .78rem;
}

.admin-rail .rail-foot strong {
    color: #60a5fa;
}

.admin-rail .rail-foot .btn-quiet,
.admin-rail .rail-foot button {
    width: 100%;
    background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
    color: #fff;
    border: 1px solid rgba(96, 165, 250, 0.3);
    padding: 10px 16px;
    border-radius: 8px;
    font-size: .89rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-top: 12px;
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.2);
}

.admin-rail .rail-foot button:hover {
    background: linear-gradient(135deg, #357abd 0%, #2a5a9e 100%);
    border-color: #60a5fa;
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(74, 144, 226, 0.4);
}

.admin-rail .rail-foot button:active {
    transform: translateY(0);
}

.admin-main { flex: 1 1 auto; padding: 26px 30px 60px; min-width: 0; }

.admin-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 20px; flex-wrap: wrap; margin-bottom: 22px;
}

.admin-head h1 { font-size: 1.5rem; font-weight: 650; letter-spacing: -.02em; margin: 0; }
.admin-head .sub { color: var(--admin-muted); font-size: .87rem; margin-top: 4px; }

/* ---- cards ---------------------------------------------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 26px;
}

.stat {
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
    padding: 16px 18px;
    box-shadow: var(--admin-shadow);
}

.stat .label {
    color: var(--admin-muted);
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    font-weight: 600;
}

.stat .value {
    font-size: 1.7rem; font-weight: 650; letter-spacing: -.03em;
    margin-top: 6px; font-variant-numeric: tabular-nums;
}

.stat .foot { color: var(--admin-muted); font-size: .78rem; margin-top: 2px; }

.panel {
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow);
    margin-bottom: 22px;
    overflow: hidden;
}

.panel > header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--admin-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--admin-surface-2);
}

.panel > header h2 { font-size: .95rem; font-weight: 620; margin: 0; letter-spacing: -.01em; }
.panel > header .hint { color: var(--admin-muted); font-size: .78rem; }
.panel .panel-body { padding: 16px 18px; }

.panel-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 22px;
    align-items: start;
}

/* ---- tables --------------------------------------------------------- */

.admin-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.admin-table th {
    text-align: left; font-weight: 600; color: var(--admin-muted);
    font-size: .73rem; text-transform: uppercase; letter-spacing: .06em;
    padding: 10px 18px; border-bottom: 1px solid var(--admin-border);
    background: var(--admin-surface-2);
}
/* Only a table inside its own scroll box has a header worth pinning; in a
   table that grows with the page it would float over the rows instead. */
.table-scroll .admin-table th { position: sticky; top: 0; z-index: 1; }
.admin-table td { padding: 10px 18px; border-bottom: 1px solid var(--admin-border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: var(--admin-surface-2); }
.admin-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { max-height: 420px; overflow: auto; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8em; }
.truncate { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- pills and bars -------------------------------------------------- */

.pill {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: .72rem; font-weight: 600; letter-spacing: .02em; white-space: nowrap;
}
.pill.healthy { background: rgba(5, 150, 105, .13); color: var(--admin-good); }
.pill.degraded { background: rgba(217, 119, 6, .14); color: var(--admin-warn); }
.pill.poor { background: rgba(217, 119, 6, .2); color: var(--admin-warn); }
.pill.down { background: rgba(220, 38, 38, .13); color: var(--admin-bad); }
.pill.neutral { background: var(--admin-accent-soft); color: var(--admin-accent); }
/* Ran cleanly but had nothing to publish, or never tries to: not a fault. */
.pill.empty,
.pill.handoff,
.pill.unknown { background: rgba(100, 116, 139, .18); color: var(--admin-muted); }

.pct-none { color: var(--admin-muted); font-size: .78rem; font-style: italic; }

.meter { display: flex; align-items: center; gap: 10px; }
.meter .track {
    flex: 1 1 auto; height: 7px; min-width: 70px;
    background: var(--admin-border); border-radius: 999px; overflow: hidden;
}
.meter .fill { height: 100%; border-radius: 999px; background: var(--admin-accent); }
.meter .fill.good { background: var(--admin-good); }
.meter .fill.warn { background: var(--admin-warn); }
.meter .fill.bad { background: var(--admin-bad); }
.meter .pct { font-size: .78rem; color: var(--admin-muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }

.empty { color: var(--admin-muted); font-size: .86rem; padding: 26px 18px; text-align: center; }

/* ---- danger zone ----------------------------------------------------- */

.danger {
    border-color: rgba(220, 38, 38, .35);
}
.danger > header { background: rgba(220, 38, 38, .07); }
.danger > header h2 { color: var(--admin-bad); }

.danger input[type="text"] {
    background: var(--admin-surface-2); color: var(--admin-text);
    border: 1px solid var(--admin-border); border-radius: 9px;
    padding: 8px 11px; font-size: .86rem; max-width: 260px;
}

.btn-danger-solid {
    background: var(--admin-bad); color: #fff; border: none;
    border-radius: 9px; padding: 8px 15px; font-size: .86rem; font-weight: 560; cursor: pointer;
}
.btn-danger-solid:hover { filter: brightness(1.08); }

.btn-quiet {
    background: transparent; color: var(--admin-rail-text);
    border: 1px solid rgba(148, 163, 184, .3); border-radius: 8px;
    padding: 6px 12px; font-size: .82rem; cursor: pointer; width: 100%;
}
.btn-quiet:hover { background: var(--admin-rail-active); color: #fff; }

.notice { border-radius: 10px; padding: 11px 15px; font-size: .86rem; margin-bottom: 18px; border: 1px solid; }
.notice.ok { background: rgba(5, 150, 105, .1); border-color: rgba(5, 150, 105, .3); color: var(--admin-good); }
.notice.warn { background: rgba(217, 119, 6, .1); border-color: rgba(217, 119, 6, .3); color: var(--admin-warn); }

/* ---- sign-in --------------------------------------------------------- */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }

.login-card {
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: 18px;
    box-shadow: var(--admin-shadow);
    padding: 32px;
    width: 100%; max-width: 392px;
}

.login-card h1 { font-size: 1.24rem; font-weight: 650; margin: 0 0 4px; letter-spacing: -.02em; }
.login-card .sub { color: var(--admin-muted); font-size: .86rem; margin-bottom: 22px; }
.login-card label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 6px; }
.login-card input {
    width: 100%; background: var(--admin-surface-2); color: var(--admin-text);
    border: 1px solid var(--admin-border); border-radius: 10px;
    padding: 10px 12px; font-size: .92rem; margin-bottom: 15px;
}
.login-card input:focus { outline: 2px solid var(--admin-accent); outline-offset: 1px; border-color: transparent; }
.login-card button {
    width: 100%; background: var(--admin-accent); color: #fff; border: none;
    border-radius: 10px; padding: 11px; font-size: .92rem; font-weight: 580; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.07); }

.login-error {
    background: rgba(220, 38, 38, .1); border: 1px solid rgba(220, 38, 38, .32);
    color: var(--admin-bad); border-radius: 10px; padding: 10px 13px;
    font-size: .84rem; margin-bottom: 17px;
}

.setup-steps {
    background: var(--admin-surface-2); border: 1px solid var(--admin-border);
    border-radius: 10px; padding: 15px; font-size: .82rem; color: var(--admin-muted);
}
.setup-steps code {
    display: block; background: var(--admin-rail); color: #e2e8f0;
    padding: 9px 11px; border-radius: 7px; margin: 9px 0;
    font-size: .78rem; overflow-x: auto; white-space: pre;
}

@media (max-width: 820px) {
    .admin-shell { flex-direction: column; }
    .admin-rail {
        width: auto; flex: none; flex-direction: row; flex-wrap: wrap;
        align-items: center; padding: 12px;
        /* A top bar rather than a column, but still pinned. */
        align-self: stretch; height: auto; overflow: visible;
    }
    .admin-rail .brand { padding: 4px 8px; }
    .admin-rail .rail-foot { margin: 0 0 0 auto; border: none; padding: 0; }
    .admin-main { padding: 18px 16px 44px; }
}

/* ---- forms and controls --------------------------------------------- */

.admin-main label { display:block; font-size:.79rem; font-weight:600; margin-bottom:5px; }

.admin-main input[type="text"],
.admin-main input[type="number"],
.admin-main input[type="password"],
.admin-main select {
    background: var(--admin-surface-2); color: var(--admin-text);
    border: 1px solid var(--admin-border); border-radius: 9px;
    padding: 8px 11px; font-size: .86rem; font-family: inherit; max-width: 100%;
}
.admin-main input:focus, .admin-main select:focus {
    outline: 2px solid var(--admin-accent); outline-offset: 1px; border-color: transparent;
}
.admin-main select[multiple] { padding: 6px; }

.stack { display: flex; flex-direction: column; gap: 4px; }
.stack > label { margin-top: 9px; }
.stack > label:first-child { margin-top: 0; }
.stack > input, .stack > select { width: 100%; }
.stack > button { margin-top: 14px; align-self: flex-start; }

.field-hint { color: var(--admin-muted); font-size: .78rem; margin: 3px 0 0; }

label.check { display:flex; align-items:center; gap:8px; font-weight:500; margin-top:12px; }
label.check input { width:auto; }

.filter-row { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.filter-row input[type="text"] { flex: 1 1 240px; min-width: 190px; }

.field-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(250px,1fr)); gap:14px; }
.field input { width:100%; }

.btn-primary {
    background: var(--admin-accent); color:#fff; border:none; border-radius:9px;
    padding:9px 16px; font-size:.86rem; font-weight:560; cursor:pointer; font-family:inherit;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-quiet-inline {
    background: transparent; color: var(--admin-text);
    border: 1px solid var(--admin-border); border-radius:8px;
    padding:7px 13px; font-size:.82rem; cursor:pointer; font-family:inherit;
}
.btn-quiet-inline:hover { background: var(--admin-surface-2); border-color: var(--admin-accent); }

.link { color: var(--admin-accent); text-decoration:none; font-size:.84rem; }
.link:hover { text-decoration: underline; }
.muted { color: var(--admin-muted); }
