:root {
  color-scheme: light;
  --bg: #f2f0e9;
  --surface: #fffdf7;
  --surface-strong: #ffffff;
  --ink: #18201c;
  --muted: #647068;
  --line: #d8ddd7;
  --primary: #17231d;
  --primary-ink: #ffffff;
  --accent: #d8ff72;
  --green: #2f8f59;
  --green-soft: #e4f5e9;
  --yellow: #b57900;
  --yellow-soft: #fff1bf;
  --red: #c34747;
  --red-soft: #fde5e4;
  --shadow: 0 18px 55px rgba(24, 32, 28, .09);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { min-width: 0; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 90% -10%, rgba(216,255,114,.45), transparent 28rem), var(--bg); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid #6a8b19; outline-offset: 2px; }
[hidden] { display: none !important; }

.login-layout { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); background: rgba(255,253,247,.94); border: 1px solid var(--line); border-radius: 30px; box-shadow: var(--shadow); padding: clamp(24px, 7vw, 44px); }
.brand-mark { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 17px; background: var(--primary); color: var(--accent); font-size: 1.5rem; font-weight: 900; transform: rotate(-4deg); }
.brand-mark-small { width: 38px; height: 38px; border-radius: 12px; font-size: 1rem; flex: 0 0 auto; }
.eyebrow { margin: 18px 0 6px; color: var(--muted); font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .16em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(2rem, 6vw, 3.6rem); line-height: .98; letter-spacing: -.055em; }
h2 { margin-bottom: 8px; font-size: 1.35rem; letter-spacing: -.025em; }
h3 { margin-bottom: 6px; font-size: 1rem; }
.lead { color: var(--muted); line-height: 1.5; margin-bottom: 28px; }
.stack { display: grid; gap: 15px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field > span { color: var(--muted); font-size: .78rem; font-weight: 750; }
.field input, .field textarea, .field select { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-strong); color: var(--ink); padding: 10px 12px; }
.field textarea { resize: vertical; line-height: 1.5; }
.form-error { min-height: 20px; margin: 0; color: var(--red); font-size: .82rem; }
.button { min-height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 15px; background: var(--surface); color: var(--ink); font-weight: 780; transition: transform .15s ease, border-color .15s ease; }
.button:hover { transform: translateY(-1px); border-color: #9eaaa2; }
.button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.button-quiet { background: transparent; }
.button-block { width: 100%; }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 1.5rem; }

.app-shell { min-height: 100vh; padding-bottom: 30px; }
.topbar { height: 70px; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 0 max(20px, calc((100% - 1180px) / 2)); border-bottom: 1px solid rgba(216,221,215,.85); background: rgba(242,240,233,.78); backdrop-filter: blur(16px); position: sticky; top: 0; z-index: 10; }
.brand-button { display: flex; align-items: center; gap: 10px; background: transparent; border: 0; color: var(--ink); padding: 0; text-align: left; }
.brand-button strong, .brand-button small { display: block; }
.brand-button small { color: var(--muted); font-size: .7rem; margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.mobile-label { display: none; }
.main-content { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 42px 0 60px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 24px; }
.page-heading .eyebrow { margin-top: 0; }
.page-heading h1 { margin-bottom: 0; }
.status-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.status-stat { display: flex; align-items: center; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,247,.66); }
.status-stat i { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.status-stat strong, .status-stat span { display: block; }
.status-stat strong { font-size: 1.35rem; }
.status-stat span { color: var(--muted); font-size: .76rem; }
.status-stat.blocked i { background: var(--red); }.status-stat.in_progress i { background: var(--yellow); }.status-stat.completed i { background: var(--green); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.segmented { display: flex; flex-wrap: wrap; gap: 5px; }
.segmented button, .tabs button { border: 0; border-radius: 999px; background: transparent; color: var(--muted); min-height: 38px; padding: 0 13px; font-weight: 760; }
.segmented button.is-active, .tabs button.is-active { background: var(--primary); color: var(--primary-ink); }
.project-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.project-card { appearance: none; width: 100%; min-height: 225px; position: relative; overflow: hidden; display: flex; flex-direction: column; text-align: left; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; color: var(--ink); box-shadow: 0 8px 26px rgba(24,32,28,.04); transition: transform .18s ease, box-shadow .18s ease; }
.project-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.project-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: var(--status-color); }
.project-card.status-blocked { --status-color: var(--red); background: linear-gradient(145deg, var(--red-soft), var(--surface)); }
.project-card.status-in_progress { --status-color: var(--yellow); background: linear-gradient(145deg, var(--yellow-soft), var(--surface)); }
.project-card.status-completed { --status-color: var(--green); background: linear-gradient(145deg, var(--green-soft), var(--surface)); }
.status-badge { display: inline-flex; align-items: center; gap: 7px; align-self: flex-start; padding: 6px 9px; border-radius: 999px; font-size: .7rem; font-weight: 850; text-transform: uppercase; letter-spacing: .05em; background: rgba(255,255,255,.58); }
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--status-color); }
.project-card h2 { margin: 18px 0 8px; font-size: 1.25rem; }
.project-card p { color: var(--muted); font-size: .85rem; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-card .block-reason { color: var(--red); font-weight: 700; }
.project-card-meta { margin-top: auto; display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: .75rem; }
.empty-state { grid-column: 1 / -1; min-height: 280px; display: grid; place-items: center; text-align: center; border: 1px dashed #aab4ad; border-radius: var(--radius); color: var(--muted); padding: 30px; }
.empty-state strong { display: block; color: var(--ink); margin-bottom: 7px; }

.back-button { border: 0; background: transparent; color: var(--muted); padding: 5px 0; margin-bottom: 20px; font-weight: 750; }
.project-header { border-radius: 24px; padding: 22px; margin-bottom: 14px; border: 1px solid var(--line); }
.project-header.status-blocked { background: var(--red-soft); --status-color: var(--red); }.project-header.status-in_progress { background: var(--yellow-soft); --status-color: var(--yellow); }.project-header.status-completed { background: var(--green-soft); --status-color: var(--green); }
.project-title-row { display: flex; justify-content: space-between; gap: 18px; align-items: start; }
.project-title-row h1 { font-size: clamp(1.8rem, 5vw, 3rem); }
.project-description { color: var(--muted); max-width: 740px; line-height: 1.5; }
.status-editor { display: grid; grid-template-columns: 180px minmax(180px, 1fr) auto; gap: 8px; align-items: end; margin-top: 18px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 5px 0 12px; margin-bottom: 10px; }
.project-panel { min-height: 360px; }
.section-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 16px; align-items: start; }
.surface { background: rgba(255,253,247,.83); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.surface-heading { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 14px; }
.surface-heading h2 { margin: 0; }
.metric-list { display: grid; gap: 8px; }
.metric-row { display: flex; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.metric-row:last-child { border-bottom: 0; }.metric-row span { color: var(--muted); }.metric-row strong { text-align: right; }
.quick-next { border-left: 4px solid var(--yellow); padding: 12px 14px; background: var(--yellow-soft); border-radius: 6px 14px 14px 6px; }
.quick-next.blocked-next { margin-top: 10px; border-left-color: var(--red); background: var(--red-soft); }
.list-stack { display: grid; gap: 9px; }
.note-card { border: 1px solid var(--line); background: var(--surface); border-radius: 15px; padding: 15px; }
.note-card.is-pinned { border-color: #b08b28; }
.note-top, .list-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.note-category { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 850; }
.note-content { white-space: pre-wrap; line-height: 1.5; margin: 8px 0 10px; }
.note-date { color: var(--muted); font-size: .72rem; }
.delete-button { width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; flex: 0 0 auto; }
.delete-button:hover { background: var(--red-soft); color: var(--red); }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.task-row, .purchase-row { display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.task-row:last-child, .purchase-row:last-child { border-bottom: 0; }
.check-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--muted); }
.check-button.is-done { background: var(--green); border-color: var(--green); color: white; }
.is-done-text { color: var(--muted); text-decoration: line-through; }
.purchase-form { display: grid; grid-template-columns: 2fr .7fr .7fr 1fr 1fr 1.2fr auto; gap: 8px; align-items: end; margin-bottom: 14px; }
.purchase-meta { color: var(--muted); font-size: .76rem; margin-top: 3px; }
.purchase-price { font-weight: 850; white-space: nowrap; }
.shopping-list { display: grid; gap: 12px; }
.shopping-group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.shopping-group h2 { margin-bottom: 14px; }
.upload-help { color: var(--muted); font-size: .76rem; line-height: 1.45; margin: 0; }
.attachment-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.attachment-grid .empty-state { grid-column: 1 / -1; }
.attachment-card { min-width: 0; display: grid; grid-template-rows: 150px auto auto; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 17px; }
.attachment-preview { width: 100%; height: 150px; display: block; object-fit: cover; background: var(--surface-strong); }
.attachment-icon { height: 150px; display: grid; place-items: center; background: var(--surface-strong); color: var(--muted); font-size: 1.2rem; font-weight: 900; letter-spacing: .08em; }
.attachment-copy { min-width: 0; padding: 13px 13px 8px; }
.attachment-copy strong, .attachment-copy span { display: block; }
.attachment-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-copy span { color: var(--muted); font-size: .72rem; margin-top: 4px; }
.attachment-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 9px 9px 13px; }
.attachment-download { min-height: 34px; display: inline-flex; align-items: center; text-decoration: none; font-size: .75rem; }
.assistant-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); gap: 16px; align-items: start; }
.assistant-history { min-height: 360px; display: grid; gap: 10px; align-content: start; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,253,247,.5); }
.assistant-empty { min-height: 300px; display: grid; place-content: center; gap: 6px; text-align: center; color: var(--muted); }
.assistant-empty strong { color: var(--ink); }
.assistant-message { max-width: 88%; border-radius: 16px; padding: 12px 14px; }
.assistant-message > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .68rem; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.assistant-message p { margin: 0; line-height: 1.5; white-space: pre-wrap; }
.assistant-message.user { justify-self: end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 5px; }
.assistant-message.user > span { color: inherit; opacity: .7; }
.assistant-message.assistant { justify-self: start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.assistant-composer { position: sticky; top: 86px; }
.assistant-composer h2 { margin: 0; }
.ai-setup-copy { margin: 0; color: var(--muted); line-height: 1.55; }
.ai-status { margin: 0; color: var(--green); font-size: .78rem; font-weight: 750; }
.ai-status.is-offline { color: var(--red); }
.assistant-error { min-height: 0; }
.assistant-error:empty { display: none; }
.ai-billing-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.dialog { width: min(92vw, 560px); border: 1px solid var(--line); border-radius: 24px; background: var(--surface); color: var(--ink); padding: 0; box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10,16,13,.55); backdrop-filter: blur(4px); }
.dialog-body { padding: 22px; display: grid; gap: 15px; }
.dialog-heading { display: flex; justify-content: space-between; gap: 14px; align-items: start; }.dialog-heading .eyebrow { margin-top: 0; }.dialog-heading h2 { margin: 0; }
.dialog-copy, .password-help { margin: 0; color: var(--muted); line-height: 1.5; }
.dialog-copy { font-size: .88rem; }
.password-help { font-size: .76rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; z-index: 30; background: var(--primary); color: white; padding: 10px 15px; border-radius: 999px; font-weight: 760; transition: .22s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.mobile-nav { display: none; }

@media (max-width: 880px) {
  .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-grid { grid-template-columns: 1fr; }
  .purchase-form { grid-template-columns: repeat(3, 1fr); }
  .purchase-form .purchase-name { grid-column: 1 / -1; }
  .purchase-form .button { grid-column: 1 / -1; }
  .assistant-layout { grid-template-columns: 1fr; }
  .assistant-composer { position: static; }
}

@media (max-width: 620px) {
  body { background: var(--bg); }
  .app-shell { padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
  .topbar { height: 62px; padding: 0 14px; }
  .topbar-actions { gap: 4px; }
  .topbar-actions .button { min-height: 38px; padding: 0 9px; font-size: .75rem; }
  .desktop-label { display: none; }
  .mobile-label { display: inline; }
  .main-content { width: min(100% - 24px, 1180px); padding: 25px 0 30px; }
  .page-heading { align-items: start; }.page-heading > .button { display: none; }
  .status-summary { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .status-stat { display: block; padding: 11px; }.status-stat i { margin-bottom: 8px; }.status-stat strong { font-size: 1.15rem; }.status-stat span { font-size: .68rem; }
  .toolbar { display: block; }.toolbar > .button { display: none; }
  .segmented { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .segmented button { white-space: nowrap; }
  .project-grid { grid-template-columns: 1fr; }
  .project-card { min-height: 195px; }
  .project-title-row { display: block; }.project-title-row .status-badge { margin-bottom: 14px; }
  .status-editor { grid-template-columns: 1fr; }
  .tabs { margin-left: -4px; margin-right: -4px; }
  .tabs button { white-space: nowrap; }
  .surface { padding: 15px; }
  .inline-form { grid-template-columns: 1fr; }
  .purchase-form { grid-template-columns: 1fr 1fr; }.purchase-form .purchase-name, .purchase-form .button { grid-column: 1 / -1; }
  .purchase-row { grid-template-columns: auto 1fr auto; }
  .attachment-grid { grid-template-columns: 1fr; }
  .attachment-card { grid-template-rows: 190px auto auto; }
  .attachment-preview, .attachment-icon { height: 190px; }
  .assistant-history { min-height: 300px; padding: 12px; }
  .assistant-message { max-width: 94%; }
  .mobile-nav { display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; inset: auto 0 0; z-index: 20; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255,253,247,.94); backdrop-filter: blur(18px); }
  .mobile-nav button { min-height: 54px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); font-size: .68rem; font-weight: 780; }
  .mobile-nav button span { display: block; font-size: 1.2rem; margin-bottom: 2px; }
  .mobile-nav button.is-active { background: var(--primary); color: white; }
  .dialog { width: min(calc(100vw - 20px), 560px); border-radius: 20px; }
  .dialog-body { padding: 18px; }
  .dialog-actions .button { flex: 1; white-space: nowrap; }
}

@media (max-width: 370px) {
  .brand-button > span:last-child { display: none; }
}

@media (prefers-color-scheme: dark) {
  :root { color-scheme: dark; --bg:#0c1210; --surface:#121b17; --surface-strong:#17221d; --ink:#f3f7f4; --muted:#97a69e; --line:#2c3932; --primary:#e9f4ed; --primary-ink:#101814; --green-soft:#142d20; --yellow-soft:#322a12; --red-soft:#321a1b; --shadow:0 18px 55px rgba(0,0,0,.28); }
  body { background: radial-gradient(circle at 90% -10%, rgba(122,166,48,.18), transparent 28rem), var(--bg); }
  .topbar { background: rgba(12,18,16,.82); }.login-card { background: rgba(18,27,23,.95); }
  .status-badge { background: rgba(0,0,0,.22); }
  .mobile-nav { background: rgba(18,27,23,.96); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
