:root {
  --green: #2f9e5c;
  --green-bg: #e7f7ee;
  --orange: #e08a1e;
  --orange-bg: #fdf1de;
  --red: #d9432f;
  --red-bg: #fbe6e3;
  --ink: #1f2a24;
  --muted: #6b7570;
  --border: #e2e6e3;
  --bg: #f7f8f6;
  --card: #ffffff;
  --accent: #2f6f4f;
  --accent-dark: #245239;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef2ef;
    --muted: #9aa39d;
    --border: #2c332e;
    --bg: #141815;
    --card: #1b201c;
    --green-bg: #103322;
    --orange-bg: #3a2a11;
    --red-bg: #3a1712;
    --accent: #4caf7d;
    --accent-dark: #6fc79a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.hidden { display: none !important; }

.view { min-height: 100vh; }

/* Login */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; }

.muted { color: var(--muted); margin: 0 0 20px; font-size: 0.9rem; }

.login-card input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1.1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.15em;
  margin-bottom: 14px;
}

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

.login-card button[type="submit"] {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
}

.error { color: var(--red); font-size: 0.85rem; margin: 12px 0 0; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 { font-size: 1.15rem; margin: 0; }

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: underline;
  padding: 4px;
}

#main-content {
  padding: 16px 16px 90px;
  max-width: 720px;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  flex: 1;
  padding: 14px 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  border-top: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent);
  border-top-color: var(--accent);
}

/* Dashboard */
.sort-bar {
  display: flex;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}

.sort-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 7px;
}

.sort-btn.active {
  background: var(--accent);
  color: white;
}

.location-group { margin-bottom: 22px; }

.location-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 8px 2px;
}

.item-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.green { background: var(--green); }
.status-dot.orange { background: var(--orange); }
.status-dot.red { background: var(--red); }

.item-info { flex: 1; min-width: 0; }

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

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

.wash-btn {
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--accent);
  color: white;
  white-space: nowrap;
}

.wash-btn:active { background: var(--accent-dark); }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge.green { background: var(--green-bg); color: var(--green); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.red { background: var(--red-bg); color: var(--red); }

/* Log */
.log-entry {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.log-entry .what { font-weight: 600; }
.log-entry .where { color: var(--muted); font-size: 0.8rem; }
.log-entry .when { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

/* Manage */
.manage-section { margin-bottom: 24px; }

.manage-location {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.manage-location-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.manage-location-header input {
  font-weight: 700;
  font-size: 1rem;
  border: none;
  background: none;
  color: var(--ink);
  width: 100%;
}

.manage-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}

.manage-item-row input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.85rem;
}

.manage-item-row input[type="number"] {
  width: 56px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 4px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.85rem;
  text-align: center;
}

.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  padding: 4px 8px;
}

.icon-btn.danger { color: var(--red); }

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.add-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--ink);
  font-size: 0.85rem;
}

.small-btn {
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.ghost-btn {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 10px;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  width: 100%;
  margin-top: 4px;
}

.empty-state { color: var(--muted); text-align: center; padding: 40px 0; font-size: 0.9rem; }

.toast {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 20;
  transition: opacity 0.2s;
}
