/* ============================================================================
   License Management UI. Same design system as the SNGen Suite
   (SNGen.UI/wwwroot/sngen.css): tokens, top bar, panels, fields, buttons.
   ========================================================================== */

:root {
    /* Micro-Dyn Medical Systems brand: deep teal (#001b1a) + teal accent */
    --bg-1: #eaf1f0;
    --bg-2: #f4f8f7;
    --surface: #ffffff;
    --surface-2: #f3f8f7;
    --surface-3: #e7f0ef;
    --border: #dbe7e5;
    --border-2: #c8d9d6;
    --text: #05201f;
    --text-2: #3c534f;
    --muted: #5d7570;
    --brand-deep: #001b1a;
    --primary: #12817c;
    --primary-2: #0b615d;
    --primary-soft: #e1f2f0;
    --ring: rgba(18, 129, 124, 0.18);
    --warn: #8f5b07;
    --success: #158a5b;
    --danger: #d64343;
    --shadow-sm: 0 1px 2px rgba(16, 32, 64, 0.06);
    --shadow: 0 8px 28px rgba(20, 40, 80, 0.08);
    --shadow-lg: 0 20px 54px rgba(20, 40, 80, 0.14);
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
    --sans: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 18px;
}

/* Dark palette: when the OS prefers dark (unless light is forced), and always with data-theme="dark". */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg-1: #041413; --bg-2: #08201e;
        --surface: #0c211f; --surface-2: #0a1c1a; --surface-3: #12302d;
        --border: #1e3a37; --border-2: #294c48;
        --text: #e6f1ef; --text-2: #a4bcb8; --muted: #7f9a94;
        --primary: #2bb3ac; --primary-2: #46cabf; --primary-soft: #0f322f;
        --ring: rgba(43, 179, 172, 0.32);
        --warn: #e0a44a; --success: #34d399; --danger: #f77070;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
        --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
    }
}
:root[data-theme="dark"] {
    --bg-1: #041413; --bg-2: #08201e;
    --surface: #0c211f; --surface-2: #0a1c1a; --surface-3: #12302d;
    --border: #1e3a37; --border-2: #294c48;
    --text: #e6f1ef; --text-2: #a4bcb8; --muted: #7f9a94;
    --primary: #2bb3ac; --primary-2: #46cabf; --primary-soft: #0f322f;
    --ring: rgba(43, 179, 172, 0.32);
    --warn: #e0a44a; --success: #34d399; --danger: #f77070;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: var(--sans);
    background:
        radial-gradient(1200px 600px at 100% -10%, color-mix(in srgb, var(--primary) 10%, transparent), transparent 60%),
        linear-gradient(180deg, var(--bg-1), var(--bg-2));
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

html { background-color: var(--bg-2); }
h1:focus, h1:focus-visible { outline: none; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.icon { width: 16px; height: 16px; flex: 0 0 auto; }
.mono { font-family: var(--mono); letter-spacing: 0.04em; }

.btn-primary:focus-visible, .btn-sm:focus-visible, .link-btn:focus-visible, .theme-btn:focus-visible,
.family-tab:focus-visible, .chip:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---- Shell: one top bar, the page, one status bar ----------------------- */
.suite { min-height: 100vh; display: flex; flex-direction: column; }
.suite-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    padding: 10px 22px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 13px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border-radius: 11px;
    overflow: hidden;
    background: var(--brand-deep);
    border: 1px solid color-mix(in srgb, var(--primary) 32%, transparent);
    box-shadow: var(--shadow-sm);
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 750; font-size: 1.02rem; letter-spacing: -0.01em; }
.brand-tag { font-size: 0.74rem; color: var(--muted); font-weight: 500; }

.family-bar { flex: 1; display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.family-tab {
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
    font: inherit; font-weight: 640; font-size: 0.86rem; cursor: pointer;
    padding: 7px 18px; border-radius: 999px; transition: all .14s ease;
}
.family-tab:hover { border-color: var(--primary); color: var(--text); text-decoration: none; }
.family-tab.family-on { background: var(--primary); border-color: var(--primary); color: #fff; }

.topbar-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.theme-switch { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 9px; }
.theme-btn {
    display: grid; place-items: center; width: 30px; height: 26px;
    border: 0; background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer;
    transition: color .13s, background .13s, box-shadow .13s;
}
.theme-btn:hover { color: var(--text); }
.theme-on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.theme-btn .icon { width: 15px; height: 15px; }

.login { display: flex; align-items: center; gap: 10px; }

@media (max-width: 980px) {
    .topbar { justify-content: center; }
    .family-bar { order: 3; flex: 1 0 100%; padding-top: 6px; }
}
@media (max-width: 560px) {
    .topbar { padding: 12px 15px; gap: 12px; }
    .brand-tag { display: none; }
}

/* Status pills */
.pill {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 0.75rem; font-weight: 650;
    padding: 5px 11px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
    white-space: nowrap;
}
.pill .icon { width: 13px; height: 13px; }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent); }
.pill-secure { color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); background: var(--primary-soft); }
.pill-muted { color: var(--muted); background: var(--surface-2); }

.statusbar {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
    padding: 12px 26px;
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 60%, transparent);
    color: var(--muted);
    font-size: 0.78rem;
}
.status-left, .status-right { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent); }
.sep { opacity: 0.5; }

/* ---- Workspace ---------------------------------------------------------- */
.workspace {
    flex: 1;
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 26px 26px 34px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
@media (max-width: 560px) { .workspace { padding: 16px 13px; gap: 16px; } }

.status-strip {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
    margin-bottom: -8px; color: var(--muted); font-size: 0.8rem;
}
.status-cluster { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.back { color: var(--muted); font-weight: 600; }
.back:hover { color: var(--primary); text-decoration: none; }

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 20px 22px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surface-2), var(--surface));
}
.panel-title, .panel-head h1 { margin: 0; font-size: 1.02rem; font-weight: 720; letter-spacing: -0.01em; }
.panel-head h1 { font-size: 1.3rem; }
.panel-sub { margin: 3px 0 0; font-size: 0.8rem; color: var(--muted); }
.panel-badge {
    font-size: 0.72rem; font-weight: 700;
    padding: 4px 10px; border-radius: 999px;
    color: var(--primary); background: var(--primary-soft);
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--border));
    white-space: nowrap;
}
.panel-body { padding: 22px; }
.panel-body > :last-child { margin-bottom: 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (max-width: 560px) { .panel-head, .panel-body { padding-left: 16px; padding-right: 16px; } }

/* ---- Fields ------------------------------------------------------------- */
.section-label {
    font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.09em;
    color: var(--muted);
    margin: 0 0 14px; padding-bottom: 9px;
    border-bottom: 1px solid var(--border);
}
* + .section-label { margin-top: 24px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 18px; }
.field { margin-bottom: 18px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.micro-label, .field > label {
    display: block;
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--muted);
    margin-bottom: 8px;
}
.hint { color: var(--muted); font-weight: 500; text-transform: none; letter-spacing: 0; }

.input {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border-2);
    border-radius: var(--r);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 0.92rem;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.input:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border-2)); }
.input:focus { outline: none; background: var(--surface); border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.input[readonly] { background: var(--surface); }
select.input {
    appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d7570' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}
textarea.input { resize: vertical; line-height: 1.55; }
.search { flex: 1; min-width: 220px; }

/* Checkbox chips (states, fiscal years) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border-2); border-radius: 10px;
    background: var(--surface-2); color: var(--text-2);
    font-size: 0.88rem; font-weight: 600; cursor: pointer;
    transition: border-color .13s, background .13s, color .13s;
}
.chip:hover { border-color: var(--primary); }
.chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip input, .check input { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.check { display: inline-flex; align-items: center; gap: 10px; font-size: 0.9rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.field > label.check { text-transform: none; letter-spacing: 0; font-size: 0.9rem; font-weight: 600; color: var(--text-2); margin-bottom: 0; }

/* ---- Buttons ------------------------------------------------------------ */
.btn-primary {
    width: 100%;
    display: inline-flex; align-items: center; justify-content: center; gap: 9px;
    border: 0;
    padding: 13px 18px;
    border-radius: var(--r);
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    font: inherit; font-weight: 700; font-size: 0.96rem;
    cursor: pointer;
    box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 38%, transparent);
    transition: transform .08s, filter .15s, box-shadow .15s;
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 10px 26px color-mix(in srgb, var(--primary) 46%, transparent); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .65; cursor: default; filter: none; }
.btn-primary .icon { width: 17px; height: 17px; }
.btn-row { margin-top: 6px; }

.btn-sm {
    display: inline-flex; align-items: center; gap: 7px;
    border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 650; font-size: 0.84rem; padding: 8px 14px; border-radius: 9px; cursor: pointer;
    transition: border-color .12s, color .12s, filter .12s;
}
.btn-sm:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm:disabled { opacity: .6; cursor: default; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-sm-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-sm-primary:hover { filter: brightness(1.06); color: #fff; }

.link-btn { border: 0; background: none; color: var(--primary); font: inherit; font-size: 0.84rem; font-weight: 650; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.link-btn:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.link-btn.danger { color: var(--danger); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }

/* ---- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th {
    text-align: left; font-size: 0.68rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
    color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table a { font-weight: 650; }
.cell-sub { display: block; font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.key-cell { font-family: var(--mono); font-size: 0.84rem; letter-spacing: .03em; word-break: break-all; }
.row-actions { display: flex; gap: 14px; justify-content: flex-end; white-space: nowrap; }
.kind {
    display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
    background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border);
}
.kind-token { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 25%, var(--border)); }

/* ---- Messages ----------------------------------------------------------- */
.notice { color: var(--muted); font-size: 0.9rem; margin: 0; }
.empty { text-align: center; padding: 22px 12px; color: var(--muted); font-size: 0.9rem; }
.error {
    display: flex; align-items: center; gap: 8px;
    margin: 14px 0 0;
    padding: 10px 12px;
    font-size: 0.85rem; font-weight: 600;
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
    border-radius: var(--r);
}
.note {
    margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; font-size: 0.85rem;
    color: var(--success);
    background: color-mix(in srgb, var(--success) 8%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border));
}

/* Issued result, as in the SNGen order panel */
.issued {
    margin-top: 20px;
    padding: 18px 20px;
    border-radius: 16px;
    border: 1px solid color-mix(in srgb, var(--primary) 26%, var(--border));
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 9%, var(--surface)), var(--surface-2));
}
.issued-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.issued-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; color: var(--text-2); }
.issued-key { font-family: var(--mono); font-size: 0.98rem; letter-spacing: .04em; color: var(--text); background: var(--surface); }
.issued-actions { display: flex; gap: 16px; }

/* Customer and decode results */
.result {
    margin: 18px 0 0; padding: 14px 16px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r);
    font-family: var(--mono); font-size: 0.84rem; color: var(--text); overflow: auto;
}

.boot { padding: 4rem 1rem; text-align: center; color: var(--muted); font-family: var(--sans); }

#blazor-error-ui {
    display: none;
    position: fixed; left: 0; bottom: 0; width: 100%;
    padding: 0.7rem 1.25rem;
    background: #fff3cd; color: #664d03;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.2);
    z-index: 2000;
}
#blazor-error-ui .reload { color: #664d03; font-weight: 700; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.9rem; top: 0.55rem; }

/* ---- Serial order: one editable row per serial (as the SNGen Suite order grid) ---- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.grid-wrap { overflow-x: auto; padding-bottom: 4px; }
.grid-table { min-width: 1080px; }
.grid-table th { padding: 6px 6px; white-space: nowrap; }
.grid-table td { padding: 6px 5px; vertical-align: top; }
.grid-table tbody tr:hover td { background: transparent; }
.grid-table tr.order-row > td:first-child { padding-top: 14px; }
.grid-table .col-n { width: 28px; }
.grid-table .cell-n { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 0.78rem; }
.grid-table .col-product { min-width: 170px; }
.grid-table .col-module { width: 150px; }
.grid-table .col-prefix { width: 100px; }
.grid-table .col-exp { width: 250px; }
.grid-table .col-pos { width: 150px; }
.grid-table .col-pricer { width: 100px; }
.grid-table .col-states { min-width: 150px; }
.grid-table .col-actions { width: 44px; }
.cell-input { padding: 8px 9px; font-size: 0.84rem; border-radius: 8px; }
select.cell-input { padding-right: 26px; background-position: right 7px center; background-size: 14px; cursor: pointer; }
.cell-input.mono { letter-spacing: 0.04em; }
.cell-row { display: flex; gap: 4px; align-items: center; }
.cell-row .inp-exp { flex: 1 1 auto; min-width: 128px; }
.cell-row .exp-preset { flex: 0 0 auto; width: 100px; color: var(--text-2); }
.cell-stack { display: flex; flex-direction: column; gap: 4px; }
.cell-hint { display: block; margin-top: 4px; font-size: 0.7rem; line-height: 1.3; color: var(--muted); }
.cell-hint.warn { color: var(--danger); }
.cell-na { display: block; padding-top: 9px; text-align: center; color: var(--muted); }
.grid-table .row-actions { justify-content: center; padding-top: 2px; }
.grid-table tr.row-problem td { border-bottom-color: transparent; }
.grid-table tr.row-problem-msg td { padding: 0 8px 8px; border-bottom: 1px solid var(--border); }
.grid-table tr.row-problem-msg .cell-problem { font-size: 0.78rem; font-weight: 600; color: var(--danger); }
.grid-table tr.row-problem td, .grid-table tr.row-problem-msg td { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.input-invalid, .input-invalid:hover { border-color: var(--danger); }
.grid-toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; margin: 12px 0 14px; }
.grid-toolbar .cell-row { gap: 12px; flex-wrap: wrap; }
.grid-toolbar .cell-hint { margin-top: 0; }
.btn-add-row { border-color: var(--primary); color: var(--primary); }
.btn-add-row .icon { width: 14px; height: 14px; }
.btn-add-row:hover { background: color-mix(in srgb, var(--primary) 8%, var(--surface)); }
.icon-btn {
    display: grid; place-items: center; width: 32px; height: 32px;
    border: 1px solid var(--border-2); border-radius: 8px;
    background: var(--surface); color: var(--text-2); cursor: pointer; transition: color .12s, border-color .12s;
}
.icon-btn:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn .icon { width: 15px; height: 15px; }
.chips-tight { gap: 4px; }
.chip-sm { padding: 5px 9px; font-size: 0.78rem; border-radius: 8px; gap: 6px; }
.chip-sm input { width: 14px; height: 14px; }
.presets { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.presets .hint { font-size: 0.78rem; }
button.chip { font: inherit; font-size: 0.78rem; }
.toolbar-top { margin: 14px 0 0; }
.issued .table { margin-top: 2px; }
.issued-serial { user-select: all; font-size: 0.9rem; }
.cell-label { display: block; font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 2px 0 2px; }
.cell-label .hint { text-transform: none; letter-spacing: 0; font-size: 0.68rem; }
.grid-table tr.row-token > td { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.inp-max { max-width: 180px; }
