:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --border: #e7e4de;
  --text: #23211d;
  --text-dim: #726d63;
  --accent: #3f7a6a;
  --accent-dim: #e7f0ec;
  --warn: #b5541c;
  --warn-dim: #fbeee3;
  --danger: #a3372f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(35,33,29,0.04), 0 4px 16px rgba(35,33,29,0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171815;
    --surface: #211f1b;
    --border: #322f29;
    --text: #ede9e2;
    --text-dim: #a29c8e;
    --accent: #6fb39c;
    --accent-dim: #223530;
    --warn: #e08a4f;
    --warn-dim: #3a2a1c;
    --danger: #e07068;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 18px 80px;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
}

.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.login-card .sub {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 0 0 22px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { opacity: 0.92; }

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  padding: 6px 0;
}

.form-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 10px;
  min-height: 1em;
}

.toggle-row {
  text-align: center;
  margin-top: 14px;
}

/* ---------- Header ---------- */

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 22px;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: -0.01em;
}

.topbar .who {
  color: var(--text-dim);
  font-size: 0.82rem;
}

.topbar .who button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  padding: 0;
  margin-left: 8px;
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 4px;
  margin-bottom: 18px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--text-dim);
  font-weight: 500;
}

.tab-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.tab-btn .count {
  display: inline-block;
  margin-left: 5px;
  font-size: 0.75rem;
  opacity: 0.85;
}

/* ---------- Item cards ---------- */

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 22px 0 10px;
}

.section-header h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 0;
  font-weight: 600;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.item-card.low {
  border-color: var(--warn);
  background: var(--warn-dim);
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.item-name {
  font-weight: 600;
  font-size: 0.97rem;
}

.item-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-top: 2px;
}

.pill {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  white-space: nowrap;
}

.pill.low { background: var(--warn); color: #fff; }

.bar-track {
  height: 6px;
  border-radius: 4px;
  background: var(--border);
  margin: 10px 0 12px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.bar-fill.low { background: var(--warn); }

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.item-actions .btn {
  padding: 6px 11px;
  font-size: 0.8rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.empty-state {
  color: var(--text-dim);
  font-size: 0.88rem;
  text-align: center;
  padding: 30px 10px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Floating add button + modal ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 1.6rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20,18,14,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
}

.modal {
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 22px 20px 28px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
}

@media (min-width: 640px) {
  .modal { border-radius: 16px; }
}

.modal h2 {
  font-size: 1.05rem;
  margin: 0 0 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions .btn { flex: 1; }

.starter-note {
  font-size: 0.82rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  margin-top: 18px;
  padding-top: 14px;
}

.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.checkbox-inline input { width: 17px; height: 17px; }
.checkbox-inline label { font-size: 0.85rem; color: var(--text); margin: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 40;
  box-shadow: var(--shadow);
}
