:root {
  --primary: #5d4037;
  --secondary: #efebe9;
  --accent: #d4a373;
  --ink: #3e2c24;
  --ink-light: #6b5347;
  --wood: #8d5f3f;
  --wood-dark: #6f4a30;
  --cream: #f7f2ec;
  --rule: rgba(61,44,33,0.12);
  --shadow: 0 6px 16px rgba(40,25,15,0.28);
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255,255,255,0.06), transparent 60%),
    repeating-linear-gradient(90deg, rgba(40,24,12,0.05) 0 2px, transparent 2px 90px),
    repeating-linear-gradient(0deg, rgba(40,24,12,0.04) 0 3px, transparent 3px 60px),
    linear-gradient(160deg, #9c6a44, #7a5134 45%, #5d4037 100%);
  height: 100%;
  overflow: hidden;
}

.desk {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.tab-view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(20px + env(safe-area-inset-top)) 16px 120px;
}

.panel { display: block; }

.panel-title {
  font-family: Georgia, serif;
  font-weight: normal;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.85rem;
  margin: 26px 0 12px;
  border-bottom: 1px solid rgba(239,235,233,0.25);
  padding-bottom: 8px;
}

/* ---------- TAB BAR ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: linear-gradient(180deg, #7a5a3c, #63432a);
  border-top: 3px solid #b8894f;
  box-shadow: 0 -4px 14px rgba(30,16,8,0.4);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

.tab-btn {
  position: relative;
  appearance: none;
  border: none;
  background: transparent;
  padding: 26px 4px calc(10px + env(safe-area-inset-bottom));
  font-family: Georgia, serif;
  font-size: 0.66rem;
  color: var(--secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tab-btn .tab-label { opacity: 0.75; letter-spacing: 0.02em; }

/* Brass binder clip */
.tab-btn .clip {
  display: block;
  width: 40px;
  height: 22px;
  border-radius: 4px 4px 3px 3px;
  background: linear-gradient(180deg, #c9a25e, #a87e3f 55%, #8a6531);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 2px 3px rgba(30,16,8,0.45);
  position: relative;
}

.tab-btn .clip::before,
.tab-btn .clip::after {
  content: "";
  position: absolute;
  bottom: -7px;
  width: 3px;
  height: 12px;
  background: linear-gradient(180deg, #8a6531, #5f431f);
  border-radius: 0 0 3px 3px;
}
.tab-btn .clip::before { left: 6px; }
.tab-btn .clip::after { right: 6px; }

/* Active clip: angled open, shiny gold, shadow */
.tab-btn.active .clip {
  background: linear-gradient(165deg, #ffe3a0, #f2c468 40%, #d4a373 70%, #b9874a);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.65), 0 6px 10px rgba(20,10,4,0.5);
  transform: rotate(-8deg) translateY(-2px) scale(1.06);
}
.tab-btn.active .clip::before {
  transform: translate(-2px, 2px) rotate(-8deg);
}
.tab-btn.active .clip::after {
  transform: translate(2px, 2px) rotate(8deg);
}
.tab-btn.active .tab-label { opacity: 1; font-weight: bold; }

/* ---------- INDEX CARD ---------- */
.card {
  position: relative;
  background: var(--cream);
  border: 1px solid rgba(80,55,35,0.25);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 12px 14px 14px;
  margin-bottom: 14px;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent 0 24px, var(--rule) 24px 25px);
  pointer-events: none;
  border-radius: 6px;
}

.card-tab {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
}
.card-tab.blue { background: #3f6fb0; }
.card-tab.grey { background: #9a9a93; }

/* Brass paperclip */
.card .paperclip {
  position: absolute;
  top: 14px;
  right: 12px;
  width: 18px;
  height: 42px;
  border: 3px solid #c9a25e;
  border-radius: 9px;
  box-shadow: 0 2px 3px rgba(40,25,15,0.3), inset 0 0 0 1px rgba(255,255,255,0.3);
  background: linear-gradient(135deg, #efd79a, #c9a25e 60%);
  transform: rotate(4deg);
}

.card-name {
  margin: 2px 0 0;
  font-size: 1.12rem;
  font-family: 'Segoe Print', 'Comic Sans MS', 'Brush Script MT', cursive;
  color: var(--ink);
  padding-right: 26px;
  position: relative;
}
.card-sub {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--ink-light);
  position: relative;
  font-family: Georgia, serif;
  font-style: italic;
  word-break: break-word;
}

.card-actions {
  position: relative;
  display: flex;
  gap: 8px;
  margin-top: 12px;
  z-index: 2;
}
.card-actions button {
  appearance: none;
  border: 1px solid rgba(80,55,35,0.3);
  background: #fff;
  color: var(--primary);
  font-family: Georgia, serif;
  font-size: 0.72rem;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(40,25,15,0.2);
}
.card-actions button:active { background: #f0e9e0; }

/* Inline edit fields */
.edit-fields {
  position: relative;
  margin-top: 10px;
  z-index: 2;
}
.edit-fields input {
  width: 100%;
  display: block;
  margin-bottom: 8px;
  font-family: 'Segoe Print', 'Comic Sans MS', cursive;
  font-size: 0.95rem;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px dashed rgba(61,44,33,0.4);
  outline: none;
  padding: 3px 2px;
}
.edit-fields input:focus { border-bottom-color: var(--primary); }

/* ---------- ARCHIVED STAMP ---------- */
.stamp {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-12deg);
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: bold;
  font-size: 1.5rem;
  letter-spacing: 0.18em;
  color: #b3261e;
  border: 3px double #b3261e;
  border-radius: 4px;
  padding: 3px 10px;
  text-transform: uppercase;
  opacity: 0.55;
  pointer-events: none;
  z-index: 3;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
  box-shadow: 0 0 0 1px #b3261e inset;
  mix-blend-mode: multiply;
}

/* ---------- DASHBOARD ---------- */
.dashboard { position: relative; }

.paperclip-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 12px;
}

.clip-counter {
  position: relative;
  width: 82px;
  height: 96px;
}
.clip-metal {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 72px;
  border: 5px solid #c9a25e;
  border-radius: 12px;
  background: linear-gradient(145deg, #efd79a, #a87e3f);
  box-shadow: 0 5px 8px rgba(30,16,8,0.4), inset 0 1px 0 rgba(255,255,255,0.4);
}
.clip-flag {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(-4deg);
  background: #fffdf7;
  width: 44px;
  height: 34px;
  border: 1px solid rgba(80,55,35,0.3);
  border-radius: 3px;
  box-shadow: 0 3px 5px rgba(30,16,8,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.flag-num {
  font-family: 'Segoe Print', 'Comic Sans MS', cursive;
  font-size: 1.3rem;
  font-weight: bold;
  color: var(--ink);
}

.counter-labels {
  display: flex;
  justify-content: space-around;
  color: var(--secondary);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 2px;
}
.counter-labels span { width: 82px; text-align: center; }

.recent-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}
.mini-card {
  flex: 0 0 44%;
  background: var(--cream);
  border: 1px solid rgba(80,55,35,0.25);
  border-radius: 5px;
  box-shadow: 0 5px 10px rgba(30,16,8,0.3);
  padding: 10px 12px;
  cursor: pointer;
  position: relative;
  min-width: 150px;
}
.mini-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 8px;
  background: #3f6fb0;
  border-radius: 5px 5px 0 0;
}
.mini-card .m-name {
  margin: 12px 0 3px;
  font-family: 'Segoe Print', 'Comic Sans MS', cursive;
  font-size: 0.95rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mini-card .m-email {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-light);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-add {
  display: block;
  width: 100%;
  margin-top: 18px;
  appearance: none;
  border: 1px solid #b8894f;
  background: linear-gradient(180deg, #d4a373, #b9874a);
  color: #fff;
  font-family: Georgia, serif;
  font-size: 1rem;
  padding: 14px;
  border-radius: 8px;
  box-shadow: 0 5px 10px rgba(30,16,8,0.4);
  cursor: pointer;
}
.btn-add:active { transform: translateY(1px); }

/* ---------- SEARCH ---------- */
.search-wrap { margin-bottom: 14px; }
.search {
  width: 100%;
  appearance: none;
  border: 1px solid rgba(80,55,35,0.3);
  background: var(--cream);
  border-radius: 6px;
  padding: 11px 12px;
  font-family: Georgia, serif;
  font-size: 0.9rem;
  color: var(--ink);
  box-shadow: 0 3px 6px rgba(30,16,8,0.2);
}
.search::placeholder { color: var(--ink-light); font-style: italic; }

/* ---------- ADD FORM ---------- */
.blank-card {
  position: relative;
  background: var(--cream);
  border: 1px solid rgba(80,55,35,0.25);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 22px 18px 18px;
}
.tab-blue {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 10px;
  background: #3f6fb0;
  border-radius: 6px 6px 0 0;
}
.card-heading {
  margin: 6px 0 16px;
  font-family: Georgia, serif;
  font-weight: normal;
  font-size: 1.2rem;
  color: var(--ink);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 8px;
}
.field { display: block; margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.input-hand {
  width: 100%;
  appearance: none;
  border: none;
  border-bottom: 1px dashed rgba(61,44,33,0.4);
  background: transparent;
  font-family: 'Segoe Print', 'Comic Sans MS', cursive;
  font-size: 1.05rem;
  color: var(--ink);
  padding: 4px 2px;
  outline: none;
}
.input-hand:focus { border-bottom-color: var(--primary); }
.btn-save {
  display: block;
  width: 100%;
  appearance: none;
  border: 1px solid #b8894f;
  background: linear-gradient(180deg, #d4a373, #b9874a);
  color: #fff;
  font-family: Georgia, serif;
  font-size: 1rem;
  padding: 14px;
  border-radius: 8px;
  box-shadow: 0 5px 10px rgba(30,16,8,0.4);
  cursor: pointer;
}
.btn-save:active { transform: translateY(1px); }
.form-error {
  color: #b3261e;
  font-size: 0.8rem;
  margin: 4px 0 10px;
  font-style: italic;
}

/* ---------- EMPTY STATE ---------- */
.empty {
  position: relative;
  background: rgba(239,235,233,0.1);
  border: 2px dashed rgba(239,235,233,0.4);
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  color: var(--secondary);
}
.empty .drum {
  font-size: 3rem;
  margin-bottom: 8px;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}
.empty .e-title {
  font-family: Georgia, serif;
  font-size: 1.05rem;
  margin: 0 0 4px;
}
.empty .e-sub {
  font-size: 0.8rem;
  font-style: italic;
  opacity: 0.8;
  margin: 0;
}