:root {
  --bg: #f3ebe0;
  --card: #fffdf8;
  --ink: #1e2a44;
  --muted: #6b7280;
  --navy: #1e3a5f;
  --navy-soft: #dbe7f5;
  --green: #15803d;
  --green-bg: #e8f5e9;
  --green-dot: #2e7d32;
  --has-bg: #e6f4ea;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --border: #e5ddd0;
  --shadow: 0 2px 10px rgba(30, 42, 68, 0.08);
  --radius: 16px;
  --tab-h: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "PingFang TC", "Noto Sans TC", "Helvetica Neue", sans-serif;
  --brand: "Georgia", "Songti TC", serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
body { padding-bottom: 24px; padding-top: 0; }

/* Reduce accidental double-tap zoom on controls (iOS/Android) */
html {
  touch-action: manipulation;
}
button, a, input, textarea, label, .cal-cell, .tab, .icon-btn {
  touch-action: manipulation;
}


.app {
  max-width: 980px;
  margin: 0 auto;
  min-height: 100dvh;
}

.chrome {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(243, 235, 224, 0.96);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 8px;
  position: relative;
  z-index: 20;
  background: transparent;
  backdrop-filter: none;
}
.brand {
  margin: 0;
  font-family: var(--brand);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--navy);
  letter-spacing: 0.01em;
}

.conn-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.conn-badge.connected {
  background: var(--green-bg);
  color: var(--green);
  border-color: #bbf7d0;
}
.conn-badge.disconnected {
  background: var(--red-bg);
  color: var(--red);
  border-color: #fecaca;
}
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.main { padding: 0 16px 24px; }
.phone-only { display: block; }
@media (min-width: 768px) {
  .phone-only { display: none; }
}

.home-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (min-width: 768px) {
  .home-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
  }
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.panel-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
  color: var(--navy);
}

.cal-nav, .date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.cal-month {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--navy);
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--navy);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 6px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  aspect-ratio: 1;
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0;
  position: relative;
}
.cal-cell.muted { color: #b0b0b0; background: transparent; box-shadow: none; }
.cal-cell.has {
  background: var(--has-bg);
  font-weight: 600;
}
.cal-cell.has::after {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green-dot);
}
.cal-cell.holiday-day {
  border: 2px solid #c62828;
  box-shadow: none;
}
.cal-cell.holiday-day.selected {
  border: 2px solid #c62828;
  outline-color: var(--navy);
}
.cal-cell.selected {
  outline: 2.5px solid var(--navy);
  outline-offset: 0;
  background: var(--has-bg);
}
.cal-cell.today-mark .num {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.8rem;
}
.cal-legend i.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-dot);
  margin-right: 4px;
}
.cal-legend i.box {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--navy);
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}
.cal-legend i.box.holiday {
  border-color: #c62828;
  border-width: 2px;
}

.date-card {
  flex: 1;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.date-card .date-line {
  display: block;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.35;
  text-align: center;
}
.date-card .date-line .holiday {
  display: block;
  color: #b45309;
  font-weight: 700;
  margin-top: 2px;
}
.btn-voice, #stt-pill { display: none !important; }

.entry-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0 8px;
  flex-wrap: wrap;
}
.entry-heading .field-label {
  margin: 0;
}
.entry-heading .pill {
  flex-shrink: 0;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.warn { background: #fff7ed; color: #c2410c; }
.pill.muted { background: #f3f4f6; color: var(--muted); }

.field-label {
  display: block;
  font-weight: 700;
  margin: 4px 0 8px;
  color: var(--navy);
  font-size: 1.05rem;
}
.entry-text {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.55;
  background: #fff;
  color: var(--ink);
}
.entry-text:focus {
  outline: 2px solid var(--navy-soft);
  border-color: #93c5fd;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: 14px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-voice {
  background: #fff;
  border: 2px solid var(--navy);
  color: var(--navy);
}
.btn-voice.listening {
  background: var(--navy);
  color: #fff;
  animation: pulse 1.2s ease infinite;
}
@keyframes pulse {
  50% { opacity: 0.85; }
}
.btn-attach {
  background: #fff;
  border: 2px dashed #9ca3af;
  color: var(--muted);
}
.btn-save {
  background: var(--navy);
  border: none;
  color: #fff;
  margin-top: 16px;
}
.btn-save:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-ico { font-size: 1.1rem; }

.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.attach-item {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f8fafc;
}
.attach-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attach-item .file-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 6px;
  font-size: 0.7rem;
  text-align: center;
  word-break: break-all;
  color: var(--ink);
}
.attach-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 0.75rem;
  cursor: pointer;
  line-height: 1;
}

.view-search .search-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.search-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  font: inherit;
  font-size: 1.05rem;
  background: #fff;
}
.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.search-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
}
.search-item .when {
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 4px;
}
.search-item .snip {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}
.search-empty {
  color: var(--muted);
  text-align: center;
  padding: 24px 8px;
}

.tabbar {
  position: relative;
  left: auto;
  transform: none;
  bottom: auto;
  width: calc(100% - 32px);
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px;
  box-shadow: 0 4px 14px rgba(30, 42, 68, 0.1);
  z-index: 30;
}
.tab {
  border: none;
  background: transparent;
  border-radius: 14px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--navy-soft);
  color: var(--navy);
  font-weight: 700;
}
.tab-ico { font-size: 1.2rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 40;
  max-width: 90vw;
}

@media (min-width: 768px) {
  .topbar { padding: 18px 24px 10px; }
  .main { padding: 0 24px 32px; }
  .brand { font-size: 1.55rem; }
  .tabbar { width: calc(100% - 48px); max-width: 520px; }
}

.search-detail {
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.search-detail-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}
.search-detail-body {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 1.05rem;
  color: var(--ink);
  min-height: 3em;
}
.search-item.is-active {
  outline: 2.5px solid var(--navy);
  outline-offset: 0;
}

.attach-item {
  cursor: pointer;
}
.attach-item img,
.attach-item .file-chip {
  pointer-events: none;
}
.attach-del {
  z-index: 2;
  pointer-events: auto;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 16px 24px;
  box-sizing: border-box;
}
.lightbox[hidden] {
  display: none !important;
}
.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #fff;
  color: #1e293b;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  z-index: 2;
}
.lightbox-body {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-body img {
  max-width: 100%;
  max-height: calc(100vh - 80px);
  border-radius: 12px;
  object-fit: contain;
  background: #fff;
}
.lightbox-body .lightbox-file {
  background: #fff;
  color: var(--ink);
  padding: 24px 28px;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  max-width: 90vw;
  word-break: break-all;
}
