/* Theme "Ankleide": warm linen with a sage accent. All colors are tokens here. */
:root {
    --bg: #f6f3ee;
    --surface: #ffffff;
    --surface-2: #ece7df;
    --text: #25221f;
    --muted: #6f6860;
    --border: #ddd6cb;
    --accent: #4f6f5c;
    --accent-text: #ffffff;
    --accent-soft: #dde8e0;
    --warn-bg: #fbeed5;
    --warn-text: #6b4a10;
    --danger: #a3392f;
    --radius: 14px;
    --shadow: 0 1px 3px rgb(0 0 0 / 0.08);
    color-scheme: light;
}

/* Dark tokens twice: once for "follow the system" (unless the user picked
   light in the settings), once for an explicit dark choice. Keep in sync. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1c1b1a;
        --surface: #262422;
        --surface-2: #312e2b;
        --text: #eee9e2;
        --muted: #a39b91;
        --border: #3d3935;
        --accent: #8fb39c;
        --accent-text: #15201a;
        --accent-soft: #2e3d33;
        --warn-bg: #3d3220;
        --warn-text: #f0d7a6;
        --danger: #e07a70;
        --shadow: none;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #1c1b1a;
    --surface: #262422;
    --surface-2: #312e2b;
    --text: #eee9e2;
    --muted: #a39b91;
    --border: #3d3935;
    --accent: #8fb39c;
    --accent-text: #15201a;
    --accent-soft: #2e3d33;
    --warn-bg: #3d3220;
    --warn-text: #f0d7a6;
    --danger: #e07a70;
    --shadow: none;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: env(safe-area-inset-bottom);
}

[hidden] { display: none !important; }

h1 { font-size: 1.25rem; margin: 0; font-weight: 600; }
.muted { color: var(--muted); font-weight: normal; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- top bar */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; }
.icon-btn {
    display: grid; place-items: center;
    width: 40px; height: 40px;
    border: 0; border-radius: 50%;
    background: transparent; color: var(--text);
    cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

.banner {
    margin: 12px 16px 0;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: var(--warn-bg); color: var(--warn-text);
    font-size: 0.9rem;
}

main { max-width: 960px; margin: 0 auto; }
.boot { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 60vh; color: var(--muted); }
.view { padding: 16px; }

/* ---- buttons, inputs */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 46px; padding: 0 18px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface); color: var(--text);
    font: inherit; font-weight: 500;
    cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 6px; }

label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 500; }
.field-label { font-size: 0.9rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text);
    font: inherit; font-weight: normal;
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .chip:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }

label[for] { display: block; }
.password-field { position: relative; }
.password-field input { padding-right: 48px; }
.reveal {
    position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
    display: grid; place-items: center;
    width: 40px; height: 40px;
    border: 0; border-radius: 8px; background: transparent; color: var(--muted);
    cursor: pointer;
}
.reveal:hover { color: var(--text); }
.reveal:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.reveal .eye-closed, .reveal.on .eye-open { display: none; }
.reveal.on .eye-closed { display: block; }
.form-error { margin: 0; color: var(--danger); font-size: 0.9rem; }

/* ---- auth */
.auth { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card form { text-align: left; margin-top: 24px; }
.auth-logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 12px; }
.auth-card h1 { font-size: 1.6rem; }

/* ---- chips */
.chips, .filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    flex-shrink: 0;
    min-height: 36px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface); color: var(--text);
    font: inherit; font-size: 0.9rem;
    cursor: pointer;
}
.chip.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }

.swatch { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgb(0 0 0 / 0.2); }
.swatch-black { background: #111; }
.swatch-white { background: #fff; }
.swatch-cream { background: #f3ead3; }
.swatch-grey { background: #8d8d8d; }
.swatch-beige { background: #d6c3a1; }
.swatch-brown { background: #7a5232; }
.swatch-navy { background: #1f2d5a; }
.swatch-blue { background: #2f6fc4; }
.swatch-lightblue { background: #9cc6ea; }
.swatch-green { background: #3c8a4a; }
.swatch-olive { background: #6b6b2e; }
.swatch-red { background: #c9312c; }
.swatch-burgundy { background: #6e1f2d; }
.swatch-pink { background: #eda3bc; }
.swatch-purple { background: #7a4c9e; }
.swatch-yellow { background: #f0cf3a; }
.swatch-orange { background: #ea8a2e; }
.swatch-gold { background: linear-gradient(135deg, #b8912f, #f3dc8c, #b8912f); }
.swatch-silver { background: linear-gradient(135deg, #9a9a9a, #eee, #9a9a9a); }

/* ---- gallery */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    padding-bottom: 96px;
}
.tile {
    position: relative;
    display: flex; flex-direction: column;
    border-radius: var(--radius); overflow: hidden;
    background: var(--surface); box-shadow: var(--shadow);
    color: inherit; text-decoration: none;
}
.tile img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; background: var(--surface-2); display: block; }
.tile-label { padding: 8px 10px; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
    position: absolute; top: 8px; left: 8px;
    padding: 3px 9px; border-radius: 999px;
    background: var(--warn-bg); color: var(--warn-text);
    font-size: 0.75rem; font-weight: 600;
}
.badge.busy { background: var(--accent-soft); color: var(--text); }

.empty { text-align: center; padding: 48px 16px 120px; max-width: 420px; margin: 0 auto; }

.add-bar {
    position: fixed; left: 0; right: 0; bottom: 0;
    display: flex; justify-content: center; gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(transparent, var(--bg) 35%);
}

/* ---- item */
.item-layout { display: grid; gap: 16px; }
@media (min-width: 760px) {
    .item-layout { grid-template-columns: 1fr 1.2fr; align-items: start; }
    .item-photo-col { position: sticky; top: 80px; grid-row: span 2; }
}
.item-photo-col { display: flex; flex-direction: column; gap: 10px; }
.photo-tools { display: flex; align-items: center; justify-content: center; gap: 8px; }
.photo-tools .segmented { width: 100%; max-width: 280px; }
.small { font-size: 0.85rem; display: inline-flex; align-items: center; gap: 8px; }
.segmented[data-count="2"] { --segments: 2; }

/* Cut-out garments (transparent background) float on a calm surface with
   some air around them, instead of being cropped to fill the tile. */
img.cutout { object-fit: contain !important; padding: 8%; background: var(--surface-2); }
.tile img.cutout { padding: 10%; }
.item-photo { margin: 0; }
.item-photo img { width: 100%; max-height: 60vh; object-fit: contain; border-radius: var(--radius); background: var(--surface-2); display: block; }

.notice { margin: 0 0 8px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); font-size: 0.9rem; display: flex; align-items: center; gap: 10px; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.segmented { display: grid; grid-template-columns: repeat(var(--segments, 5), 1fr); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.segmented label { position: relative; font-weight: normal; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span { display: grid; place-items: center; min-height: 42px; padding: 4px; text-align: center; font-size: 0.78rem; background: var(--surface); border-left: 1px solid var(--border); }
.segmented label:first-child span { border-left: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.segmented[data-count="3"] { --segments: 3; }

.secondary-actions { display: flex; gap: 10px; }
.secondary-actions .btn { flex: 1; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- toast */
.toast {
    position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    padding: 10px 16px; border-radius: 999px;
    background: var(--text); color: var(--bg);
    font-size: 0.9rem; box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
}

/* ---- tabs */
.tabs {
    position: sticky; top: calc(61px + env(safe-area-inset-top)); z-index: 9;
    display: flex; gap: 4px;
    padding: 8px 16px 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.tabs a {
    flex: 1; text-align: center;
    padding: 10px 8px;
    color: var(--muted); text-decoration: none; font-weight: 500;
    border-bottom: 2px solid transparent;
}
.tabs a.selected { color: var(--text); border-bottom-color: var(--accent); }

/* ---- cards */
.card {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 16px;
}
.card h2 { font-size: 1.05rem; margin: 0 0 4px; font-weight: 600; }
.card.problem { text-align: center; padding: 28px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.card.problem p { margin: 0 0 6px; max-width: 420px; }

/* ---- today */
.today { display: flex; flex-direction: column; gap: 14px; max-width: 640px; margin: 0 auto; padding-bottom: 24px; }
.weather { display: flex; align-items: center; gap: 14px; }
.weather-emoji { font-size: 2.4rem; line-height: 1; }
.weather-title { font-weight: 600; }

.outfit { display: flex; flex-direction: column; gap: 12px; }
.outfit.chosen { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.outfit-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.outfit-item { display: flex; flex-direction: column; gap: 4px; color: inherit; text-decoration: none; font-size: 0.8rem; }
.outfit-item img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; background: var(--surface-2); display: block; }
.outfit-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.outfit-reason { margin: 0; color: var(--muted); font-size: 0.95rem; }
.today-actions { display: flex; justify-content: center; }

/* ---- admin */
.admin { display: flex; flex-direction: column; gap: 14px; max-width: 720px; margin: 0 auto; padding-bottom: 24px; }
.admin h3 { font-size: 0.95rem; margin: 6px 0 0; font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.stat-value { font-size: 1.4rem; font-weight: 600; }
.stat-label { font-size: 0.78rem; color: var(--muted); }
.admin-row { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 0.9rem; overflow-wrap: anywhere; }
.admin-row:first-of-type { border-top: 0; }

.admin-item summary { display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none; }
.admin-item summary::-webkit-details-marker { display: none; }
.admin-item summary img { width: 56px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--surface-2); flex-shrink: 0; }
.admin-item summary img.cutout { padding: 6%; }
.admin-item summary > span { display: flex; flex-direction: column; min-width: 0; }
.admin-item[open] summary { margin-bottom: 12px; }
.admin-item[open] { display: flex; flex-direction: column; gap: 10px; }
.admin-photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.admin-photos figure { margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; }
.admin-photos img { width: 100%; border-radius: 10px; background: var(--surface-2); display: block; }
.admin-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 0.88rem; }
.admin-facts dt { color: var(--muted); }
.admin-facts dd { margin: 0; overflow-wrap: anywhere; }
.admin-raw { margin: 0; padding: 10px; border-radius: 8px; background: var(--surface-2); font-size: 0.75rem; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

.tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); font-size: 0.75rem; font-weight: 600; }
.plan-actions { display: flex; flex-direction: column; gap: 8px; }
.admin-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.admin-actions .link-btn { padding-left: 0; }

/* ---- settings */
.settings { display: flex; flex-direction: column; gap: 14px; max-width: 560px; margin: 0 auto; }
.place-search { display: flex; gap: 8px; }
.place-search input { flex: 1; }
input[type=search] {
    width: 100%; padding: 11px 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text); font: inherit;
}
.place-results { display: flex; flex-direction: column; gap: 6px; }
.place {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 10px 12px; text-align: left;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer;
}
.place:hover { border-color: var(--accent); }
.align-start { align-self: flex-start; padding-left: 0; }
.card p { margin: 0; }

/* ---- pull to refresh (standalone PWA only, see app.js). Sits just above
   the top edge and slides into view as the page is pulled down. */
.ptr-indicator {
    position: fixed; top: calc(env(safe-area-inset-top) - 2rem); left: 50%; z-index: 30;
    width: 2rem; height: 2rem;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
    color: var(--muted); font-size: 1.1rem;
    opacity: 0;
    transform: translate(-50%, 0);
    transition: transform 0.2s, opacity 0.2s;
    pointer-events: none;
}
/* Follows the finger 1:1 while pulling; the transition only animates the
   snap back after an aborted pull. */
.ptr-indicator.pulling { transition: none; }
.ptr-indicator.ready, .ptr-indicator.refreshing { color: var(--accent); border-color: var(--accent); }
.ptr-indicator.refreshing { opacity: 1; animation: ptr-spin 0.8s linear infinite; }
@keyframes ptr-spin {
    from { transform: translate(-50%, 60px) rotate(0deg); }
    to { transform: translate(-50%, 60px) rotate(360deg); }
}
