:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232733;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --green: #34c759;
  --amber: #ff9f0a;
  --red: #ff453a;
  --radius: 12px;
}
* { box-sizing: border-box; }
/* Ensure the HTML `hidden` attribute always wins over display rules below
   (e.g. .modal/.card set display, which would otherwise reveal hidden nodes). */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; position: sticky; top: 0; background: var(--bg); z-index: 5;
  border-bottom: 1px solid var(--surface-2);
}
header h1 { font-size: 1.2rem; margin: 0; }
nav#tabs {
  display: flex; gap: 4px; padding: 8px; overflow-x: auto;
  position: sticky; top: 56px; background: var(--bg); z-index: 4;
}
nav#tabs button {
  flex: 1 0 auto; padding: 8px 12px; border: none; border-radius: 999px;
  background: var(--surface); color: var(--muted); font-size: .9rem; cursor: pointer;
}
nav#tabs button.active { background: var(--accent); color: white; }
main { padding: 12px 16px 40px; max-width: 720px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px;
}
.row { display: flex; gap: 8px; margin-bottom: 12px; }
.row > * { flex: 1; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
input, select, textarea, button {
  font: inherit; padding: 11px; border-radius: 10px; border: 1px solid var(--surface-2);
  background: var(--surface-2); color: var(--text); width: 100%;
}
textarea { resize: vertical; }
button {
  background: var(--accent); color: white; border: none; cursor: pointer; font-weight: 600;
}
button.ghost { background: transparent; color: var(--text); width: auto; padding: 6px 10px; }
button.secondary { background: var(--surface-2); color: var(--text); }
button.danger { background: var(--red); }
button.small { width: auto; padding: 8px 12px; font-size: .85rem; }

.seg { display: flex; gap: 4px; margin-bottom: 12px; background: var(--surface); border-radius: 999px; padding: 4px; }
.seg button { background: transparent; color: var(--muted); border-radius: 999px; }
.seg button.active { background: var(--accent); color: white; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer;
}
.item:active { background: var(--surface-2); }
.item .meta { min-width: 0; }
.item .name { font-weight: 600; }
.item .sub { color: var(--muted); font-size: .8rem; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: .7rem; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.available { background: rgba(52,199,89,.18); color: var(--green); }
.badge.borrowed { background: rgba(255,159,10,.18); color: var(--amber); }
.badge.used, .badge.consumed { background: rgba(154,163,178,.18); color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: flex-end; justify-content: center; z-index: 20;
}
.modal-body {
  background: var(--surface); width: 100%; max-width: 720px; border-radius: 16px 16px 0 0;
  padding: 20px 18px 30px; max-height: 88vh; overflow-y: auto;
}
.modal-body h2 { margin: 0 0 4px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.kv { color: var(--muted); font-size: .9rem; margin: 4px 0; }
.kv b { color: var(--text); font-weight: 600; }

/* Login screen */
.login {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 16px;
  padding: 28px 22px; text-align: center; gap: 14px;
}
.login-logo { font-size: 2.4rem; }
.login-card h2 { margin: 0; }
.login-card p { color: var(--muted); font-size: .9rem; margin: 0 0 6px; }
.login-error { color: var(--red); font-size: .85rem; min-height: 1em; }

/* Sub-headings and quick-add forms inside detail modals */
.modal-body h3 { margin: 18px 0 8px; font-size: .95rem; color: var(--muted); }
.quick-add {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px;
  background: var(--surface-2); padding: 10px; border-radius: 10px;
}
.quick-add input { flex: 1 1 120px; width: auto; background: var(--surface); }
.quick-add button { flex: 0 0 auto; width: auto; padding: 10px 14px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); padding: 12px 18px; border-radius: 10px;
  opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 30; max-width: 90%;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); color: white; }
.add-form button { margin-top: 4px; }
