/* shared.bmac.com admin panel. Hand-written CSS, no framework.
   Visual language follows the AppStack admin template (dark sidebar, white
   top bar, shadowed borderless cards, Poppins, soft badges) — written from
   scratch, no Bootstrap. Design tokens up top — change the look here, not
   inline. */

@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/poppins-latin-400-normal.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/poppins-latin-500-normal.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/poppins-latin-600-normal.woff2") format("woff2");
}

:root {
    --bg: #f7f9fc;
    --panel: #ffffff;
    --panel-alt: #f4f7f9;
    --border: #dee6ed;
    --text: #495057;
    --text-muted: #6c757d;

    --sidebar-width: 260px;
    --sidebar-bg: #293042;
    --sidebar-text: rgba(226, 232, 238, .5);
    --sidebar-text-hover: rgba(226, 232, 238, .75);
    --sidebar-active: #e2e8ee;
    --sidebar-header: #ced4da;

    --accent: #3f80ea;
    --accent-hover: #366dc7;
    --accent-text: #2f6bd0;      /* accent darkened to pass AA as small text */
    --accent-soft: #e0eafc;

    /* Status colours are AppStack's hues, darkened so they stay legible as
       small text on their own tint. *-solid is the original fill colour. */
    --success: #2a8449;
    --success-solid: #4bbf73;
    --success-bg: rgba(75, 191, 115, .175);
    --warning: #a3690f;
    --warning-solid: #e5a54b;
    --warning-bg: rgba(229, 165, 75, .22);
    --danger: #c9302c;
    --danger-solid: #d9534f;
    --danger-bg: rgba(217, 83, 79, .175);
    --info-bg: rgba(63, 128, 234, .175);
    --neutral-bg: rgba(73, 80, 87, .12);

    --radius: .25rem;
    --radius-sm: .2rem;
    --gutter: 24px;
    --shadow-card: 0 0 .875rem 0 rgba(41, 48, 66, .05);
    --shadow-nav: 0 0 2rem 0 rgba(41, 48, 66, .1);
    --shadow-pop: 0 .5rem 1rem rgba(0, 0, 0, .15);
    --font: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
strong, b { font-weight: 600; }
.icon { width: 18px; height: 18px; flex-shrink: 0; vertical-align: middle; }

/* ── Shell ─────────────────────────────────────────────── */
.wrapper { display: flex; align-items: stretch; width: 100%; min-height: 100vh; }

.sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transition: margin-left .35s ease-in-out;
}
html.sidebar-toggled .sidebar { margin-left: calc(var(--sidebar-width) * -1); }

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: 1.15rem 1.5rem;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 500;
}
.sidebar-brand:hover { text-decoration: none; }
.sidebar-brand .icon { width: 24px; height: 24px; color: #4a88eb; }
.sidebar-brand span span { color: var(--sidebar-text-hover); font-weight: 400; }

.sidebar-nav { list-style: none; margin: 0; padding: 0 0 1.5rem; }
.sidebar-header {
    padding: 1.5rem 1.5rem .375rem;
    color: var(--sidebar-header);
    font-size: .75rem;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .625rem 1.625rem;
    color: var(--sidebar-text);
    transition: color 75ms ease-in-out;
}
.sidebar-link:hover { color: var(--sidebar-text-hover); text-decoration: none; }
.sidebar-link.active { color: var(--sidebar-active); }
.sidebar-backdrop { display: none; }

.main {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 100vh;
}

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 68px;
    padding: .875rem 1.25rem;
    background: var(--panel);
    box-shadow: var(--shadow-nav);
    position: relative;
    z-index: 20;
}
.sidebar-toggle {
    display: flex;
    align-items: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}
.hamburger, .hamburger::before, .hamburger::after {
    display: block;
    width: 24px;
    height: 3px;
    border-radius: 1px;
    background: var(--text-muted);
    content: "";
    transition: background .1s ease-in-out;
}
.hamburger { position: relative; }
.hamburger::before { position: absolute; top: -8px; width: 20px; }
.hamburger::after { position: absolute; bottom: -8px; width: 16px; }
.sidebar-toggle:hover .hamburger,
.sidebar-toggle:hover .hamburger::before,
.sidebar-toggle:hover .hamburger::after { background: var(--accent); }

.nav-user {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
.nav-user .icon { width: 14px; height: 14px; color: var(--text-muted); }
.nav-user-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
    letter-spacing: .5px;
}

.content { flex: 1; padding: 2.5rem 2.5rem 1.5rem; }

.footer {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .25rem 1.5rem;
    padding: 1rem 2.5rem;
    background: var(--panel);
    color: var(--text-muted);
    font-size: 12.5px;
}

/* ── Dropdown ──────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + .75rem);
    right: 0;
    z-index: 30;
    min-width: 13rem;
    padding: .5rem 0;
    background: var(--panel);
    border: 1px solid rgba(0, 0, 0, .1);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-pop);
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-header {
    padding: .35rem 1.5rem;
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dropdown-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    padding: .4rem 1.5rem;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .1s ease-in-out;
}
.dropdown-item:hover, .dropdown-item:focus-visible { background: var(--panel-alt); text-decoration: none; }
.dropdown-item .icon { width: 16px; height: 16px; color: var(--text-muted); }
.dropdown-divider { height: 0; margin: .5rem 0; border-top: 1px solid var(--border); }

/* ── Typography & layout helpers ───────────────────────── */
h1, h2, h3 { color: var(--text); font-weight: 500; line-height: 1.2; }
h1 { font-size: 1.2375rem; margin: 0 0 1.25rem; }
h2 { font-size: 1.03rem; margin: 0 0 .75rem; }
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    margin-bottom: 1.25rem;
}
.page-head h1 { margin: 0; }
.page-lead { margin: -.5rem 0 1.25rem; color: var(--text-muted); }
.back-link { display: inline-block; margin-bottom: .75rem; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.note-danger { color: var(--danger); font-size: 12px; margin-top: 2px; }

/* Cards carry their own bottom margin, so grids only need a column gap. */
.grid { display: grid; column-gap: var(--gutter); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
/* Wide table + side form. Stacked until the table has room for its action
   column without a horizontal scroll; side by side only on very wide screens. */
.grid-main-side { grid-template-columns: minmax(0, 1fr); }
.grid-start { align-items: start; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-bottom: var(--gutter);
    background: var(--panel);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .25rem 1rem;
    padding: 1rem 1.25rem;
}
.card-header + .card-body { padding-top: 0; }
.card-title { margin: 0; font-size: .95rem; font-weight: 500; }
.card-actions { color: var(--text-muted); font-size: 12.5px; }
.card-body { flex: 1 1 auto; padding: 1.25rem; }
.card-body > :last-child { margin-bottom: 0; }
.card-body.split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-notice { background: var(--warning-bg); box-shadow: inset 3px 0 0 var(--warning-solid), var(--shadow-card); }

/* Welcome tile — AppStack's "illustration" card. */
.card-welcome { background: var(--accent-soft); color: var(--accent-text); overflow: hidden; }
.card-welcome .card-body { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.card-welcome h2 { margin: 0 0 .35rem; color: var(--accent-text); font-size: 1.03rem; }
.card-welcome p { margin: 0; }
.card-welcome .icon { width: 72px; height: 72px; stroke-width: 1.25; opacity: .45; margin-right: -.25rem; }

/* Stat tiles: value, label, sub-line on the left; round icon on the right. */
.stat-card .card-body { display: flex; align-items: flex-start; gap: .75rem; padding: 1.5rem 1.25rem; }
.stat-text { flex: 1; min-width: 0; }
.stat-value { margin: 0 0 .35rem; font-size: 1.35rem; font-weight: 500; line-height: 1.2; }
.stat-label { margin-bottom: .35rem; }
.stat-sub { color: var(--text-muted); font-size: 12.5px; }
.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
}
.stat-icon .icon { width: 24px; height: 24px; }
.stat-icon-success { background: var(--success-bg); color: var(--success); }
.stat-icon-warning { background: var(--warning-bg); color: var(--warning); }
.stat-icon-danger { background: var(--danger-bg); color: var(--danger); }

/* A row of plain metrics inside one card. */
.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1rem 1.5rem; }
.metric-value { font-size: 1.2rem; font-weight: 500; line-height: 1.2; }
.metric-label { color: var(--text-muted); font-size: 12.5px; }

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 500; vertical-align: bottom; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--panel-alt); }
/* Line the outer columns up with the card header. */
.card > .table-wrap th:first-child, .card > .table-wrap td:first-child { padding-left: 1.25rem; }
.card > .table-wrap th:last-child, .card > .table-wrap td:last-child { padding-right: 1.25rem; }
.card > .table-wrap:last-child { border-radius: 0 0 var(--radius) var(--radius); }

/* ── Badges (sync status etc.) ─────────────────────────── */
.badge {
    display: inline-block;
    padding: .3em .55em;
    border-radius: var(--radius-sm);
    font-size: 80%;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    vertical-align: baseline;
}
.badge-success { color: var(--success); background: var(--success-bg); }
.badge-warning { color: var(--warning); background: var(--warning-bg); }
.badge-error { color: var(--danger); background: var(--danger-bg); }
.badge-running { color: var(--accent-text); background: var(--info-bg); }
.badge-queued, .badge-pending { color: var(--text); background: var(--neutral-bg); }

/* ── Buttons & forms ───────────────────────────────────── */
.btn {
    display: inline-block;
    padding: .4rem .85rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.625;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 .2rem rgba(63, 128, 234, .4); }
.btn-secondary { background: var(--panel); color: var(--text); border-color: var(--border); box-shadow: 0 1px 2px rgba(0, 0, 0, .05); }
.btn-secondary:hover { background: var(--panel-alt); border-color: var(--border); }
.btn-danger { background: var(--danger-solid); border-color: var(--danger-solid); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); }
.btn-sm { padding: .15rem .6rem; font-size: 12px; }
.btn-lg { padding: .5rem 1.25rem; font-size: 14px; }
.btn-block { display: block; width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

label { display: block; margin-bottom: .35rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
    width: 100%;
    padding: .4rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.625;
    min-height: 36px;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
input::placeholder { color: #adb5bd; }
input:focus, select:focus, textarea:focus {
    outline: 0;
    border-color: #9fc0f5;
    box-shadow: 0 0 0 .2rem rgba(63, 128, 234, .25);
}
.input-lg { padding: .55rem 1rem; }
.field { margin-bottom: 1rem; }
.hint { margin-top: .25rem; color: var(--text-muted); font-size: 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.form-row .field { flex: 1 1 160px; margin-bottom: 0; }
.form-row .field-actions { flex: 0 0 auto; align-self: flex-end; display: flex; gap: .5rem; }
.form-row + .hint { margin-top: -.6rem; }
.inline-form { display: inline; }
.inline-form-row { display: flex; gap: 6px; margin-top: 6px; }
.inline-form-row input { width: 200px; }
.reset-password { display: inline-block; margin-left: 6px; font-size: 12.5px; vertical-align: middle; }
.test-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
summary { cursor: pointer; }

/* ── Flash messages ────────────────────────────────────── */
.flash { margin-bottom: var(--gutter); padding: .85rem 1.1rem; border-radius: var(--radius); font-weight: 500; }
.flash-success { color: var(--success); background: var(--success-bg); box-shadow: inset 3px 0 0 var(--success-solid); }
.flash-error { color: var(--danger); background: var(--danger-bg); box-shadow: inset 3px 0 0 var(--danger-solid); }

/* ── Progress bars ─────────────────────────────────────── */
.progress { height: .5rem; background: #e2e8ee; border-radius: var(--radius-sm); overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width .4s ease; }
.progress-bar-success { background: var(--success-solid); }
.meter { display: flex; align-items: center; gap: 10px; }
.col-meter { min-width: 140px; }
.meter .progress { flex: 1; }

/* ── Login page ────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}
.login-head { margin-bottom: 1.5rem; text-align: center; }
.login-head .icon { width: 40px; height: 40px; color: var(--accent); margin-bottom: .75rem; }
.login-head h1 { font-size: 1.44rem; margin: 0 0 .35rem; }
.login-head p { margin: 0; color: var(--text-muted); font-size: 1.03rem; font-weight: 400; }
.login-card { width: min(440px, 100%); margin-bottom: 0; }
.login-card .card-body { padding: 2rem; }
.login-foot { margin-top: 1.25rem; color: var(--text-muted); font-size: 12.5px; }

/* ── Modal (shared helper — never use browser confirm()) ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal {
    width: min(460px, calc(100vw - 32px));
    background: var(--panel);
    border-radius: .3rem;
    padding: 1.25rem;
    box-shadow: var(--shadow-pop);
}
.modal h3 { margin: 0 0 .5rem; font-size: 1.03rem; }
.modal p { margin: 0 0 1.25rem; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ── Misc ──────────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: .6rem 1rem; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; min-width: 0; }
.kv-wide { grid-template-columns: 220px 1fr; }
.run-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; padding: 5px 0; }
.secret-box {
    padding: .5rem .7rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    overflow-wrap: anywhere;
}
pre.log {
    margin: 0;
    background: #1e2430;
    color: #d7dde6;
    border-radius: var(--radius);
    padding: 14px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.5;
}
pre.log-wrap { margin-top: 6px; white-space: pre-wrap; }
.pagination { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: var(--gutter); }
.pagination a, .pagination span {
    padding: .25rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--panel);
}
.pagination a:hover { background: var(--panel-alt); text-decoration: none; }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination .plain { border: 0; background: none; }

/* ── Responsive ────────────────────────────────────────── */
@media (min-width: 1700px) {
    .grid-main-side { grid-template-columns: minmax(0, 3fr) minmax(300px, 1fr); }
}

/* Below 992px the sidebar is off-canvas and the toggle means "open". */
@media (max-width: 991.98px) {
    .sidebar { position: fixed; left: 0; z-index: 40; margin-left: calc(var(--sidebar-width) * -1); }
    html.sidebar-toggled .sidebar { margin-left: 0; }
    html.sidebar-toggled .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 35;
        background: rgba(0, 0, 0, .4);
    }
    .content { padding: 1.5rem 1rem 1rem; }
    .footer { padding: 1rem; }
}

@media (max-width: 575.98px) {
    .nav-user-name { display: none; }
    .kv, .kv-wide { grid-template-columns: 1fr; gap: 0; }
    .kv dd { margin-bottom: .6rem; }
    .card-body.split { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .progress-bar { transition: none; }
}
