/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #2d5a27;
  --green-light: #4a8c3f;
  --cream: #f5f0e8;
  --white: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #666;
  --border: #e0d8cc;
  --danger: #d94a4a;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 16px);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--cream);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-bottom));
}

/* ========== Header ========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--green);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.btn-icon {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 1.25rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.btn-icon:active { background: rgba(255,255,255,0.4); }

/* Status badge */
.status-badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}
.status-ok { background: rgba(255,255,255,0.25); }
.status-warn { background: rgba(255,200,0,0.3); }
.status-err { background: rgba(255,80,80,0.3); }

/* Empty result */
.empty-result {
  text-align: center;
  color: #999;
  padding: 40px;
  font-size: 0.9rem;
}

/* Record hint sub */
.record-hint-sub {
  font-size: 0.75rem;
  color: #aaa;
  text-align: center;
}

/* ========== Pages ========== */
.page {
  display: none;
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}
.page.active { display: block; }

/* ========== Search Bar ========== */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.input-search {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--white);
  outline: none;
}
.input-search:focus { border-color: var(--green); }

.select-filter {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--white);
  outline: none;
  min-width: 80px;
}

/* ========== Log List ========== */
.log-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
}
.log-card:active { transform: scale(0.98); }

.log-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.log-card-title {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
  line-height: 1.4;
}

.log-card-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
  margin-left: 8px;
}
.badge-match { background: #fde8e8; color: #c53030; }
.badge-training { background: #e6f4e6; color: #2d5a27; }
.badge-practice { background: #ebf4ff; color: #2b6cb0; }

.log-card-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.log-card-preview {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

.log-card-kw {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.kw-tag {
  font-size: 0.75rem;
  background: #e8f0e4;
  color: var(--green);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 500;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-hint { font-size: 0.85rem; margin-top: 8px; opacity: 0.7; }

/* ========== Record Page ========== */
.record-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.record-date-row {
  width: 100%;
}
.input-date {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--white);
  width: 100%;
  outline: none;
}

.record-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.btn-record {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 4px solid var(--danger);
  background: white;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
  box-shadow: 0 4px 24px rgba(217,74,74,0.2);
}
.btn-record:active { transform: scale(0.95); }

.mic-icon { font-size: 2.5rem; }
.mic-label { font-size: 0.85rem; color: var(--text-secondary); }

.record-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  max-width: 280px;
}

/* Recording active */
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--danger);
}

.pulse {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(217,74,74,0.5); }
  70% { box-shadow: 0 0 0 16px rgba(217,74,74,0); }
  100% { box-shadow: 0 0 0 0 rgba(217,74,74,0); }
}

.btn-stop {
  padding: 14px 40px;
  border-radius: 30px;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

/* Transcript */
.transcript-area, .ai-result, .prompt-mode {
  width: 100%;
}

.transcript-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.transcript-header h3 { font-size: 1rem; }

.btn-text {
  background: none;
  border: none;
  color: var(--green);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 8px;
}

.badge {
  font-size: 0.75rem;
  background: #e8f0e4;
  color: var(--green);
  padding: 2px 8px;
  border-radius: 20px;
}

.transcript-text {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 120px;
  font-size: 0.95rem;
  line-height: 1.7;
  outline: none;
  width: 100%;
}

.transcript-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  width: 100%;
}

.edit-textarea-lg {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.7;
  font-family: inherit;
  resize: vertical;
  outline: none;
}
.edit-textarea-lg:focus { border-color: var(--green); }

.prompt-pre {
  background: #1a1a1a;
  color: #e0e0e0;
  padding: 16px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 12px;
}

/* ========== Buttons ========== */
.btn {
  padding: 12px 24px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--green); color: white; }
.btn-outline { background: white; color: var(--green); border: 1.5px solid var(--green); }
.btn-danger { background: var(--danger); color: white; }
.btn-lg { padding: 14px 28px; font-size: 1rem; width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }

/* ========== Cards Page ========== */
.cards-scroll {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-block {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card-block h2 {
  font-size: 1.05rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--green-light);
}

/* Markdown content in cards */
.card-md { font-size: 0.9rem; line-height: 1.7; }
.card-md h1, .card-md h2 { font-size: 1rem; margin: 12px 0 6px; }
.card-md h3 { font-size: 0.95rem; margin: 10px 0 4px; }
.card-md p { margin: 6px 0; }
.card-md ul, .card-md ol { padding-left: 20px; margin: 6px 0; }
.card-md li { margin: 3px 0; }
.card-md table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin: 8px 0; }
.card-md th, .card-md td { padding: 8px 10px; border: 1px solid var(--border); text-align: left; }
.card-md th { background: #f5f0e8; font-weight: 600; }
.card-md blockquote { border-left: 3px solid var(--green-light); padding: 4px 12px; margin: 8px 0; color: var(--text-secondary); background: #f9f7f3; }
.card-md code { background: #e8f0e4; padding: 1px 5px; border-radius: 3px; font-size: 0.85em; }
.card-md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ========== Detail Modal ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.modal-sheet {
  position: relative;
  background: var(--cream);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}
.modal-full { max-height: 95dvh; }
.modal-sheet .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-sheet .modal-header h2 { font-size: 1.1rem; }
.modal-header-actions { display: flex; gap: 8px; }
.modal-sheet .modal-header .btn-icon {
  background: #eee;
  color: var(--text);
  width: 36px;
  height: 36px;
}
.modal-sheet .modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.detail-meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  display: flex;
  gap: 16px;
}

.kw-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.kw-tag-big {
  font-size: 0.85rem;
  background: #e8f0e4;
  color: var(--green);
  padding: 4px 14px;
  border-radius: 20px;
  font-weight: 500;
}
.kw-tag-big .kw-desc {
  font-weight: 400;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-left: 4px;
}

/* ========== Forms ========== */
.form-row {
  display: flex;
  gap: 12px;
}
.form-row .form-group { flex: 1; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.input-full {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  background: var(--white);
}
.input-full:focus { border-color: var(--green); }

textarea.input-full {
  resize: vertical;
  line-height: 1.6;
}

.form-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.kw-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.kw-name { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.9rem; }
.kw-desc { flex: 2; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.9rem; }
.btn-remove-kw {
  background: none;
  border: none;
  color: #999;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
}

/* ========== Settings ========== */
.setting-group { margin-bottom: 24px; }
.setting-group label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 6px; }
.setting-hint { font-size: 0.8rem; color: var(--text-secondary); margin-top: 6px; }
.setting-status { font-size: 0.85rem; margin-top: 8px; font-weight: 500; }
.setting-info {
  font-size: 0.9rem;
  padding: 8px 12px;
  background: #f0f0f0;
  border-radius: 6px;
  word-break: break-all;
}

/* ========== Bottom Nav ========== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 0 var(--safe-bottom);
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 16px;
  border-radius: 10px;
  transition: background 0.15s;
  color: var(--text-secondary);
}
.nav-item:active { background: #f0f0f0; }
.nav-item.active { color: var(--green); }

.nav-icon { font-size: 1.4rem; }
.nav-icon-big {
  font-size: 1.6rem;
  background: var(--green);
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -18px;
  box-shadow: 0 4px 12px rgba(45,90,39,0.3);
}
.nav-label { font-size: 0.7rem; font-weight: 500; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  z-index: 300;
  animation: fadeIn 0.2s ease;
  white-space: nowrap;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--danger); }
@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== Utility ========== */
.hidden { display: none !important; }

/* ========== Record Mode Tabs ========== */
.mode-tabs {
  display: flex;
  gap: 0;
  width: 100%;
  background: #e8e2d6;
  border-radius: var(--radius);
  padding: 3px;
}

.mode-tab {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: calc(var(--radius) - 3px);
  background: transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}
.mode-tab.active {
  background: white;
  color: var(--green);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.mode-panel {
  width: 100%;
}

/* Text input */
.text-input-big {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.8;
  resize: vertical;
  outline: none;
  background: var(--white);
}
.text-input-big:focus { border-color: var(--green); }

.text-input-big::placeholder {
  color: #c0b8a8;
  font-size: 0.95rem;
}

.transcript-box { width: 100%; }

.btn-text-sm {
  background: none;
  border: none;
  color: #999;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 6px;
}

/* ========== Utility ========== */
.hidden { display: none !important; }

/* ========== Summary Page ========== */
.summary-stats {
  display: flex;
  gap: 12px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}
.stat-item {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.stat-item strong {
  color: var(--green);
  font-size: 1.1rem;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--green-light);
}
.card-header-row h2 {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.card-badge {
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: #e8f0e4;
  padding: 2px 10px;
  border-radius: 20px;
}

/* Live keywords */
.kw-live { display: flex; flex-direction: column; gap: 4px; }
.kw-live-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f0ebe0;
}
.kw-live-item:last-child { border-bottom: none; }
.kw-live-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--green);
  background: #e8f0e4;
  padding: 2px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.kw-live-desc {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.kw-live-count {
  font-size: 0.8rem;
  color: #999;
  white-space: nowrap;
}

/* Regenerate */
.regenerate-status {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.status-success { background: #e6f4e6; color: var(--green); }
.status-error { background: #fde8e8; color: var(--danger); }

/* Keyword delete */
.btn-kw-delete {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}
.btn-kw-delete:hover, .btn-kw-delete:active { color: var(--danger); }

.kw-hidden { opacity: 0.4; }
.kw-toggle-row { margin-top: 8px; text-align: center; }

/* ========== Password Gate ========== */
.password-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  padding: 20px;
}
.password-card {
  text-align: center;
  color: white;
  max-width: 320px;
  width: 100%;
}
.password-card h1 { font-size: 3rem; margin-bottom: 8px; }
.password-card h2 { font-size: 1.3rem; margin-bottom: 8px; }
.password-card p { font-size: 0.9rem; opacity: 0.8; margin-bottom: 20px; }

.password-input {
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  text-align: center;
  outline: none;
  margin-bottom: 14px;
  letter-spacing: 4px;
}
.password-input::placeholder { letter-spacing: 0; }

.password-error {
  color: #ffdddd;
  font-size: 0.85rem;
  margin-top: 12px;
}

/* Edit modal actions row */
.edit-actions-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.edit-actions-row .btn { flex: 1; }
