:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #2b2520;
  --muted: #7a6f64;
  --accent: #b35c2c;
  --accent-2: #d6884c;
  --good: #3b8f4d;
  --warn: #c8821b;
  --bad: #c63c3c;
  --line: #e3dccf;
  --shadow: 0 2px 6px rgba(0,0,0,.08);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 6px;
  transition: background .12s, transform .05s;
}
button:hover { background: #f9f4ec; }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.brand { font-weight: 700; font-size: 18px; }
.stats { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
.stat { color: var(--muted); }
.stat b { color: var(--ink); }
.actions { display: flex; gap: 6px; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 16px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab.active {
  color: var(--ink);
  background: var(--bg);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  padding: 18px;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.col { flex: 1 1 320px; min-width: 280px; }
h2 { margin: 0 0 12px; font-size: 18px; }
h3 { margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  background: #ede7da;
  color: var(--muted);
  font-size: 12px;
}
.tag.good { background: #e2f1e3; color: var(--good); }
.tag.warn { background: #fbeed3; color: var(--warn); }
.tag.bad { background: #f7dcdc; color: var(--bad); }

/* Build mode */
.build-wrap { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.palette { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow-y: auto; }
.palette .item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  background: var(--panel);
}
.palette .item.active { border-color: var(--accent); background: #fff6ee; }
.palette .item .icon { font-size: 18px; width: 24px; text-align: center; }
.palette .item .meta { flex: 1; font-size: 12px; }
.palette .item .price { color: var(--muted); font-size: 11px; }
.palette .group-title {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 8px 0 2px;
  padding-left: 4px;
}

.grid {
  display: grid;
  gap: 1px;
  background: #d6cfc1;
  padding: 1px;
  border-radius: 8px;
  user-select: none;
  width: fit-content;
}
.cell {
  width: 38px;
  height: 38px;
  background: #f0e9da;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  position: relative;
}
.cell:hover { outline: 2px solid var(--accent-2); z-index: 1; }
.cell .lvl {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 9px;
  background: var(--accent);
  color: white;
  padding: 0 3px;
  border-radius: 3px;
  line-height: 1.4;
}
.cell.dirty::after {
  content: '';
  position: absolute;
  top: 2px; right: 2px;
  width: 6px; height: 6px;
  background: #8b6240;
  border-radius: 50%;
}
.cell.t-wall { background: #8b7d65; }
.cell.t-door { background: #c8a578; }
.cell.t-table2, .cell.t-table4, .cell.t-table6 { background: #d8c4a4; }
.cell.t-stove, .cell.t-oven { background: #6f5b48; color: #fff; }
.cell.t-prep { background: #a89876; color: #fff; }
.cell.t-fridge { background: #c5d4d8; }
.cell.t-dishwasher { background: #b9c7d4; }
.cell.t-sink { background: #d4dde0; }
.cell.t-counter { background: #b58c64; }
.cell.t-restroom { background: #b8c8b9; }
.cell.t-computer { background: #2b2520; color: #fff; }
.cell.t-register { background: #c0a874; }
.cell.t-plant { background: #cfe1bd; }
.cell.t-painting { background: #e3d0d0; }
.cell.t-lamp { background: #f5e8c2; }
.cell.t-trashcan { background: #6e7a82; color: #fff; }
.cell.t-barstool { background: #c2a47a; }

/* Hint zone */
.required-list { display: flex; gap: 8px; flex-wrap: wrap; }
.required-list .req { font-size: 12px; padding: 4px 8px; border-radius: 4px; background: #f7dcdc; color: var(--bad); }
.required-list .req.ok { background: #e2f1e3; color: var(--good); }

/* Catalog cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card .title { font-weight: 600; }
.card .price { color: var(--accent); font-weight: 600; }
.card .desc { color: var(--muted); font-size: 12px; }
.card .row-end { display: flex; align-items: center; gap: 6px; margin-top: auto; }
.card input[type=number] { width: 64px; }

/* Email list */
.email-list { display: flex; flex-direction: column; gap: 4px; }
.email {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
}
.email.unread { background: #fff6ee; font-weight: 600; }
.email .from { font-size: 12px; color: var(--muted); }
.email .subj { font-size: 13px; }
.email .day { font-size: 11px; color: var(--muted); }
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
}
.email:not(.unread) .dot { background: transparent; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.kpi {
  padding: 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}
.kpi .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.kpi .val { font-size: 22px; font-weight: 700; }
.kpi.good .val { color: var(--good); }
.kpi.bad .val { color: var(--bad); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: white;
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 80%;
  text-align: center;
}
.toast.hidden { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.day-log {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  max-height: 360px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.5;
}
.day-log .log-row { white-space: pre-wrap; }
.day-log .log-good { color: var(--good); }
.day-log .log-bad { color: var(--bad); }
.day-log .log-money { color: var(--accent); }

.bar { background: #efe7d6; border-radius: 4px; height: 8px; overflow: hidden; }
.bar > div { background: var(--accent); height: 100%; transition: width .3s; }

.hint {
  background: #fff8eb;
  border: 1px solid #f0d99c;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #6c4a16;
}
.error { color: var(--bad); }
.flex { display: flex; gap: 8px; align-items: center; }
.gap { gap: 12px; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.checkbox { display: flex; align-items: center; gap: 6px; }
