:root {
    --canvas: #f3f5f4;
    --surface: #ffffff;
    --surface-raised: #fbfcfb;
    --ink: #18211e;
    --soft: #64706c;
    --line: #dfe5e2;
    --line-strong: #cbd4d0;
    --brand: #087f5b;
    --brand-dark: #066348;
    --brand-soft: #e9f7f1;
    --blue: #2563eb;
    --danger: #c2413d;
    --warning: #b45309;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(24, 33, 30, .05), 0 10px 28px rgba(24, 33, 30, .05);
    --tblr-font-sans-serif: "Inter", "Segoe UI", sans-serif;
    --tblr-primary: #087f5b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--canvas); }
body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    color: var(--ink);
    background: var(--canvas);
    font-family: "Inter", "Segoe UI", sans-serif;
    letter-spacing: 0;
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
.app-shell { width: 100%; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 68px;
    padding: 10px max(24px, calc((100vw - 1540px) / 2));
    border: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .96);
    box-shadow: 0 1px 10px rgba(24, 33, 30, .03);
    backdrop-filter: blur(12px);
}
.topbar-brand, .topbar-actions { display: flex; align-items: center; gap: 11px; }
.logout-form { margin: 0; }
.brand-mark {
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    color: #fff;
    background: var(--brand);
    box-shadow: 0 6px 14px rgba(8, 127, 91, .18);
}
.brand-mark svg { width: 20px; height: 20px; }
h1 { margin: 1px 0 0; font-size: 1.18rem; font-weight: 700; line-height: 1.2; }
h2 { margin: 0; font-size: 1.05rem; font-weight: 700; }
h3, h4 { color: var(--ink); }
.eyebrow, .section-kicker {
    color: var(--brand);
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.system-state { display: inline-flex; align-items: center; gap: 8px; color: var(--soft); font-size: .78rem; font-weight: 500; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: #22a06b; box-shadow: 0 0 0 3px #dcfce7; }

.login-shell { display: grid; min-height: 100vh; padding: 24px; place-items: center; }
.login-panel { width: min(400px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-form { display: grid; gap: 15px; }
.login-form label { display: grid; gap: 6px; color: var(--soft); font-size: .76rem; font-weight: 600; }
.login-form input { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 6px; color: var(--ink); background: #fff; }
.login-form input:focus { border-color: var(--brand); outline: 3px solid rgba(8, 127, 91, .14); }
.login-error { padding: 10px 12px; border: 1px solid #fecaca; border-radius: 6px; color: #991b1b; background: #fef2f2; font-size: .78rem; }

.workspace { width: min(1540px, calc(100% - 40px)); margin: 20px auto 48px; }
.summary-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.metric {
    display: grid;
    min-width: 0;
    min-height: 96px;
    padding: 13px 15px;
    overflow: hidden;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(24, 33, 30, .03);
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.metric:hover { border-color: #aebbb5; box-shadow: var(--shadow); transform: translateY(-1px); }
.metric:focus-visible { outline: 3px solid rgba(8, 127, 91, .17); outline-offset: 2px; }
.metric span { color: var(--soft); font-size: .73rem; font-weight: 600; }
.metric strong { align-self: end; min-width: 0; margin: 3px 0; overflow-wrap: anywhere; font-size: 1.42rem; font-weight: 700; }
.metric small { min-width: 0; color: #84908b; font-size: .69rem; overflow-wrap: anywhere; }
.metric-warning { border-color: #f3bc78; background: #fffaf3; }

.workspace-tabs {
    position: sticky;
    top: 68px;
    z-index: 45;
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    padding: 0 8px;
    overflow-x: auto;
    overflow-y: hidden;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    background: rgba(251, 252, 251, .97);
    scrollbar-width: thin;
    backdrop-filter: blur(10px);
}
.workspace-tabs .nav-link {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 7px;
    min-height: 50px;
    padding: 0 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    color: var(--soft);
    background: transparent;
    box-shadow: none;
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
}
.workspace-tabs .nav-link:hover { color: var(--ink); background: #f2f6f4; }
.workspace-tabs .nav-link.active { color: var(--brand-dark); border-bottom-color: var(--brand); background: transparent; }
.workspace-tabs .nav-link:focus-visible { outline: 2px solid var(--brand); outline-offset: -3px; }
.workspace-tabs svg { width: 16px; height: 16px; }

.tab-surface {
    min-height: 480px;
    border: 1px solid var(--line);
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.workspace-panel { min-width: 0; padding: 20px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.section-heading > div:first-child { min-width: 0; }
.toolbar-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.button-grid, .action-toolbar, .section-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.button-grid { margin-bottom: 12px; }

button:not(.metric):not(.nav-link) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    padding: 7px 11px;
    border: 1px solid var(--brand);
    border-radius: 6px;
    color: #fff;
    background: var(--brand);
    box-shadow: 0 1px 1px rgba(24, 33, 30, .05);
    font-size: .76rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
button:not(.metric):not(.nav-link):hover { color: #fff; border-color: var(--brand-dark); background: var(--brand-dark); }
button:not(.metric):not(.nav-link):focus-visible { outline: 3px solid rgba(8, 127, 91, .18); outline-offset: 2px; }
button:disabled { cursor: wait; opacity: .55; }
button svg { width: 15px; height: 15px; flex: 0 0 auto; }
button.secondary { color: var(--ink); border-color: var(--line-strong); background: var(--surface); }
button.secondary:hover { color: var(--brand-dark); border-color: #9eb1a8; background: var(--brand-soft); }
button.icon-button { width: 36px; padding: 0; color: var(--ink); border-color: var(--line-strong); background: var(--surface); }
button.icon-button:hover { color: var(--brand-dark); background: var(--brand-soft); }

.segmented-control { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #f1f4f2; }
.segmented-control button:not(.metric):not(.nav-link) { min-height: 30px; padding: 4px 11px; border: 0; color: var(--soft); background: transparent; box-shadow: none; }
.segmented-control button.active { color: var(--ink); background: #fff; box-shadow: 0 1px 3px rgba(24, 33, 30, .12); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); gap: 12px; }
.filter-form { display: flex; align-items: end; flex-wrap: wrap; gap: 8px; margin: 0; }
.compact-filter label { min-width: 180px; }
label { display: block; color: var(--soft); font-size: .72rem; font-weight: 600; }
input, select, textarea {
    width: 100%;
    min-height: 38px;
    margin-top: 5px;
    padding: 7px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    outline: none;
    color: var(--ink);
    background: var(--surface);
    font-size: .8rem;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(8, 127, 91, .11); }
.field-help { display: block; margin-top: 5px; color: var(--soft); font-weight: 400; }
.mapping-field { width: min(640px, 100%); margin: 4px 0 10px; }
.sync-rule-form { align-items: end; margin-bottom: 14px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.toggle-field { display: flex; min-height: 38px; align-items: center; justify-content: space-between; gap: 12px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.toggle-field input { width: 18px; min-height: 18px; margin: 0; }
.switch-control { position: relative; display: inline-flex; width: 34px; height: 20px; }
.switch-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch-control span { width: 34px; height: 20px; border-radius: 10px; background: #b8c1bd; transition: background .15s ease; }
.switch-control span::after { display: block; width: 14px; height: 14px; margin: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(24, 33, 30, .25); content: ''; transition: transform .15s ease; }
.switch-control input:checked + span { background: var(--brand); }
.switch-control input:checked + span::after { transform: translateX(14px); }
.switch-control input:focus-visible + span { outline: 3px solid rgba(8, 127, 91, .18); outline-offset: 2px; }
.row-actions { display: flex; gap: 6px; }
button.danger-button { color: var(--danger); border-color: #fecaca; }
button.danger-button:hover { color: #fff; border-color: var(--danger); background: var(--danger); }

.inline-disclosure { min-width: 0; margin: 0; }
.inline-disclosure > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    padding: 7px 11px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    color: var(--ink);
    background: var(--surface);
    font-size: .76rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
}
.inline-disclosure > summary::-webkit-details-marker { display: none; }
.inline-disclosure > summary:hover { color: var(--brand-dark); border-color: #9eb1a8; background: var(--brand-soft); }
.inline-disclosure > summary svg { width: 15px; height: 15px; }
.inline-disclosure[open] > summary { color: var(--brand-dark); border-color: var(--brand); background: var(--brand-soft); }
.disclosure-body { width: 100%; margin-top: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-raised); }
.inline-disclosure.full-width { width: 100%; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

.status-line, #accounts-status, #games-status, #live-offers-status, #cached-offers-status, #eldaroto-gg-status {
    min-height: 20px;
    margin: 7px 0 10px;
    color: var(--soft);
    font-size: .75rem;
}
.table-scroll, #games-list, #offers-list, #cached-offers-list, #offer-accounts-list, #ggchest-import-preview { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 9px; border-bottom: 1px solid #e8ecea; text-align: left; vertical-align: top; font-size: .78rem; }
th { color: var(--soft); background: #f7f9f8; font-size: .67rem; font-weight: 700; text-transform: uppercase; white-space: nowrap; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f6faf8; }
tbody tr:last-child td { border-bottom: 0; }
a { color: var(--blue); font-weight: 600; text-decoration: none; }
a:hover { text-decoration: underline; }
.offer-title { min-width: 210px; max-width: 360px; }
.mono-cell { max-width: 300px; overflow-wrap: anywhere; font-family: "IBM Plex Mono", monospace; font-size: .7rem; }
.secret-cell { max-width: 280px; }
.muted { color: var(--soft); font-size: .69rem; }
.game-icon { display: block; width: 34px; height: 34px; border-radius: 6px; object-fit: cover; }
.platform-badge, .status-badge { display: inline-flex; padding: 3px 7px; border-radius: 999px; font-size: .66rem; font-weight: 700; text-transform: capitalize; white-space: nowrap; }
.platform-badge { color: #155e75; background: #e7f8fb; }
.status-active { color: #166534; background: #dcfce7; }
.status-unsold { color: #374151; background: #e5e7eb; }
.status-sold { color: #991b1b; background: #fee2e2; }
.status-paused { color: #92400e; background: #fef3c7; }

.audit-ok, .audit-warning { display: flex; align-items: center; gap: 10px; margin: 10px 0; padding: 9px 11px; border-radius: 6px; font-size: .76rem; }
.audit-ok { color: #166534; border: 1px solid #bbf7d0; background: #f0fdf4; }
.audit-warning { color: #9a3412; border: 1px solid #fed7aa; background: #fff7ed; }
.audit-warning span { color: #7c2d12; }

.modal-backdrop { position: fixed; inset: 0; z-index: 1000; display: flex; justify-content: center; padding: 28px 14px; overflow: auto; background: rgba(17, 25, 22, .62); backdrop-filter: blur(3px); }
.modal-panel { width: min(1040px, 100%); max-height: calc(100vh - 56px); padding: 18px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 24px 70px rgba(17, 25, 22, .25); }
.modal-header { position: sticky; top: -18px; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 0 0 12px; background: var(--surface); }
button.modal-close { width: 34px; min-height: 34px; padding: 0; color: var(--ink); border-color: var(--line); background: #fff; }
body.modal-open { overflow: hidden; }
.details-section { padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--line); }
.details-section h3 { margin: 0 0 8px; font-size: .88rem; }
.details-grid { display: grid; grid-template-columns: minmax(150px, 220px) 1fr; gap: 6px 14px; margin: 0; }
.details-grid dt { color: var(--soft); font-size: .74rem; font-weight: 700; }
.details-grid dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-size: .78rem; }
.json-preview { max-height: 300px; margin: 0; padding: 10px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #f7f9f8; font-family: "IBM Plex Mono", monospace; font-size: .7rem; white-space: pre-wrap; }

.dt-container { color: var(--soft); font-size: .75rem; }
.dt-container .dt-layout-row { margin: 0 0 10px; }
.dt-container .dt-layout-row:last-child { margin: 10px 0 0; }
.dt-container .dt-search input, .dt-container .dt-length select, .dt-container .dt-input {
    width: auto;
    min-height: 34px;
    margin: 0 0 0 6px;
    padding: 5px 8px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: #fff;
}
.dt-container .dt-search input { width: min(240px, 52vw); }
.dt-container .dt-paging .dt-paging-button { min-width: 32px; min-height: 30px; padding: 4px 8px !important; border: 1px solid transparent !important; border-radius: 5px !important; color: var(--ink) !important; background: transparent !important; box-shadow: none !important; }
.dt-container .dt-paging .dt-paging-button.current { border-color: var(--line-strong) !important; background: #f2f6f4 !important; }

@media (max-width: 980px) {
    .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .workspace { width: min(100% - 24px, 1540px); margin-top: 12px; }
}

@media (max-width: 680px) {
    .topbar { min-height: 62px; padding-inline: 12px; }
    .brand-mark { width: 34px; height: 34px; }
    .system-state { display: none; }
    .workspace { width: calc(100% - 16px); }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .metric { min-height: 84px; padding: 10px 11px; }
    .metric strong { font-size: 1.18rem; }
    .workspace-tabs { top: 62px; padding-inline: 3px; }
    .workspace-tabs .nav-link { min-height: 46px; padding-inline: 11px; }
    .workspace-panel { padding: 13px 11px; }
    .section-heading, .toolbar-row { align-items: stretch; flex-direction: column; }
    .section-heading .segmented-control { align-self: flex-start; }
    .action-toolbar button { flex: 1 1 calc(50% - 8px); }
    .inline-disclosure, .inline-disclosure > summary { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .details-grid { grid-template-columns: 1fr; }
    .details-grid dd { margin-bottom: 5px; }
    .audit-warning { align-items: flex-start; flex-direction: column; }
    .dt-container .dt-layout-row { align-items: stretch; flex-direction: column; gap: 8px; }
    .dt-container .dt-search input { width: calc(100% - 6px); }
}

@media (max-width: 420px) {
    .topbar .eyebrow { display: none; }
    .summary-grid { grid-template-columns: 1fr 1fr; }
    .workspace-tabs .nav-link span { display: none; }
    .workspace-tabs .nav-link { flex: 1 0 44px; justify-content: center; padding-inline: 12px; }
    .action-toolbar button { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
