/* ==========================================================================
   Loom Studio — application styles

   PRINCIPLES (from the brief): minimal, professional, fast, no unnecessary
   animation, dashboard-first.

   No CSS framework. At this size a framework costs more in overridden defaults
   than it saves. Custom properties carry the theme so there is one place to
   change a colour.

   Dark mode is handled by prefers-color-scheme only — no toggle, no stored
   preference, no JavaScript. The OS already knows the answer.
   ========================================================================== */

:root {
    --bg:            #f6f7f9;
    --surface:       #ffffff;
    --surface-alt:   #fafbfc;
    --border:        #e3e6ea;
    --border-strong: #cfd4da;

    --text:          #1a1d21;
    --text-muted:    #6b7280;
    --text-faint:    #9ca3af;

    --accent:        #2f5fd0;
    --accent-text:   #ffffff;
    --accent-soft:   #eef2fd;

    --success:       #17784b;
    --success-soft:  #e7f5ee;
    --danger:        #b4232a;
    --danger-soft:   #fdeceb;
    --warning:       #8a5a00;
    --warning-soft:  #fdf3e0;

    --radius:        6px;
    --sidebar-width: 220px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
            Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:            #14161a;
        --surface:       #1c1f24;
        --surface-alt:   #22262c;
        --border:        #2e333a;
        --border-strong: #3d444d;

        --text:          #e8eaed;
        --text-muted:    #9aa3ad;
        --text-faint:    #6b737d;

        --accent:        #6b93ea;
        --accent-text:   #10131a;
        --accent-soft:   #1e2739;

        --success:       #4ec38b;
        --success-soft:  #16281f;
        --danger:        #f08a86;
        --danger-soft:   #2b1918;
        --warning:       #e0aa4f;
        --warning-soft:  #2a2113;
    }
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.3; }

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

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

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
}

.brand-mark {
    width: 26px;
    height: 26px;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 700;
    display: grid;
    place-items: center;
    flex: 0 0 26px;
}

.brand-text { font-weight: 600; letter-spacing: -0.01em; }

.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 1px; }

.nav-link {
    padding: 7px 10px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
}

.nav-link:hover { background: var(--surface-alt); color: var(--text); text-decoration: none; }

.nav-link.is-active { background: var(--accent-soft); color: var(--accent); }

.sidebar-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }

.phase-badge { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }

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

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.page-title { font-size: 19px; }
.business-name { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }

.content { padding: 20px 24px 48px; }

/* --- Cards & layout ------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.card-title { font-size: 15px; }
.card-note { margin: 0; color: var(--text-muted); font-size: 12.5px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* --- Stat tiles ----------------------------------------------------------- */

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.stat-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.stat-label { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.stat-sub   { color: var(--text-faint); font-size: 11.5px; margin-top: 4px; }

/* --- Tables -------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }

table.data th,
table.data td {
    text-align: left;
    padding: 9px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

table.data th {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

table.data tbody tr:hover { background: var(--surface-alt); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.actions { white-space: nowrap; text-align: right; }

/* --- Badges -------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-neutral { background: var(--surface-alt); color: var(--text-muted); border-color: var(--border); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent); }

/* --- Buttons ------------------------------------------------------------- */

.btn {
    display: inline-block;
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: var(--surface-alt); text-decoration: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.btn-danger { color: var(--danger); border-color: var(--border-strong); }
.btn-small  { padding: 3px 8px; font-size: 12px; }
.btn-link   { border: 0; background: none; color: var(--accent); padding: 3px 6px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* --- Forms --------------------------------------------------------------- */

.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.field { display: flex; flex-direction: column; gap: 4px; }
.field-wide { grid-column: 1 / -1; }

.field label { font-weight: 600; font-size: 12.5px; }

.field input[type="text"],
.field input[type="number"],
.field input[type="email"],
.field input[type="url"],
.field input[type="date"],
.field input[type="time"],
.field input[type="datetime-local"],
.field select,
.field textarea {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13.5px;
}

.field textarea { resize: vertical; min-height: 84px; line-height: 1.55; }

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

.field-help  { color: var(--text-muted); font-size: 12px; }
.field-error { color: var(--danger); font-size: 12px; font-weight: 500; }

.field.has-error input,
.field.has-error select,
.field.has-error textarea { border-color: var(--danger); }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row label { font-weight: 500; font-size: 13.5px; }

/* Occasion checkbox grid on the product form. */
.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: var(--surface-alt);
}

.check-item { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.check-item .shared { color: var(--text-faint); font-size: 11px; }

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 14px;
}

.filters .field { gap: 3px; min-width: 150px; }

/* --- Flash --------------------------------------------------------------- */

.flash-stack { padding: 14px 24px 0; display: flex; flex-direction: column; gap: 8px; }

.flash {
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 500;
}

.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error   { background: var(--danger-soft);  color: var(--danger); }
.flash-info    { background: var(--accent-soft);  color: var(--accent); }

/* --- Empty states -------------------------------------------------------- */

.empty {
    padding: 22px 16px;
    text-align: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-alt);
}

.empty-message { margin: 0; color: var(--text-muted); font-size: 13.5px; }
.empty-hint    { margin: 5px 0 0; color: var(--text-faint); font-size: 12.5px; }

.phase-tag {
    display: inline-block;
    margin-top: 9px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text-faint);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- Draft caption preview ------------------------------------------------ */

.caption-preview {
    white-space: pre-wrap;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    font-size: 13.5px;
    line-height: 1.6;
    margin: 0;
    font-family: inherit;
}

.hashtag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.hashtag {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 999px;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 500;
}

.meta-list { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; }
.meta-list dt { color: var(--text-muted); font-weight: 500; }
.meta-list dd { margin: 0; }

/* --- Holiday relevance meter --------------------------------------------- */

.relevance { display: inline-flex; gap: 2px; vertical-align: middle; }

.relevance i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border-strong);
    display: block;
}

.relevance i.on { background: var(--accent); }

/* --- Errors -------------------------------------------------------------- */

.error-card { max-width: 620px; }
.error-status { margin: 0; font-size: 30px; font-weight: 700; color: var(--text-faint); }
.error-title { font-size: 18px; margin: 4px 0 8px; }
.error-message { color: var(--text-muted); margin: 0 0 14px; }

.error-trace {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 11px;
    font-family: var(--mono);
    font-size: 11.5px;
    overflow-x: auto;
    max-height: 320px;
    color: var(--text-muted);
}

/* --- Utilities ----------------------------------------------------------- */

.muted   { color: var(--text-muted); }
.faint   { color: var(--text-faint); }
.nowrap  { white-space: nowrap; }
.mt-0    { margin-top: 0; }
.mb-0    { margin-bottom: 0; }
.mb-16   { margin-bottom: 16px; }
.text-right { text-align: right; }

.inline-form { display: inline; }

/* --- Auth shell (login, error pages) ------------------------------------- */

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.auth-brand-name { font-weight: 650; letter-spacing: -0.01em; }
.auth-brand-tag  { color: var(--text-muted); font-size: 12px; }

.auth-title { font-size: 17px; margin-bottom: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 13px; }
.auth-submit { width: 100%; padding: 8px 12px; }
.auth-foot { margin: 16px 0 0; color: var(--text-faint); font-size: 12px; line-height: 1.6; }

.auth-code {
    display: inline-block;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--mono);
    font-size: 11.5px;
}

/* The error page reuses .card, which needs no outer margin inside .auth-card. */
.auth-card .card { border: 0; padding: 0; margin: 0; background: none; }

/* --- Nav groups ---------------------------------------------------------- */

.nav-group-label {
    padding: 12px 10px 4px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
}

/* --- Topbar right: business switcher + user menu -------------------------- */

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

.switcher select {
    padding: 5px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    max-width: 190px;
}

.user-menu { display: flex; align-items: center; gap: 9px; }
.user-name { font-size: 13px; font-weight: 500; }

/* --- Percentage bar (content mix) ---------------------------------------- */

.bar {
    display: block;
    width: 100%;
    min-width: 90px;
    height: 7px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill { display: block; height: 100%; background: var(--accent); }

.pct-input {
    width: 74px;
    padding: 4px 7px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    text-align: right;
}

/* --- Knowledge editing / prompt preview ---------------------------------- */

/* Markdown is written in a monospace field: alignment and indentation are
   meaningful, and a proportional font hides trailing-space and list problems. */
.mono-input {
    font-family: var(--mono) !important;
    font-size: 12.5px !important;
    line-height: 1.65 !important;
    tab-size: 4;
}

.prompt-preview {
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
    margin: 0;
    max-height: 620px;
    overflow-y: auto;
    color: var(--text);
}

.preview-list { margin: 0; padding-left: 20px; font-size: 13.5px; line-height: 1.9; }

code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: var(--surface-alt);
    border-radius: 3px;
    padding: 1px 4px;
}

/* --- Approval queue review cards ----------------------------------------- */

.review {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 14px;
    background: var(--surface-alt);
}

.review:last-child { margin-bottom: 0; }

.review-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 10px;
}

.review-title { font-weight: 600; font-size: 14.5px; }

.review-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 3px;
    font-size: 12.5px;
}

.review-reason {
    margin: 10px 0 0;
    padding: 9px 11px;
    border-left: 3px solid var(--accent);
    background: var(--surface);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 13px;
    color: var(--text-muted);
}

.review-actions { margin-top: 12px; }

/* --- Disclosure forms (reject / schedule) --------------------------------- */

/* <details> rather than JS so these work with scripting off. The friction of opening the
   disclosure is deliberate for rejection: a reason is mandatory. */
.reject-box,
.schedule-box {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.reject-box > summary,
.schedule-box > summary {
    padding: 7px 11px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    user-select: none;
}

.reject-box > summary:hover,
.schedule-box > summary:hover { color: var(--text); }

.reject-box[open] > summary,
.schedule-box[open] > summary { border-bottom: 1px solid var(--border); }

.reject-box > form,
.schedule-box > form { padding: 11px; display: flex; flex-direction: column; gap: 10px; }

/* In a table cell the disclosure must not stretch the column. */
td .schedule-box { min-width: 210px; }

/* --- Decision timeline ---------------------------------------------------- */

.timeline { list-style: none; margin: 0; padding: 0; }

.timeline-item {
    position: relative;
    padding: 0 0 14px 18px;
    border-left: 2px solid var(--border);
}

.timeline-item:last-child { padding-bottom: 0; border-left-color: transparent; }

.timeline-item::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.timeline-action { font-size: 13.5px; font-weight: 500; }
.timeline-meta   { font-size: 12px; color: var(--text-faint); margin-top: 1px; }

.timeline-note {
    margin-top: 6px;
    padding: 7px 10px;
    background: var(--surface-alt);
    border-radius: var(--radius);
    font-size: 12.5px;
    color: var(--text-muted);
}

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

@media (max-width: 800px) {
    .shell { flex-direction: column; }

    .sidebar {
        width: 100%;
        flex: none;
        height: auto;
        position: static;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .nav { flex-direction: row; overflow-x: auto; }
    .sidebar-foot { display: none; }
    .content { padding: 16px; }
    .topbar { padding: 16px; }
    .flash-stack { padding: 12px 16px 0; }
}
