:root {
  --red: #b3261e;
  --red-dark: #8c1d17;
  --bg: #f5f4f2;
  --card: #ffffff;
  --text: #1c1b1b;
  --muted: #6b6663;
  --border: #e4e1de;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; }
.screen.visible { display: block; }

/* ---------- Login ---------- */
#login-screen {
  display: none;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--red) 0%, var(--red-dark) 100%);
}
#login-screen.visible { display: flex; }
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.login-logo { font-size: 48px; margin-bottom: 4px; }
.login-card h1 { font-size: 22px; margin: 4px 0; }
.login-card .muted { margin-bottom: 20px; }
#login-form input {
  width: 100%;
  font-size: 20px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
  text-align: center;
  letter-spacing: 2px;
}

/* ---------- App shell ---------- */
#app-screen { display: none; flex-direction: column; min-height: 100dvh; }
#app-screen.visible { display: flex; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--red);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px calc(14px);
  padding-top: max(14px, env(safe-area-inset-top));
}
.topbar-title { font-weight: 700; font-size: 18px; }
.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.view {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(96px + var(--safe-bottom));
  overflow-y: auto;
}

/* ---------- Search ---------- */
.search-bar input {
  width: 100%;
  font-size: 17px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
}
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 12px 0;
  padding-bottom: 4px;
}
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}
.chip.active { background: var(--red); border-color: var(--red); color: #fff; }

.results-list { display: flex; flex-direction: column; gap: 10px; }
.result-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  width: 100%;
}
.result-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.result-type { font-size: 13px; color: var(--red); font-weight: 700; }
.result-date { font-size: 12px; color: var(--muted); margin-left: auto; }
.result-title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.result-excerpt { font-size: 14px; color: var(--muted); line-height: 1.4; }

.empty-state { text-align: center; color: var(--muted); margin-top: 40px; font-size: 15px; }

/* ---------- Cards / forms ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 17px; margin: 0 0 10px; }
.card input[type="text"],
.card input[type="url"],
.card textarea,
.card input[type="file"] {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
  font-family: inherit;
  background: #fafafa;
}
.card textarea { resize: vertical; min-height: 120px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.status-text { font-size: 13px; margin-top: 8px; min-height: 16px; }
.status-text.ok { color: #1e7d32; }
.status-text.err { color: var(--red); }
.error-text { color: var(--red); font-size: 14px; min-height: 18px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 18px;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:active { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--red); padding: 10px 4px; font-weight: 700; }
.btn-danger { background: #fff; color: var(--red); border: 1px solid var(--red); }

/* ---------- Detail view ---------- */
#view-detail .meta { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
#view-detail h2 { font-size: 20px; margin: 10px 0; }
#view-detail .summary-box {
  background: #fff7f6;
  border: 1px solid #f0d7d4;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  line-height: 1.5;
}
#view-detail .full-content {
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 15px;
  color: var(--text);
}
#view-detail details { margin-top: 10px; }
#view-detail summary { cursor: pointer; color: var(--red); font-weight: 600; padding: 8px 0; }
.detail-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}
.nav-btn.active { color: var(--red); font-weight: 700; }
.nav-icon { font-size: 22px; }

@media (min-width: 700px) {
  .view { max-width: 640px; margin: 0 auto; width: 100%; }
  .bottom-nav { max-width: 640px; margin: 0 auto; left: 0; right: 0; border-radius: 14px 14px 0 0; }
}
