/* The Work Barn — mobile-first styles */
:root {
  --brand: #8e2f26;
  --brand-2: #a8392e;
  --accent: #f2b134;
  --bg: #f7f4ef;
  --card: #fff;
  --ink: #1d2523;
  --muted: #66716e;
  --line: #dde3e1;
  --good: #2f8f5b;
  --bad: #c0392b;
  --warn: #b8730a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121716; --card: #1b2220; --ink: #e6ecea; --muted: #97a3a0; --line: #2c3633;
    --brand-2: #e0897d; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
a { color: var(--brand-2); }
h1 { font-size: 1.5rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: .4rem 0; }
code { background: var(--line); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 2rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---- Top bar & navigation ---- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem;
  background: var(--brand); color: #fff; padding: .55rem 1rem; padding-top: calc(.55rem + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; margin-right: auto; }
.brand img { border-radius: 7px; background: #fff; }
.mainnav, .topbar .new-btn { display: none; }
.only-desktop { display: none !important; }
.mainnav a { color: #f3d9d4; text-decoration: none; padding: .4rem .7rem; border-radius: 8px; }
.mainnav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.mainnav a[aria-current] { background: rgba(255,255,255,.16); color: #fff; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu .menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: .4rem; display: flex; flex-direction: column;
}
.usermenu .menu a, .usermenu .menu button { display: block; text-align: left; padding: .55rem .7rem; border-radius: 8px; color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--bg); }
.usermenu .who { padding: .5rem .7rem; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted); text-decoration: none; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current] { color: var(--brand-2); font-weight: 600; }
.tabbar .tab-new span { display: grid; place-items: center; width: 40px; height: 40px; margin-top: -14px; border-radius: 50%; background: var(--accent); color: #2b2100; font-size: 1.7rem; line-height: 1; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

@media (min-width: 900px) {
  body { padding-bottom: 2rem; }
  .tabbar, .only-mobile { display: none; }
  .mainnav { display: flex; gap: .15rem; margin-right: auto; }
  .brand { margin-right: 1rem; }
  .topbar .new-btn { display: inline-flex; }
  .only-desktop { display: inline-flex !important; }
}

/* ---- Page ---- */
.page { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: .25rem 0 1rem; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.narrow { max-width: 640px; }
.empty { color: var(--muted); padding: 1rem; text-align: center; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.flash { background: #e3f4ea; color: #17542f; border: 1px solid #b9e2c8; padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; transition: opacity .6s; }
.flash.err { background: #fde8e6; color: #8a1f14; border-color: #f4c3bd; }
.flash.hide { opacity: 0; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .45rem .85rem; border-radius: 999px; text-decoration: none; color: var(--muted); background: var(--card); border: 1px solid var(--line); white-space: nowrap; }
.tabs a[aria-current] { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- Buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 40px; padding: .45rem 1rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.topbar .btn.primary { background: var(--accent); border-color: var(--accent); color: #2b2100; }
.btn.small { min-height: 32px; padding: .25rem .7rem; font-size: .88rem; }
.btn.busy, label.busy { opacity: .6; pointer-events: none; }
.link { background: none; border: 0; padding: 0; color: var(--brand-2); font: inherit; cursor: pointer; text-decoration: underline; }
.link.danger, .danger { color: var(--bad); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; padding: .3rem .45rem; border-radius: 6px; }
.icon-btn:hover { background: var(--bg); color: var(--bad); }
form.inline { display: inline; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .55rem .7rem; min-height: 42px; width: 100%;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input[type=color] { padding: 2px; width: 46px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; }
label { display: block; font-weight: 500; font-size: .92rem; }
label > input, label > select, label > textarea { margin-top: .3rem; font-weight: 400; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 500; font-size: .92rem; margin-bottom: .3rem; }
.field-err { color: var(--bad); margin: .25rem 0 0; font-size: .85rem; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.check-label { display: inline-flex; align-items: center; gap: .35rem; font-weight: 400; white-space: nowrap; }

.task-form { display: grid; gap: 1rem; grid-template-columns: 1fr; max-width: 820px; }
.task-form .full { grid-column: 1 / -1; }
@media (min-width: 640px) { .task-form { grid-template-columns: 1fr 1fr; } }
.actions { display: flex; gap: .6rem; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: .55rem .2rem; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 500; }
.seg input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.seg .p1 input:checked + span { background: var(--bad); border-color: var(--bad); }
.seg .p2 input:checked + span { background: var(--warn); border-color: var(--warn); }
.seg input:focus-visible + span { outline: 2px solid var(--brand-2); }

.filters { display: grid; gap: .5rem; grid-template-columns: 1fr 1fr; margin-bottom: .5rem; }
.filters input[type=search] { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters { grid-template-columns: 2fr repeat(6, 1fr); } .filters input[type=search] { grid-column: auto; } }

.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .6rem 0; }
.inline-form input:not([type=checkbox]):not([type=color]), .inline-form select { width: auto; flex: 1 1 160px; }
.inline-form .num { flex: 0 0 80px !important; }
.list-edit .inline-form { padding-bottom: .6rem; border-bottom: 1px solid var(--line); }
.list-edit .inline-form.add { border: 0; }

/* ---- Pills, avatars ---- */
.pill { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.pill.s-idea { background: #fff6e0; color: #8a5d00; border-color: #f3dc9c; }
.pill.s-todo { background: #e6f0fb; color: #1f4f86; border-color: #bcd3ef; }
.pill.s-in_progress { background: #e3f4ea; color: #17542f; border-color: #b9e2c8; }
.pill.s-waiting { background: #f1e8fa; color: #5d2b8c; border-color: #dac5ef; }
.pill.s-done { background: #e3f4ea; color: #17542f; border-color: #b9e2c8; }
.pill.p1 { background: var(--bad); color: #fff; border-color: var(--bad); }
.pill.p2 { background: #fdf0dc; color: var(--warn); border-color: #f2d2a0; }
.pill.p3, .pill.p4 { font-weight: 500; }
@media (prefers-color-scheme: dark) {
  .pill:not(.p1) { background: transparent; }
  .pill.s-idea { color: #f3c969; } .pill.s-todo { color: #8db8ec; } .pill.s-in_progress, .pill.s-done { color: #7fd1a0; }
  .pill.s-waiting, .pill-btn.on { color: #c9a5ef; background: transparent; } .pill.p2 { color: #f0b35a; }
  .flash { background: #173524; color: #bfe8cf; border-color: #24533a; } .flash.err { background: #3d1a16; color: #f6c4bd; border-color: #6b2a22; }
}
.due { font-size: .82rem; color: var(--muted); }
.due.soon { color: var(--warn); font-weight: 600; }
.due.overdue, .overdue { color: var(--bad); font-weight: 700; }
.prop-tag { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.prop-tag::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--pc, #999); }
.avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--c, #777);
  color: #fff; font-size: .78rem; font-weight: 700; letter-spacing: .02em; flex: none; vertical-align: middle;
}
.avatar.sm { width: 24px; height: 24px; font-size: .62rem; }
.avatar.empty { background: transparent; border: 1.5px dashed var(--line); color: var(--muted); }
.topbar .avatar { border: 2px solid rgba(255,255,255,.7); }

/* ---- Task cards ---- */
.cards { display: flex; flex-direction: column; gap: .55rem; }
.task-card { display: flex; gap: .75rem; align-items: flex-start; margin: 0; padding: .75rem; border-left: 5px solid var(--pc, #999); }
.task-card.st-done, .task-card.st-cancelled { opacity: .7; }
.task-card.st-done .task-title { text-decoration: line-through; text-decoration-color: var(--muted); }
.task-main { flex: 1; min-width: 0; }
.task-title { display: block; font-weight: 600; color: var(--ink); text-decoration: none; font-size: 1.02rem; }
.task-title::after { content: ""; }
.task-title:hover { color: var(--brand-2); }
.task-meta { display: flex; flex-wrap: wrap; gap: .3rem .6rem; align-items: center; margin-top: .25rem; font-size: .85rem; }
.task-foot { display: flex; flex-wrap: wrap; gap: .8rem; margin-top: .3rem; }
.cards.compact .task-foot { display: none; }

.vote button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; width: 46px; min-height: 50px; padding: .2rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--muted); cursor: pointer; font: inherit; font-weight: 700; font-size: .9rem;
}
.vote svg { width: 18px; height: 18px; fill: currentColor; }
.vote button:hover { border-color: var(--accent); color: var(--ink); }
.vote.on button { background: var(--accent); border-color: var(--accent); color: #2b2100; }
.vote.on button { animation: pop .25s ease-out; }
@keyframes pop { 50% { transform: scale(1.12); } }

/* ---- Home ---- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1.2rem; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.7rem; line-height: 1.1; color: var(--brand-2); }
.stat.good b { color: var(--good); }
.stat span { color: var(--muted); font-size: .88rem; }
.home-grid { display: grid; gap: 1.2rem; }
@media (min-width: 900px) { .home-grid { grid-template-columns: 1.7fr 1fr; } }
.home-section { margin-bottom: 1.4rem; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; }
.leaders { margin: 0; padding-left: 1.4rem; }
.leaders li { margin: .35rem 0; }
.leaders b { float: right; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border: 0; }
.row-between { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }

/* ---- Task detail ---- */
.task-head { display: flex; gap: .9rem; align-items: flex-start; margin-bottom: .8rem; padding-left: .8rem; border-left: 5px solid var(--pc, #999); }
.task-head h1 { margin-top: .3rem; }
.voters { margin: .4rem 0 0; display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.action-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.detail-grid { display: grid; gap: 0 1rem; }
@media (min-width: 900px) { .detail-grid { grid-template-columns: 1fr 1fr; } .timeline-card { grid-column: 1 / -1; } }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: .88rem; }
.facts dd { margin: 0; }
.description { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); overflow-wrap: anywhere; }

.materials { list-style: none; margin: 0 0 .6rem; padding: 0; }
.material { display: flex; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.material:last-child { border-bottom: 0; }
.mat-body { flex: 1; display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; min-width: 0; overflow-wrap: anywhere; }
.mat-name { font-weight: 500; }
.for-task { flex-basis: 100%; }
.m-have .mat-name { text-decoration: line-through; color: var(--muted); }
.check { width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--brand-2); background: var(--card); color: #fff; cursor: pointer; font-weight: 700; display: grid; place-items: center; }
.m-have .check { background: var(--good); border-color: var(--good); }
.pill-btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .15rem .6rem; font: inherit; font-size: .78rem; color: var(--muted); cursor: pointer; white-space: nowrap; }
.pill-btn.on { background: #f1e8fa; color: #5d2b8c; border-color: #dac5ef; }
.add-material summary { list-style: none; display: inline-flex; }
.add-material summary::-webkit-details-marker { display: none; }
.mat-form { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-top: .6rem; }
.mat-form input[name=name], .mat-form input[name=source] { grid-column: 1 / -1; }
@media (min-width: 640px) { .mat-form { grid-template-columns: 2fr 1fr 1fr 2fr auto; } .mat-form input { grid-column: auto !important; } }
.shop-group { border-left: 5px solid var(--pc, #999); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; margin-bottom: .7rem; }
.photos figure { margin: 0; position: relative; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: var(--bg); }
.photos form { position: absolute; top: 2px; right: 2px; }
.photos .icon-btn { background: rgba(0,0,0,.55); color: #fff; font-size: .75rem; }
.upload label { display: inline-flex; cursor: pointer; }

.timeline { list-style: none; margin: 0 0 1rem; padding: 0; }
.timeline li { padding: .45rem 0; }
.timeline .note { display: flex; gap: .6rem; align-items: flex-start; }
.timeline .note > div { flex: 1; background: var(--bg); border-radius: 10px; padding: .5rem .75rem; }
.note-body { overflow-wrap: anywhere; margin-top: .15rem; }
.timeline .event { display: flex; justify-content: space-between; gap: 1rem; padding-left: 2.1rem; }
.note-form { display: flex; gap: .5rem; align-items: flex-end; }
.danger-zone { text-align: right; margin-top: .5rem; }

/* ---- Properties ---- */
.prop-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.prop-card { text-decoration: none; color: var(--ink); border-top: 6px solid var(--pc); margin: 0; }
.prop-card:hover { border-color: var(--pc); box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.prop-counts { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .9rem; color: var(--muted); }
.prop-counts b { color: var(--ink); }

/* ---- Profile / admin ---- */
.swatches { display: flex; flex-wrap: wrap; gap: .5rem; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 34px; height: 34px; border-radius: 50%; background: var(--c); cursor: pointer; border: 3px solid transparent; }
.swatch input:checked + span { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--card); }
.swatch input:focus-visible + span { outline: 2px solid var(--brand-2); }
.people { display: flex; flex-direction: column; }
.person { border-bottom: 1px solid var(--line); padding: .5rem 0; }
.person summary { display: flex; align-items: center; gap: .7rem; cursor: pointer; list-style: none; }
.person summary::-webkit-details-marker { display: none; }
.person-name { display: flex; flex-direction: column; }
.person.inactive { opacity: .55; }
.invite-box { border: 2px solid var(--accent); }
.copy-row { display: flex; gap: .5rem; }
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { display: flex; gap: .6rem; align-items: center; padding: .4rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }

/* ---- Sign-in pages ---- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: linear-gradient(160deg, #8e2f26, #4a1813); }
.auth-card { background: var(--card); border-radius: 18px; padding: 2rem 1.6rem; max-width: 420px; width: 100%; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-card h1 { margin: .6rem 0 .4rem; }
.sso { display: flex; flex-direction: column; gap: .7rem; margin: 1.4rem 0; }
.sso-btn { min-height: 48px; font-weight: 600; }
