:root {
  --teal: #2c6e63;
  --teal-dark: #1f4f47;
  --red: #c8372c;
  --ink: #1e1e24;
  --muted: #6b6b75;
  --bg: #f5f3ee;
  --card-bg: #ffffff;
  --border: #e4e2dd;
  --accent-bg: #eaf3f0;
  --radius: 14px;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

.app-header {
  background: var(--teal-dark);
  color: white;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.header-inner h1 {
  font-size: 1.05rem;
  margin: 0;
}

.auth-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
}

.auth-email {
  opacity: 0.85;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-info button {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.75rem;
}

.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--muted);
}

.auth-gate[hidden] { display: none; }

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 14px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.field-block { margin-bottom: 18px; }

.field-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.cat-picker, .type-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.type-picker { grid-template-columns: repeat(3, 1fr); }

.cat-btn, .type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--card-bg);
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
}

.type-emoji { font-size: 1.8rem; }

.cat-photo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-bg);
  border: 2px solid var(--border);
}

.cat-btn.active .cat-photo { border-color: var(--teal); }

.cat-btn.active, .type-btn.active {
  border-color: var(--teal);
  background: var(--accent-bg);
  font-weight: 700;
}

#record-fields textarea,
#record-fields input[type="text"],
#record-fields input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 1rem;
  background: white;
  font-family: inherit;
}

#record-fields textarea {
  min-height: 80px;
  resize: vertical;
}

#record-datetime {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 1rem;
  background: white;
  font-family: inherit;
}

#record-submit-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  border: none;
  background: var(--teal);
  color: white;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}

#record-submit-btn:active { opacity: 0.85; }

.status {
  min-height: 22px;
  margin: 10px 2px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status.error { color: var(--red); }
.status.success { color: var(--teal); }

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.chip-group { display: flex; gap: 6px; }

.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
}

.chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-weight: 700;
}

#type-filter {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.85rem;
  color: var(--ink);
}

#history-refresh-btn {
  margin-left: auto;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
}

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

.rc-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.rc-cat-photo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.rc-cat {
  font-weight: 700;
  font-size: 0.9rem;
}

.rc-type {
  font-size: 0.8rem;
  background: var(--accent-bg);
  color: var(--teal-dark);
  padding: 2px 9px;
  border-radius: 999px;
}

.rc-time {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
}

.rc-note {
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 6px;
}

.rc-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rc-by {
  font-size: 0.72rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rc-delete {
  border: none;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.6;
  padding: 2px 6px;
}

.rc-delete:active { opacity: 1; }

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: white;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.bottom-nav[hidden] { display: none; }

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: pointer;
}

.nav-icon { font-size: 1.4rem; }

.nav-btn.active { color: var(--teal); font-weight: 700; }
