/* =========================================================================
   GOICT AllBotMaster — admin theme (light + dark, responzivní)
   ========================================================================= */
:root {
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --fg: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --input-bg: #ffffff;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --code-bg: #f1f5f9;
    --code-fg: #334155;
    --topbar: #0b1220;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, .08);

    /* sjednocená velikost ovládacích prvků (text, input, select, button) */
    --control-font: .9rem;
    --control-pad-y: .5rem;
    --control-pad-x: .65rem;
}

:root[data-theme="dark"] {
    --bg: #0e1525;
    --surface: #151f33;
    --surface-2: #1c2942;
    --fg: #e6edf6;
    --muted: #94a3b8;
    --border: #2a3852;
    --border-strong: #3b4d6b;
    --input-bg: #0f1828;
    --accent: #3b82f6;
    --accent-dark: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --code-bg: #1c2942;
    --code-fg: #cbd5e1;
    --topbar: #0a101e;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, .4);
}

/* Bez ruční volby se řídíme systémovým nastavením (dokud uživatel nepřepne) */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #0e1525;
        --surface: #151f33;
        --surface-2: #1c2942;
        --fg: #e6edf6;
        --muted: #94a3b8;
        --border: #2a3852;
        --border-strong: #3b4d6b;
        --input-bg: #0f1828;
        --accent: #3b82f6;
        --accent-dark: #2563eb;
        --danger: #ef4444;
        --success: #22c55e;
        --warning: #f59e0b;
        --code-bg: #1c2942;
        --code-fg: #cbd5e1;
        --topbar: #0a101e;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow-md: 0 6px 20px rgba(0, 0, 0, .4);
    }
    /* logo na loginu invertovat i při systémovém tmavém režimu */
    :root:not([data-theme]) .login-logo-img { filter: invert(1); }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--fg);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

/* ---- Topbar ---- */
.topbar {
    display: flex;
    gap: 1rem;
    align-items: center;
    padding: .7rem 1.5rem;
    background: var(--topbar);
    color: #fff;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar .brand { display: inline-flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.topbar .brand-logo { height: 20px; width: auto; filter: invert(1); display: block; }
.topbar .brand-suffix { color: #cbd5e1; font-weight: 600; font-size: .95rem; }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; align-items: center; margin-left: auto; }
.topbar nav a, .topbar nav button.link {
    color: #cbd5e1;
    text-decoration: none;
    background: none;
    border: none;
    box-shadow: none;
    cursor: pointer;
    font: inherit;
    padding: .4rem .7rem;
    border-radius: 999px;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.topbar nav a:hover, .topbar nav button.link:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.topbar .nav-toggle { display: none; }
.nav-burger { display: none; margin-left: auto; background: none; border: none; color: #fff; font-size: 1.6rem; line-height: 1; cursor: pointer; padding: .15rem .55rem; border-radius: 8px; }
.nav-burger:hover { background: rgba(255, 255, 255, .12); }

/* ---- Layout ---- */
.container { max-width: 1200px; margin: 1.75rem auto; padding: 0 1.25rem; }

h1 { margin: 0 0 1.25rem; font-size: 1.55rem; font-weight: 700; letter-spacing: -.01em; }
h2 { margin: 2.25rem 0 1rem; font-size: 1.15rem; font-weight: 700; padding-bottom: .4rem; border-bottom: 1px solid var(--border); }
h3 { margin: 1.5rem 0 .75rem; font-size: 1rem; font-weight: 600; color: var(--muted); }
p { margin: .5rem 0 1rem; }
small { color: var(--muted); }

/* ---- Flash ---- */
.flash { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; border: 1px solid transparent; border-left-width: 4px; box-shadow: var(--shadow-sm); font-size: .9rem; }
.flash-success { background: #f0fdf4; color: #14532d; border-color: #bbf7d0; border-left-color: var(--success); }
.flash-error   { background: #fef2f2; color: #7f1d1d; border-color: #fecaca; border-left-color: var(--danger); }
.flash-info    { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; border-left-color: var(--accent); }

/* ---- Stat karty ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); padding: 1.1rem 1rem; border-radius: var(--radius); text-align: center; box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s; }
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
a.stat { text-decoration: none; color: inherit; cursor: pointer; }
a.stat:hover { border-color: var(--accent); }
.stat[data-modal] { cursor: pointer; }
.stat[data-modal]:hover { border-color: var(--accent); }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md); max-width: 760px; width: 100%; max-height: 85vh; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer; box-shadow: none; padding: 0 .4rem; }
.modal-close:hover { color: var(--fg); background: none; box-shadow: none; }
.modal-body { padding: 1rem 1.1rem; overflow: auto; }
.modal-body table.data { margin-bottom: 0; }
.stat .num { display: block; font-size: 1.85rem; font-weight: 700; line-height: 1.1; margin-bottom: .35rem; color: var(--fg); }
.stat span:not(.num) { color: var(--muted); font-size: .8rem; }

/* ---- Tabulky ---- */
table.data { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); margin-bottom: 1.25rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
table.data th, table.data td { padding: .6rem .8rem; text-align: left; font-size: .9rem; border-bottom: 1px solid var(--border); }
table.data th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tr.row-error { background: rgba(220, 38, 38, .07); }
table.data tr.row-ok { background: rgba(22, 163, 74, .07); }

/* ---- Formuláře — sjednocené (symetrické) ovládací prvky ---- */
input[type=text], input[type=number], input[type=password], input[type=date], input[type=email], select, textarea {
    font-family: inherit;
    font-size: var(--control-font);
    line-height: 1.4;
    padding: var(--control-pad-y) var(--control-pad-x);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--fg);
    vertical-align: middle;
}
select { cursor: pointer; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .18); }
input[type=checkbox] { width: auto; margin-right: .4rem; accent-color: var(--accent); vertical-align: middle; }
label { font-size: .9rem; font-weight: 500; }

form.stacked { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); max-width: 640px; margin-bottom: 1.25rem; }
form.stacked label { display: block; margin-bottom: .8rem; }
form.stacked input[type=text], form.stacked input[type=number], form.stacked input[type=password],
form.stacked input[type=date], form.stacked input[type=email], form.stacked select, form.stacked textarea { width: 100%; margin-top: .3rem; }

form.inline { display: inline-block; margin: 0; }
form.inline label { display: inline-flex; align-items: center; gap: .35rem; }
form.inline input, form.inline select { width: auto; margin: 0 .25rem 0 0; }

/* ---- Buttons / badges (jednotný pilulkový vzhled) ---- */
button, .badge {
    display: inline-block;
    padding: .42rem .9rem;
    font-size: var(--control-font);
    font-weight: 600;
    line-height: 1.4;
    border: none;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    vertical-align: middle;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    transition: background .15s, transform .05s, box-shadow .15s;
}
button:hover, .badge:hover { background: var(--accent-dark); color: #fff; box-shadow: var(--shadow-md); }
button:active, .badge:active { transform: translateY(1px); }
button:focus-visible, .badge:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, .4); }
button.danger,  .badge-danger  { background: var(--danger); }
button.danger:hover,  .badge-danger:hover  { background: #b91c1c; }
button.success, .badge-success { background: var(--success); }
button.success:hover, .badge-success:hover { background: #15803d; }
button.neutral, .badge-neutral { background: #64748b; }
button.neutral:hover, .badge-neutral:hover { background: #475569; }
button.warn-btn, .badge-warning { background: var(--warning); }

table.data td .badge, table.data td button { margin: 2px; }
table.data td form.inline { margin: 0; }

/* ---- Misc ---- */
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: .85rem; color: var(--code-fg); }

.mode { padding: 2px 10px; border-radius: 999px; font-weight: 600; font-size: .85rem; }
.mode-test { background: #fef3c7; color: #92400e; }
.mode-live { background: #dcfce7; color: #14532d; }

/* stavové badge (status členství) — odstíny fungují v light i dark */
.status-badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.status-active    { background: rgba(22, 163, 74, .16);  color: #16a34a; }
.status-past_due  { background: rgba(220, 38, 38, .16);  color: #dc2626; }
.status-cancelled { background: rgba(217, 119, 6, .18);  color: #c2730a; }
.status-expired   { background: rgba(220, 38, 38, .16); color: #dc2626; }

.warn { background: rgba(217, 119, 6, .1); border: 1px solid rgba(217, 119, 6, .35); border-left: 4px solid var(--warning); padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }

/* ---- Login ---- */
.login-card { max-width: 410px; margin: 4rem auto; background: var(--surface); padding: 2.4rem 2.4rem 2rem; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow-md); }
.login-head { text-align: center; margin-bottom: 1.6rem; }
.login-logo-img { display: block; width: 160px; max-width: 62%; height: auto; margin: 0 auto 1.3rem; }
:root[data-theme="dark"] .login-logo-img { filter: invert(1); }
.login-head h1 { margin: 0 0 .3rem; font-size: 1.4rem; }
.login-sub { margin: 0; color: var(--muted); font-size: .88rem; }
.login-form .field { display: block; margin-bottom: 1.1rem; }
.login-form .field-label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .4rem; }
.login-form .field input { width: 100%; }
.login-form button { width: 100%; padding: .72rem; margin-top: .4rem; font-size: .95rem; border-radius: var(--radius-sm); }

/* ---- Filtry / bulk / meta ---- */
.filters { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; align-items: center; background: var(--surface); padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.filters label { display: inline-flex; align-items: center; gap: .45rem; margin: 0; }
fieldset.bulk { margin-top: 1rem; padding: 1rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
fieldset.bulk legend { font-weight: 700; padding: 0 .4rem; }
fieldset.bulk label { display: inline-flex; align-items: center; gap: .4rem; margin-right: 1rem; }

fieldset.stripe-create { margin: .5rem 0 1rem; padding: 1rem 1.25rem; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
fieldset.stripe-create legend { font-weight: 700; padding: 0 .4rem; }
fieldset.stripe-create label { display: block; margin-bottom: .6rem; }
fieldset.stripe-create label.checkline { display: flex; align-items: center; gap: .5rem; }
fieldset.stripe-create label.checkline input { width: auto; flex: 0 0 auto; }

label.archive-opt { display: inline-flex; align-items: center; gap: .25rem; font-size: .8rem; color: var(--muted); margin-right: .4rem; white-space: nowrap; }
label.archive-opt input { width: auto; }

/* Široká tabulka (produkty) — vodorovný scroll, ať se neořízne Live price / Stripe product */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 1.25rem; border-radius: var(--radius); }
.table-scroll table.data { margin-bottom: 0; }
table.data code { font-size: .78rem; }

/* Povinná pole ve formuláři */
.req { color: #dc2626; font-weight: 700; }
.req-stripe { color: #d97706; font-weight: 700; }
.form-legend { font-size: .8rem; color: var(--muted); margin: 0 0 .4rem; }
label.needed .req-stripe { text-decoration: underline; }

dl.meta { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow-sm); margin-bottom: 1.25rem; }
dl.meta dt { font-weight: 600; color: var(--muted); }
dl.meta dd { margin: 0; word-break: break-word; }

/* ---- Editor uvítací zprávy ---- */
.editor { max-width: 640px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 1rem; box-shadow: var(--shadow-sm); overflow: hidden; }
.editor.editor-narrow { max-width: 420px; }
.editor.editor-narrow .editor-area { min-height: 2.4rem; }
.editor-toolbar { display: flex; gap: .25rem; padding: .45rem; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.editor-toolbar .ed-btn { background: var(--input-bg); color: var(--fg); border: 1px solid var(--border-strong); padding: .3rem .55rem; border-radius: var(--radius-sm); min-width: 2rem; line-height: 1.2; box-shadow: none; }
.editor-toolbar .ed-btn:hover { background: var(--surface-2); }
.editor-area { width: 100%; border: none; padding: .7rem; font-size: 1rem; resize: vertical; min-height: 5rem; border-radius: 0; margin: 0; background: var(--surface); color: var(--fg); }
.editor-area:focus { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: none; }
.emoji-palette { display: flex; flex-wrap: wrap; gap: .1rem; padding: .4rem; border-bottom: 1px solid var(--border); background: var(--surface-2); max-height: 9rem; overflow-y: auto; }
.emoji-palette .emoji-item { background: none; border: none; padding: .15rem .3rem; font-size: 1.25rem; cursor: pointer; line-height: 1; box-shadow: none; }
.emoji-palette .emoji-item:hover { background: var(--border); border-radius: 4px; }
.editor-preview-wrap { padding: .55rem .7rem; border-top: 1px solid var(--border); background: var(--surface-2); }
.editor-preview-label { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.editor-preview { min-height: 1.5rem; white-space: pre-wrap; word-break: break-word; }
.editor-preview code, .editor-preview pre { background: var(--border); color: inherit; }

/* =========================================================================
   Responsive — telefony (Samsung S25 ~360px … iPhone 17 Pro Max ~440px)
   ========================================================================= */
@media (max-width: 900px) {
    .topbar { flex-wrap: wrap; }
    .nav-burger { display: block; }
    .topbar nav { display: none; width: 100%; order: 3; flex-direction: column; align-items: stretch; gap: .1rem; margin: .5rem 0 0; }
    .topbar nav a, .topbar nav button.link { width: 100%; text-align: left; padding: .65rem .8rem; }
    .topbar nav form.inline { width: 100%; }
    #nav-toggle:checked ~ nav { display: flex; }
}

@media (max-width: 640px) {
    .container { padding: 0 .9rem; margin: 1rem auto; }
    h1 { font-size: 1.35rem; margin-bottom: 1rem; }
    h2 { font-size: 1.05rem; margin-top: 1.75rem; }

    /* tabulky vodorovně scrollovatelné (zachová všechny sloupce) */
    table.data { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    table.data th, table.data td { padding: .5rem .55rem; font-size: .84rem; }

    /* statistiky 2 ve sloupci */
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
    .stat { padding: .9rem .6rem; }
    .stat .num { font-size: 1.55rem; }

    /* detail jako jeden sloupec */
    dl.meta { grid-template-columns: 1fr; gap: .1rem .5rem; padding: 1rem; }
    dl.meta dt { margin-top: .7rem; }
    dl.meta dt:first-of-type { margin-top: 0; }

    /* filtry na výšku, plná šířka ovládacích prvků */
    .filters { flex-direction: column; align-items: stretch; gap: .7rem; }
    .filters label { width: 100%; justify-content: space-between; }
    .filters select, .filters input[type=text] { flex: 1; min-width: 0; }

    form.stacked { padding: 1rem; }
    .login-card { margin: 1.5rem auto; padding: 1.6rem 1.4rem; }
    fieldset.bulk label { display: flex; width: 100%; margin: 0 0 .6rem; }
    fieldset.bulk label input { flex: 1; }
}
