:root {
    color-scheme: light;
    --ink: #172019;
    --muted: #6a756c;
    --line: #dfe5df;
    --surface: #ffffff;
    --soft: #f3f6f2;
    --accent: #2f6d42;
    --accent-dark: #225333;
    --danger: #a6453c;
    --shadow: 0 14px 40px rgba(35, 57, 40, 0.09);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 7% 0%, rgba(117, 164, 112, 0.16), transparent 30rem),
        #f7f8f5;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

.site-header {
    height: 72px;
    padding: 0 max(24px, calc((100vw - 1180px) / 2));
    border-bottom: 1px solid rgba(31, 57, 38, 0.1);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(145deg, #408656, #245c37);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .04em;
    box-shadow: 0 7px 18px rgba(47, 109, 66, .22);
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 12px; }

.user-menu { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.user-menu a, .link-button { color: var(--accent-dark); font-weight: 650; }
.user-menu form { margin: 0; }
.link-button { border: 0; padding: 0; background: none; cursor: pointer; font: inherit; }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 72px; }
.page-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 28px; }
.page-heading h1, .login-card h1 { margin: 4px 0 8px; font-size: clamp(30px, 4vw, 44px); letter-spacing: -.035em; }
.eyebrow { margin: 0; color: var(--accent); text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 800; }
.muted { margin: 0; color: var(--muted); }
.result-pill { padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); white-space: nowrap; }
.result-pill strong { color: var(--ink); }
.live-dot { width: 8px; height: 8px; margin-right: 6px; display: inline-block; border-radius: 50%; background: #43a35c; box-shadow: 0 0 0 3px rgba(67,163,92,.12); }
.live-dot.is-refreshing { animation: live-pulse .8s ease-in-out infinite alternate; }
.live-dot.is-offline { background: #b44d43; box-shadow: 0 0 0 3px rgba(180,77,67,.12); }
@keyframes live-pulse { to { opacity: .35; } }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr 1.5fr; gap: 14px; margin-bottom: 18px; }
.stat-card { padding: 18px 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 6px 24px rgba(35,57,40,.04); }
.stat-card span { display: block; color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 5px; font-size: 27px; letter-spacing: -.03em; }
.stat-card small { font-size: 14px; font-weight: 600; color: var(--muted); }

.filter-panel { margin-bottom: 24px; padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.82); box-shadow: var(--shadow); }
.csrf-token-holder { display: none; }
.find-request-status { margin-bottom: 18px; padding: 14px 17px; border: 1px solid #b8d7bf; border-radius: 14px; background: #edf7ef; color: #245d35; }
.find-request-status div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 18px; }
.find-request-status strong, .find-request-status span { font-size: 13px; }
.find-request-status.is-idle { border-color: var(--line); background: rgba(255,255,255,.72); color: var(--muted); }
.find-request-status.is-error { border-color: #e1b9b5; background: #f9e9e7; color: var(--danger); }
.filter-form { display: grid; grid-template-columns: 1fr 1.45fr .62fr 1fr auto; gap: 14px; align-items: end; }
.field label, .login-form label { display: block; margin-bottom: 7px; color: #4c5a4f; font-size: 12px; font-weight: 750; }
.field select, .field input, .login-form input {
    width: 100%;
    height: 42px;
    border: 1px solid #ccd5cd;
    border-radius: 11px;
    padding: 0 12px;
    background: white;
    color: var(--ink);
    font: inherit;
    outline: none;
}
.field select:focus, .field input:focus, .login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,109,66,.12); }
.color-input-row { display: grid; grid-template-columns: 1fr 46px; gap: 7px; }
.color-input-row input[type="color"] { padding: 5px; cursor: pointer; }
.filter-actions { display: flex; gap: 8px; }
.primary-button, .secondary-button {
    min-height: 42px;
    border-radius: 11px;
    padding: 0 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
}
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-dark); }
.secondary-button { border: 1px solid var(--line); background: white; color: var(--ink); }
.filter-hint { margin: 13px 0 0; color: var(--muted); font-size: 12px; }
.field-error { color: var(--danger); }

.spool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.spool-card { min-width: 0; overflow: hidden; display: grid; grid-template-columns: 13px 1fr; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.spool-card.is-written-off { opacity: .7; }
.spool-color { background: var(--spool-color); box-shadow: inset -1px 0 rgba(0,0,0,.08); }
.spool-main { min-width: 0; padding: 20px; }
.spool-title-row { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.spool-kicker { margin: 0 0 4px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.spool-title-row h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.spool-actions { display: grid; justify-items: end; gap: 8px; }
.status-badge { border-radius: 999px; padding: 6px 9px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-in_stock { color: #236139; background: #e5f3e8; }
.status-written_off { color: #8a3932; background: #f7e7e5; }
.find-spool-button { border: 1px solid #b9cabd; border-radius: 9px; padding: 6px 9px; background: white; color: var(--accent-dark); font: inherit; font-size: 11px; font-weight: 750; cursor: pointer; }
.find-spool-button:hover { border-color: var(--accent); background: #f3f8f4; }
.find-spool-button:disabled { cursor: wait; opacity: .65; }
.spool-meta { margin-top: 13px; display: flex; flex-wrap: wrap; gap: 7px 13px; color: var(--muted); font-size: 12px; }
.spool-meta span { display: inline-flex; align-items: center; gap: 6px; }
.color-dot { width: 12px; height: 12px; border: 1px solid rgba(0,0,0,.15); border-radius: 50%; background: var(--spool-color); }
.remaining-row { margin-top: 20px; }
.remaining-label { margin-bottom: 8px; display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.remaining-label strong { color: var(--ink); }
.progress { height: 8px; overflow: hidden; border-radius: 999px; background: #e9ede8; }
.progress span { display: block; width: var(--remaining); height: 100%; border-radius: inherit; background: linear-gradient(90deg, #4c955e, #82b66f); }
.spool-details { margin: 18px 0 0; padding-top: 15px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.spool-details div { min-width: 0; }
.spool-details dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .07em; }
.spool-details dd { margin: 3px 0 0; overflow: hidden; text-overflow: ellipsis; color: #39433b; font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; white-space: nowrap; }

.empty-state { padding: 60px 24px; border: 1px dashed #cbd5cb; border-radius: 20px; text-align: center; color: var(--muted); }
.empty-state span { width: 50px; height: 50px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; background: #e7ece6; color: var(--accent); font-weight: 800; }
.empty-state h2 { margin: 0 0 6px; color: var(--ink); }
.empty-state p { margin: 0; }

.login-shell { min-height: calc(100vh - 190px); display: grid; place-items: center; }
.login-card { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 24px; background: white; box-shadow: var(--shadow); }
.login-card h1 { font-size: 34px; }
.login-form { margin-top: 25px; display: grid; gap: 9px; }
.login-form label:not(:first-child) { margin-top: 8px; }
.login-form .primary-button { margin-top: 12px; }
.alert { margin-top: 18px; padding: 11px 13px; border-radius: 10px; background: #f9e9e7; color: #8a3932; font-size: 13px; }

@media (max-width: 900px) {
    .filter-form { grid-template-columns: 1fr 1fr; }
    .filter-actions { align-self: end; }
    .spool-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .site-header { height: auto; min-height: 68px; padding: 12px 18px; }
    .brand small, .user-menu > span { display: none; }
    .user-menu { gap: 12px; }
    .page-shell { width: min(100% - 28px, 1180px); padding-top: 30px; }
    .page-heading { align-items: start; }
    .result-pill { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .wide-stat { grid-column: 1 / -1; }
    .filter-form { grid-template-columns: 1fr; }
    .filter-actions > * { flex: 1; }
    .spool-main { padding: 17px; }
    .spool-details { grid-template-columns: 1fr; }
}
