:root {
    /* Dark theme everywhere (phones included): neutral greys, blue accent, high-contrast text. */
    --bg: #0d1117;
    --sidebar: #010409;
    --surface: #161b22;
    --surface-2: #1f2630;
    --hover: #262f3b;
    --text: #e6edf3;
    --muted: #9da7b3;
    --border: #30363d;
    --accent: #58a6ff;
    --accent-soft: #15284a;
    --primary: #2f6fdb;
    --primary-hover: #3b7ff0;
    --ok: #56d364;
    --ok-soft: #12321d;
    --danger: #ff7b72;
    --danger-soft: #3d1517;
    --warn: #e3b341;
    --warn-soft: #3a2c0b;
    --focus: #58a6ff;
    --radius: 10px;
    --shadow: none;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}

[hidden] { display: none !important; }

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

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 18px; margin-bottom: 14px; }

.muted { color: var(--muted); }
.grow { flex: 1; }
.align-right { text-align: right; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Buttons and fields ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 36px; padding: 6px 14px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text);
    font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: currentColor; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.btn-icon { width: 38px; padding: 0; font-size: 18px; }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn-block { width: 100%; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-sm { margin-bottom: 0; }

input, select, textarea {
    width: 100%; min-height: 38px; padding: 7px 10px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font: inherit;
}
input::placeholder, textarea::placeholder { color: #6e7681; }
textarea { resize: vertical; }
input:disabled { opacity: .6; }
input[type="checkbox"] { width: 18px; min-height: 18px; height: 18px; accent-color: var(--accent); }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.field-inline { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.field-inline input[type="date"] { width: auto; }

.form-error {
    margin: 0 0 12px; padding: 8px 10px; border-radius: 8px;
    background: var(--danger-soft); color: var(--danger); font-size: 14px;
}

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login-card { width: 100%; max-width: 380px; padding: 28px 24px; }
.brand-login { margin-bottom: 22px; color: var(--text); }
.brand-login .brand-sub { color: var(--muted); }

/* ---------- Shell ---------- */

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

.sidebar {
    width: 250px; flex-shrink: 0;
    background: var(--sidebar); color: var(--text); border-right: 1px solid var(--border);
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 18px 12px;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 16px; }
.brand-mark {
    display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
    background: var(--primary); color: #fff; font-weight: 700; letter-spacing: .5px; flex-shrink: 0;
}
.brand-title { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 8px;
    color: inherit; text-decoration: none; font-size: 14px;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav a, .nav button { font: inherit; }
.nav button {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 10px; border: 0; border-radius: 8px;
    background: none; color: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.nav button:hover { background: var(--surface-2); }
.nav-account { display: none; margin-top: 12px; padding-top: 4px; border-top: 1px solid var(--border); }
.nav-icon { width: 22px; text-align: center; }
.nav-group { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 5;
}
.topbar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 4px; }
.menu-toggle { display: none; }

.content { padding: 24px; max-width: 1280px; width: 100%; }

.sidebar-backdrop { display: none; }

/* ---------- Home tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.tile {
    aspect-ratio: 1 / 1; max-height: 220px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    padding: 16px; border-radius: 16px; text-align: center; text-decoration: none;
    background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: 16px;
    transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--surface-2); }
.tile-alt { background: var(--accent-soft); border-color: #1f3a66; }
.tile-alt:hover { background: #1a3260; }
.tile-icon { font-size: 40px; line-height: 1; }

/* ---------- Shop form ---------- */

.form-card { padding: 20px; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.info-banner { margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text); }
.info-banner.warn { background: var(--warn-soft); color: var(--warn); }

.picture-box {
    display: grid; place-items: center; height: 220px; overflow: hidden;
    border: 1px dashed var(--border); border-radius: var(--radius);
    background: var(--surface-2); color: var(--muted); text-align: center; cursor: pointer;
}
.picture-box:hover { border-color: var(--accent); }
.picture-box img { width: 100%; height: 100%; object-fit: contain; }
/* "Generate AI picture" ticked: choosing a picture is switched off. */
.picture-box.is-disabled { cursor: not-allowed; opacity: .5; pointer-events: none; }
.ai-picture-check { margin-top: 8px; }
.picture-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.picture-actions .btn { cursor: pointer; }
.picture-actions.is-disabled { opacity: .5; pointer-events: none; }
/* "Take photo" only where there is a touch screen (phones, tablets); desktop browsers ignore "capture". */
@media (hover: hover) and (pointer: fine) { .picture-actions .camera-only { display: none; } }

.location-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: grid; gap: 10px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.location-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

/* ---------- Toolbars, grids, pager ---------- */

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar.wrap { flex-wrap: wrap; align-items: flex-end; }
.toolbar p { margin: 0; }
#lookupForm input { max-width: 420px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th, .grid td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.grid thead th { background: var(--surface-2); font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
/* Column name that turns into a filter box when clicked. */
.grid .col-filter { min-width: 190px; }
.grid .col-city { min-width: 140px; }
.filter-label {
    display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; max-width: 100%;
    margin: -4px -6px; padding: 4px 6px; border: 0; border-radius: 6px;
    background: none; color: inherit; font: inherit; font-weight: 600; text-align: left; cursor: pointer;
}
.filter-label:hover { background: var(--hover); color: var(--text); }
.filter-icon { font-size: 11px; opacity: .6; }
.filter-label.active { color: var(--accent); }
.filter-label.active .filter-icon { opacity: 1; }
.filter-value {
    flex-basis: 100%; overflow: hidden; text-overflow: ellipsis;
    font-weight: 500; font-size: 12px; color: var(--accent);
}
.filter-value::before { content: "= "; color: var(--muted); }
.grid .filter-input { min-height: 30px; margin: -5px 0; padding: 3px 8px; font-size: 13px; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr.clickable { cursor: pointer; }
.grid tbody tr.clickable:hover { background: var(--hover); }
.grid .col-action { width: 1%; white-space: nowrap; }
/* All Shops: who added each shop, for Admin and Marketing Admin users only (admin.js sets show-added-by). */
.grid .col-added-by { white-space: nowrap; }
.grid:not(.show-added-by) .col-added-by { display: none; }
/* All Shops, Added per day: each date opens (accordion) to the shops added that day. */
.grid .per-day-head .chevron { display: inline-block; width: 1em; transition: transform .15s ease; color: var(--muted, #888); }
.grid .per-day-head.open .chevron { transform: rotate(90deg); }
.grid .per-day-head.open td { background: var(--accent-soft); }
.grid .per-day-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid .per-day-panel-cell { padding: 0 0 8px 28px; background: var(--hover); }
.grid .per-day-panel-cell > p { margin: 8px 0; }
.grid.per-day-shops { margin: 0; background: transparent; }
.grid.per-day-shops th { font-size: 12px; }
.grid .col-date { white-space: nowrap; width: 1%; }
.grid .col-response { min-width: 260px; }
/* Searched keyword and Response share one fixed width; long text wraps onto more lines instead of widening the grid. */
.grid .col-text { width: 300px; min-width: 300px; max-width: 300px; }
.grid .cell-text { display: block; max-width: 300px; white-space: normal; overflow-wrap: anywhere; }
.grid .col-text .clamp { max-width: 300px; overflow-wrap: anywhere; }
.grid .col-check { width: 1%; padding-right: 0; }
.grid .col-check input { display: block; width: 20px; height: 20px; margin: 0; cursor: pointer; }
.grid tbody tr.selected td { background: var(--accent-soft); }
.btn-danger:not(:disabled):hover { background: var(--danger-soft); }
.grid td.nowrap { white-space: nowrap; }
.grid td.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.grid .actions { display: flex; gap: 6px; }
.grid .sub { display: block; font-size: 12px; color: var(--muted); }
.grid tr.detail td { background: var(--surface-2); }
.detail-list { margin: 6px 0 0; padding-left: 18px; }
.detail-list li { margin-bottom: 4px; white-space: pre-wrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 420px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

.section-title { margin: 24px 0 10px; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 5px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 14px; }
.chip-new { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.badge-off { background: var(--warn-soft); color: var(--warn); }
.badge-blocked { background: var(--danger-soft); color: var(--danger); }
.grid tbody tr.blocked td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pager select { width: auto; min-height: 32px; margin-left: 6px; }

/* ---------- Dialogs, toast ---------- */

dialog {
    width: min(440px, calc(100vw - 32px)); padding: 0;
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .65); }
.dialog-body { padding: 22px; }
.phone-list { display: grid; gap: 6px; }
.phone-row { display: flex; gap: 6px; }
.phone-row input { flex: 1; min-width: 0; }
.add-phone { justify-self: start; margin-top: 6px; }
.duplicate-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; }
.duplicate-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
}
.duplicate-list .muted { display: block; font-size: .85em; }

/* Shop history, deleted shops, changes waiting for approval */
dialog.dialog-wide { width: min(720px, calc(100vw - 32px)); }
.history-list { list-style: none; margin: 12px 0; padding: 0; display: grid; gap: 8px; max-height: 60vh; overflow-y: auto; }
.history-list > li { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.change-list { margin: 6px 0 0; padding-left: 18px; font-size: 14px; overflow-wrap: anywhere; }
.change-old { color: var(--danger); text-decoration: line-through; }
.change-new { color: var(--ok); }
.approvals-list { max-height: none; }
.approvals-list .history-head .badge { margin-left: 8px; }
.approval-actions { display: flex; gap: 6px; }
.welcome-option { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 14px; cursor: pointer; }
.welcome-option:has(input:disabled) { color: var(--muted, inherit); cursor: default; }
.approval-picture { display: block; margin-top: 8px; max-width: 220px; max-height: 140px; border-radius: 6px; border: 1px solid var(--border); }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
    max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 8px;
    background: var(--surface-2); color: var(--text); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
.toast.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ---------- Small screens ---------- */

@media (max-width: 900px) {
    .form-grid { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 760px) {
    /* Larger text on phones; 16px fields also stop iOS zooming in on focus. */
    body { font-size: 16px; }
    input, select, textarea { font-size: 16px; }
    .grid { font-size: 15px; }
    .grid .filter-input { font-size: 16px; }
    .grid .sub, .badge { font-size: 13px; }
    .menu-toggle { display: inline-flex; }
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 30;
        transform: translateX(-100%); transition: transform .18s ease;
    }
    .shell.menu-open .sidebar { transform: none; }
    .shell.menu-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .4); }
    .topbar { padding: 10px 16px; gap: 8px; }
    .topbar-user { display: none; }
    .nav-account { display: flex; }
    .nav a, .nav button { font-size: 16px; padding: 11px 10px; }
    .content { padding: 16px; }
    .tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
    .tile { font-size: 14px; }
    .tile-icon { font-size: 32px; }
    #lookupForm input { max-width: none; }
    .toolbar.wrap > p.grow { flex-basis: 100%; text-align: left; }
}

/* ---------- Lookup fields (category, tags) ---------- */

.lookup { position: relative; }
.tag-box {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    min-height: 38px; padding: 4px 6px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: text;
}
.tag-box:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.tag-box input { flex: 1 1 120px; width: auto; min-height: 28px; padding: 2px 4px; border: 0; background: transparent; }
.tag-box input:focus-visible { outline: none; }
.tag-chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px;
    border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 14px;
}
.tag-chip button {
    width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
    background: transparent; color: inherit; font-size: 15px; line-height: 1; cursor: pointer;
}
.tag-chip button:hover { background: var(--hover); }
.lookup-menu {
    position: absolute; z-index: 20; top: 100%; left: 0; right: 0; margin: 2px 0 0; padding: 4px;
    list-style: none; max-height: 260px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
.lookup-menu li {
    display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px;
    border-radius: 6px; cursor: pointer;
}
.lookup-menu li.active, .lookup-menu li:hover { background: var(--hover); }
.lookup-menu li small { color: var(--muted); white-space: nowrap; }
.lookup-menu li.lookup-new { color: var(--accent); }
.lookup-menu li.lookup-empty { color: var(--muted); cursor: default; }

/* ---------- Tags & Categories page ---------- */

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
    min-height: 38px; padding: 6px 16px; border: 0; background: var(--surface); color: var(--muted);
    font: inherit; font-weight: 600; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.lookup-filter { max-width: 320px; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }
/* The rename suggestions may hang below the dialog's bottom edge. */
#renameLookupDialog { overflow: visible; }

/* ---------- All Shops ---------- */

.grid td strong + .badge { margin-left: 8px; }
.letter-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.letter-bar button {
    min-width: 32px; min-height: 32px; padding: 2px 8px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.letter-bar button:hover:not(:disabled) { background: var(--hover); }
.letter-bar button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.letter-bar button:disabled { opacity: .35; cursor: default; }

/* Spinner over a grid while it loads (class toggled from admin.js). */
.loading-host { position: relative; min-height: 120px; }
.loading-host.is-loading > * { opacity: .45; pointer-events: none; transition: opacity .15s; }
.loading-host.is-loading::after {
    content: ""; position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px;
    border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-host.is-loading::after { animation-duration: 2s; } }

/* Marketing message: WhatsApp-style preview of the chosen template. */
.error-text { color: var(--danger); }
#mkMediaFile { padding: 6px; }
#mkMediaFile + input { margin-top: 6px; }
.wa-preview { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #0b141a; }
.wa-preview > .muted { margin: 0; }
.wa-bubble { max-width: 360px; padding: 6px 8px 8px; border-radius: 8px; background: #202c33; color: #e9edef; }
.wa-header { padding: 4px 2px; font-weight: 700; }
.wa-media { display: block; width: 100%; max-height: 220px; object-fit: cover; border-radius: 6px; margin-bottom: 6px; }
.wa-media-empty { display: grid; place-items: center; height: 120px; background: #2a3942; color: var(--muted); font-size: 14px; }
.wa-body { padding: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.wa-footer { padding: 4px 2px 0; color: #8696a0; font-size: 13px; }
.wa-button { max-width: 360px; margin-top: 2px; padding: 8px; border-radius: 8px; background: #202c33; color: #53bdeb; text-align: center; font-size: 14px; }
.svc-compose { margin-top: 16px; }
.grid .svc-last { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.svc-filter { position: relative; }
.svc-filter-menu {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 20;
    min-width: 240px; padding: 6px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
    display: grid; gap: 4px;
}
.svc-filter-menu .btn { justify-content: flex-start; }

/* Shop Calls: shop view popup. */
#shopViewBody .view-row { display: grid; grid-template-columns: 90px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
#shopViewBody .view-row:last-child { border-bottom: 0; }
#shopViewBody .tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
#shopViewBody .tag { padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: .9em; }
