/*
 * Loop — one hand-written stylesheet. No Tailwind, no Vite, no npm build.
 *
 * WHY: the cPanel server has no Terminal, no Node and no Composer. A plain CSS
 * file uploads as-is and never needs compiling. Everything here is plain CSS
 * with custom properties ("variables"), which is also what makes dark mode
 * nearly free: we only swap six token values on [data-theme="dark"].
 *
 * COLOUR RULE: monochrome only — near-black, white, cool greys. No purple,
 * no green, no accent hue. Status is encoded by WEIGHT, FILL and SHAPE:
 *   done      = grey + strikethrough + ticked box
 *   overdue   = solid ink chip with white text (solid light chip in dark mode)
 *   important = filled dot
 *   active    = ink fill with white icon
 * That means status never depends on colour alone — better accessibility.
 */

:root {
    --bg: #FFFFFF;
    --surface: #F4F6F8;
    --ink: #16181D;
    --muted: #626D7D;
    --border: #D8DCE2;
    --soft: #3C424E;
    --inverse-bg: #16181D;
    --inverse-ink: #FFFFFF;
    --radius: 12px;
    --radius-sm: 8px;
}

[data-theme="dark"] {
    --bg: #16181D;
    --surface: #1F232B;
    --ink: #F4F6F8;
    --muted: #A6AFBD;
    --border: #3C424E;
    --soft: #D8DCE2;
    --inverse-bg: #F4F6F8;
    --inverse-ink: #16181D;
}

/* ---------------------------------------------------------------------------
   Base. system-ui keeps the UI native on macOS, iOS and Android without
   downloading a font — important on a phone with a weak connection.
   --------------------------------------------------------------------------- */
* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--ink);
    font: 400 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(112px + env(safe-area-inset-bottom));
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-weight: 500; margin: 0; }
p { margin: 0 0 10px; }
small, .small { font-size: 12px; }
.muted { color: var(--muted); }

.shell { max-width: 860px; margin: 0 auto; padding: 0 16px; }
.content { padding: 16px 0 24px; }

/* ---------------------------------------------------------------------------
   Top bar
   --------------------------------------------------------------------------- */
.topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 18px 0 12px; border-bottom: 0.5px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-size: 16px; font-weight: 500; }
.brand-mark { width: 34px; height: 34px; }
.page-title { font-size: 15px; font-weight: 500; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 12px; }

/* ---------------------------------------------------------------------------
   Buttons, links, forms
   --------------------------------------------------------------------------- */
.btn, .link-btn, button {
    font: inherit; cursor: pointer;
}
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 9px 14px; border-radius: var(--radius-sm);
    border: 0.5px solid var(--border); background: var(--bg); color: var(--ink);
    font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--inverse-bg); color: var(--inverse-ink); border-color: var(--inverse-bg); }
.btn-quiet { color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; font-size: 12px; color: var(--muted); }
.link-btn:hover { color: var(--ink); }

label { display: block; font-size: 13px; margin: 0 0 12px; }
label > input, label > select, .inline-form input, .inline-form select,
.evidence input, .install-card input, .install-card select {
    display: block; width: 100%; margin-top: 5px;
    padding: 9px 11px; font: inherit; font-size: 14px;
    color: var(--ink); background: var(--bg);
    border: 0.5px solid var(--border); border-radius: var(--radius-sm);
}
input:focus, select:focus, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--ink); outline-offset: 2px;
}
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checkbox input { width: auto; margin: 0; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input { flex: 1 1 220px; margin: 0; }
.inline-form select { flex: 0 1 150px; margin: 0; }

/* ---------------------------------------------------------------------------
   Cards, chips, tags
   --------------------------------------------------------------------------- */
.card {
    background: var(--bg); border: 0.5px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.card-title { font-size: 15px; font-weight: 500; }
.stage-title { font-size: 13px; color: var(--muted); margin: 0 0 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
    font-size: 12px; padding: 6px 11px; border-radius: 999px;
    border: 0.5px solid var(--border); color: var(--muted);
}
.chip b { font-weight: 500; color: var(--ink); margin-left: 4px; }
.chip.is-active { background: var(--inverse-bg); color: var(--inverse-ink); border-color: var(--inverse-bg); }
.chip.is-active b { color: var(--inverse-ink); }

.tag {
    font-size: 11px; padding: 2px 7px; border-radius: 6px;
    border: 0.5px solid var(--border); color: var(--muted); white-space: nowrap;
}
.tag-solid { background: var(--inverse-bg); color: var(--inverse-ink); border-color: var(--inverse-bg); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); }

.flash, .alert {
    border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px;
    margin: 0 0 14px; border: 0.5px solid var(--border); background: var(--surface);
}
.alert { border-color: var(--muted); }
.alert p { margin: 0 0 4px; }

.empty { text-align: center; padding: 48px 16px; }
.empty h2 { font-size: 18px; margin-bottom: 6px; }

/* ---------------------------------------------------------------------------
   Checks — the one-tap tick row
   --------------------------------------------------------------------------- */
.check-row {
    display: flex; align-items: flex-start; gap: 11px;
    padding: 9px 0; border-top: 0.5px solid var(--border);
}
.check-row:first-of-type { border-top: 0; }
.check-box {
    width: 19px; height: 19px; flex: 0 0 19px; margin-top: 2px; padding: 0;
    border: 0.5px solid var(--muted); border-radius: 5px; background: transparent;
    display: flex; align-items: center; justify-content: center;
}
.check-box.is-checked { background: var(--inverse-bg); border-color: var(--inverse-bg); }
.check-body { flex: 1; min-width: 0; }
.check-label { font-size: 14px; }
.check-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.check-detail.is-done .check-label { color: var(--muted); text-decoration: line-through; }
.evidence { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.evidence input { flex: 1; min-width: 0; margin: 0; font-size: 13px; padding: 6px 9px; }

/* ---------------------------------------------------------------------------
   Loops list, progress, detail header
   --------------------------------------------------------------------------- */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.loop-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.progress { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 92px; }
.progress-num { font-size: 12px; color: var(--muted); }
.progress-bar { display: block; width: 90px; height: 4px; border-radius: 2px; background: var(--surface); overflow: hidden; }
.progress-bar i { display: block; height: 100%; background: var(--ink); }
.loop-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.progress-text { font-size: 17px; font-weight: 500; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.step-list { list-style: none; padding: 0; margin: 12px 0; }
.step-list li {
    display: flex; align-items: center; gap: 9px; padding: 7px 0;
    border-top: 0.5px solid var(--border); font-size: 13px;
}
.step-list li span:first-child { flex: 1; }
details > summary { cursor: pointer; margin-top: 8px; }

/* Floating dock */
.nav {
    position: fixed;
    z-index: 20;
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
    gap: clamp(3px, 1.5vw, 12px);
    width: min(calc(100% - 24px), 440px);
    padding: 7px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: 0 10px 30px rgba(18, 26, 43, .14), inset 0 1px rgba(255, 255, 255, .22);
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 52px;
    border-radius: 16px;
    color: var(--muted);
    font-size: clamp(10px, 2.8vw, 11px);
    line-height: 1.2;
}
.nav-item.is-active {
    background: var(--bg);
    box-shadow: 0 1px 4px rgba(18, 26, 43, .1);
    color: var(--ink);
    font-weight: 600;
}
.nav-icon {
    display: block;
    width: 24px;
    height: 24px;
    background: currentColor;
    mask: var(--nav-icon) center / contain no-repeat;
}
.icon-open { --nav-icon: url('/icons/open.svg'); }
.icon-loops { --nav-icon: url('/icons/loops.svg'); }
.icon-new { --nav-icon: url('/icons/new.svg'); }
.icon-playbooks { --nav-icon: url('/icons/playbooks.svg'); }
.icon-settings { --nav-icon: url('/icons/settings.svg'); }
.nav-add {
    width: 46px;
    height: 46px;
    min-height: 44px;
    justify-self: center;
    border-radius: 50%;
    background: var(--inverse-bg);
    color: var(--inverse-ink);
}
.nav-add .nav-icon { width: 28px; height: 28px; }

@media (min-width: 760px) {
    .nav {
        bottom: calc(22px + env(safe-area-inset-bottom));
        width: 490px;
        padding: 10px 12px;
        gap: 15px;
    }
    .nav-item { min-height: 58px; }
    .nav-icon { width: 26px; height: 26px; }
    .nav-add { width: 52px; height: 52px; min-height: 44px; }
}
@media (hover: hover) and (pointer: fine) {
    .nav-item:hover { color: var(--ink); }
    .nav-add:hover { color: var(--inverse-ink); }
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
    .nav-item { transition: transform 160ms ease-out; }
    .nav-item:hover { transform: translateY(-4px); }
}

/* ---------------------------------------------------------------------------
   Quick-add sheet. :target means it opens from a plain #hash link — no JS.
   --------------------------------------------------------------------------- */
.sheet { display: none; position: fixed; inset: 0; z-index: 30; background: rgba(22,24,29,0.45); padding: 20px; align-items: flex-end; justify-content: center; }
.sheet:target { display: flex; }
.sheet-card { width: 100%; max-width: 460px; background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 20px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { font-size: 16px; }

/* ---------------------------------------------------------------------------
   Login + installer (standalone pages)
   --------------------------------------------------------------------------- */
.install-page { display: flex; justify-content: center; align-items: flex-start; padding: 48px 16px; }
.install-card {
    width: 100%; max-width: 460px; padding: 28px;
    background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius);
}
.install-card .brand { margin-bottom: 20px; }
.install-card h1 { font-size: 20px; margin-bottom: 6px; }
.install-card fieldset { border: 0; border-top: 0.5px solid var(--border); padding: 14px 0 0; margin: 16px 0 0; }
.install-card legend { font-size: 13px; font-weight: 500; padding: 0 8px 0 0; }
.install-card code { font-size: 12px; }

/* Installer "server check" panel.
   Why it exists: the host has no Terminal, so this is the only place the user
   can see PHP extensions and folder permissions. Status is shown by a tick /
   cross and by font weight, NOT by colour — part of Loop's monochrome rule
   (no status-by-hue, so it works in both light and dark mode). */
.preflight { margin: 16px 0 0; padding: 10px 12px; border: 0.5px solid var(--border); border-radius: var(--radius-sm); }
.preflight > summary { font-size: 13px; font-weight: 500; cursor: pointer; }
.preflight-list { list-style: none; margin: 10px 0 0; padding: 0; }
.preflight-row { display: flex; gap: 8px; align-items: baseline; font-size: 12px; padding: 2px 0; color: var(--muted); }
.preflight-row.pf-ok { color: var(--muted); font-weight: 400; }
.preflight-row.pf-bad { color: var(--ink); font-weight: 600; }
.pf-mark { display: inline-block; width: 12px; flex: none; font-weight: 700; }

@media (max-width: 480px) {
    .topbar { flex-wrap: wrap; }
    .page-title { order: 3; flex-basis: 100%; }
    .card { padding: 12px; }
}

/* Mobile pending work and the supplied outline icon set. */
.capture { background: var(--surface); padding: 14px; }
.capture label { margin-bottom: 6px; font-weight: 600; }
.capture-field { display: flex; gap: 8px; }
.capture-field input {
    flex: 1; min-width: 0; padding: 9px 11px; min-height: 44px;
    border-radius: var(--radius-sm); border: 1px solid var(--border);
    background: var(--bg); color: var(--ink); font: inherit; font-size: 16px;
}
.capture-field .btn { min-width: 58px; }
.capture-error { margin: 6px 0 0; font-size: 13px; }
.pending-pages { display: flex; justify-content: center; align-items: center; gap: 12px; font-size: 13px; }
.check-box {
    width: 44px; height: 44px; padding: 0; margin: 0;
    position: relative; border: 0; background: transparent;
}
.check-box::before {
    content: ""; width: 19px; height: 19px; border: 1px solid var(--muted);
    border-radius: 5px; display: block;
}
.check-box.is-checked { background: transparent; }
.check-box.is-checked::before { background: var(--inverse-bg); border-color: var(--inverse-bg); }
.check-box.is-checked::after {
    content: ""; position: absolute; width: 14px; height: 14px;
    background: var(--inverse-ink); mask: url('/icons/tick.svg') center / contain no-repeat;
}
.loop-group .check-row { align-items: center; gap: 6px; }
.check-label { overflow-wrap: anywhere; }
.sheet { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.sheet-card { max-height: calc(100dvh - 40px); overflow: auto; }
.sheet-card input, .sheet-card select { font-size: 16px; }

/* Pending groups, Loop library and checklist progress. */
.pending-group-title { font-size: 14px; }
.pending-group-title a {
    min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.pending-group-title a span { font-size: 20px; line-height: 1; color: var(--muted); }
.inbox-group { background: var(--surface); }
.loop-group .check-row { padding: 2px 0; }
.loops-tools { background: var(--surface); }
.loops-tools label { margin-bottom: 6px; font-weight: 600; }
.loops-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.loops-toolbar .chips { margin-bottom: 0; }
.loops-toolbar .chip, .loops-toolbar .btn { min-height: 40px; display: inline-flex; align-items: center; }
.loop-card { align-items: flex-start; }
.loop-card:hover { border-color: var(--muted); }
.loop-card-body { min-width: 0; overflow-wrap: anywhere; }
.next-check { margin-top: 6px; font-size: 13px; }
.next-check .muted { margin-right: 4px; }
.loop-progress { width: 100%; height: 6px; display: block; accent-color: var(--ink); }
.loop-card .loop-progress { width: 84px; }
.checklist-overview { background: var(--surface); }
.checklist-overview .progress-text { margin-top: 2px; }
.completed-toggle { margin: 10px 0 0; min-height: 36px; width: fit-content; cursor: pointer; }
.completed-toggle input { accent-color: var(--ink); }
.loop-actions { position: relative; }
.loop-actions > summary { min-height: 40px; gap: 7px; margin: 0; list-style: none; }
.loop-actions > summary::-webkit-details-marker { display: none; }
.loop-actions-panel {
    position: absolute; z-index: 2; right: 0; top: calc(100% + 6px);
    min-width: 156px; padding: 4px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); box-shadow: 0 8px 20px rgba(18,26,43,.12);
}
.loop-actions-panel button {
    display: block; width: 100%; min-height: 44px; padding: 8px 10px; text-align: left;
    border: 0; border-radius: 5px; background: transparent; color: var(--ink); white-space: nowrap;
}
.loop-actions-panel button:hover { background: var(--surface); }
.stage-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 10px; }
.stage-heading h2 { font-size: 15px; }
.stage-complete { display: none; margin: 4px 0; }
.loop-checklist:has([data-hide-completed]:checked) .check-row.is-done { display: none; }
.loop-checklist:has([data-hide-completed]:checked) .checklist-stage:not(:has(.check-row:not(.is-done))) .stage-complete { display: block; }
