:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --ink: #1f1d1a;
  --muted: #6f6a63;
  --line: #e4dfd8;
  --accent: #6b2140;
  --accent-ink: #ffffff;
  --accent-soft: #f4e8ed;
  --danger: #b42318;
  --ok-bg: #e7f4ec; --ok-ink: #1d6b3a;
  --err-bg: #fdecea; --err-ink: #9b1c1c;
  --k-item: #2f6fb3;
  --k-event: #8a4dbf;
  --k-maintenance: #c26a12;
  --k-note: #3d8b5f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 6px rgba(0,0,0,.04);
}
/* Dark theme: used when chosen with the Light/Dark button, or when no choice was made
   and the computer itself is set to dark. */
:root[data-theme="dark"] {
  --bg: #171513; --surface: #211e1b; --ink: #ece7e1; --muted: #a39c93; --line: #37322d;
  --accent: #c25b86; --accent-ink: #1a0d13; --accent-soft: #3a2230;
  --ok-bg: #173323; --ok-ink: #8fd6a9; --err-bg: #3a1a17; --err-ink: #f2a59c;
  --k-item: #6aa5e6; --k-event: #b78be0; --k-maintenance: #e39a4c; --k-note: #74c194;
  --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171513; --surface: #211e1b; --ink: #ece7e1; --muted: #a39c93; --line: #37322d;
    --accent: #c25b86; --accent-ink: #1a0d13; --accent-soft: #3a2230;
    --ok-bg: #173323; --ok-ink: #8fd6a9; --err-bg: #3a1a17; --err-ink: #f2a59c;
    --k-item: #6aa5e6; --k-event: #b78be0; --k-maintenance: #e39a4c; --k-note: #74c194;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="light"] { color-scheme: light; }

.theme-toggle { white-space: nowrap; padding: 8px 12px; }
.theme-toggle .ico { font-size: 1.05em; line-height: 1; }

* { 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;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.muted { color: var(--muted); font-size: .88rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 32px; min-height: 70vh; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark { background: var(--accent); color: var(--accent-ink); border-radius: 7px; padding: 3px 6px; font-size: .8rem; letter-spacing: .5px; }
.store-tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.store-tabs a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 500; }
.store-tabs a:hover { background: var(--bg); color: var(--ink); }
.store-tabs a.active { background: var(--accent-soft); color: var(--accent); }
.here { color: var(--k-note); font-size: .7em; vertical-align: middle; }

.new-menu { position: relative; }
.new-menu summary { list-style: none; }
.new-menu summary::-webkit-details-marker { display: none; }
.new-menu-list { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px; padding: 6px; }
.new-menu-list a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 7px; text-decoration: none; color: var(--ink); }
.new-menu-list a:hover { background: var(--bg); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.1); border-color: var(--accent); }
.btn-danger { color: var(--danger); }
.linkbtn { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; text-decoration: underline; }

/* Kind colors */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; margin-right: 6px; }
.dot-lg { width: 14px; height: 14px; margin-right: 10px; vertical-align: middle; }
.dot.kind-item, .tag.kind-item { background: var(--k-item); }
.dot.kind-event, .tag.kind-event { background: var(--k-event); }
.dot.kind-maintenance, .tag.kind-maintenance { background: var(--k-maintenance); }
.dot.kind-note, .tag.kind-note { background: var(--k-note); }
.kind-border-item { border-left: 4px solid var(--k-item) !important; }
.kind-border-event { border-left: 4px solid var(--k-event) !important; }
.kind-border-maintenance { border-left: 4px solid var(--k-maintenance) !important; }
.kind-border-note { border-left: 4px solid var(--k-note) !important; }

.tag { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: #fff; padding: 2px 8px; border-radius: 99px; }
.tag-store { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.tag-urgent { background: var(--danger); }
.status { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.status.closed { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

/* Board */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.search input { width: 260px; max-width: 100%; }
.grid-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.store-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.store-card:hover { border-color: var(--accent); }
.store-card ul { list-style: none; margin: 0; padding: 0; }
.store-card li { display: flex; align-items: center; padding: 3px 0; font-size: .92rem; }
.store-card li b { margin-left: auto; font-variant-numeric: tabular-nums; }
.store-card li.zero { color: var(--muted); }
.store-card li.zero b { font-weight: 400; }

.quick-add { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 20px; }
.quick { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font-weight: 600;
  color: var(--ink); text-decoration: none; display: flex; align-items: center; box-shadow: var(--shadow); }
.quick::before { content: "+"; margin-right: 8px; color: var(--muted); }
.quick .dot { display: none; }
.quick:hover { background: var(--accent-soft); }

.filters { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); text-decoration: none; font-size: .9rem; }
.chip b { margin-left: 6px; font-size: .8rem; background: var(--bg); padding: 0 7px; border-radius: 99px; }
.chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: 6px 14px; text-decoration: none; color: var(--muted); font-size: .9rem; }
.seg a + a { border-left: 1px solid var(--line); }
.seg a.active { background: var(--accent); color: var(--accent-ink); }

.entries { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.entry-row { display: flex; gap: 16px; justify-content: space-between; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.entry-row:hover { border-color: var(--muted); }
.entry-main { min-width: 0; }
.entry-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.entry-title { font-weight: 600; font-size: 1.05rem; overflow-wrap: anywhere; }
.entry-sub { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.entry-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty h1 { color: var(--ink); margin-bottom: 8px; }

/* Cards / forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form .row.two { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; }
.form label.full, .form .actions { grid-column: 1 / -1; }
.form small { font-weight: 400; color: var(--muted); }
.req { color: var(--danger); }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
textarea { resize: vertical; }
.actions { display: flex; justify-content: flex-end; gap: 10px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }

/* Detail */
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; font-weight: 500; }
.detail h1 { margin: 8px 0 4px; overflow-wrap: anywhere; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 24px; margin: 20px 0; }
.fields div.full { grid-column: 1 / -1; }
.fields dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
.fields dd { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.detail-actions { display: flex; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.detail-actions form { margin: 0; }

.activity { list-style: none; padding: 0; margin: 0 0 18px; }
.activity li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.activity li.system { font-size: .88rem; color: var(--muted); padding: 6px 0; }
.activity li.system b { color: var(--ink); font-weight: 600; }
.c-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.update-form { margin-top: 6px; }

/* Footer */
.footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 16px; padding-bottom: 32px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; flex-wrap: wrap; }
.footer form { margin: 0; }
.device-form select { width: auto; padding: 5px 8px; margin-left: 6px; }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login .brand { font-size: 1.2rem; }
.login label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; }
.login p { margin: 0; }

@media (max-width: 640px) {
  h1 { font-size: 1.35rem; }
  .topbar-inner { gap: 8px 12px; }
  .store-tabs { order: 3; flex-basis: 100%; }
  .theme-toggle { margin-left: auto; }
  .search, .search input { width: 100%; }
  .form, .form .row.two { grid-template-columns: 1fr; }
  .entry-row { flex-direction: column; gap: 8px; }
  .entry-meta { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; text-align: left; }
  .seg { width: 100%; }
  .seg a { flex: 1; text-align: center; }
}
