/* WhisperFlow PWA - Mobile-first design with dark/light theme */

:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-surface: #16213e;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.3);
  --command: #7c5cbf;
  --command-glow: rgba(124, 92, 191, 0.3);
  --transcribe: #10b981;
  --transcribe-glow: rgba(16, 185, 129, 0.3);
  --success: #4ade80;
  --warning: #fb923c;
  --error: #ef4444;
  --border: #2a2a4a;
  --radius: 12px;
  --input-bg: var(--bg-surface);
}

[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-surface: #e8e8ec;
  --text: #1a1a2e;
  --text-dim: #666;
  --border: #d0d0d8;
  --input-bg: #ffffff;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.3s, color 0.3s;
}

.hidden { display: none !important; }

/* ===================== Auth Screen ===================== */
.screen { min-height: 100dvh; }

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  text-align: center;
  width: 100%;
  max-width: 360px;
}

.logo {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--accent), #c23152);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  margin: 0 auto 16px;
  color: white;
}

.auth-card h1 { font-size: 28px; margin-bottom: 8px; }
.auth-card p { color: var(--text-dim); margin-bottom: 24px; }

.auth-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
}

.auth-card input:focus { border-color: var(--accent); }

.error {
  color: var(--error);
  font-size: 14px;
  margin-top: 8px;
}

/* ===================== Buttons ===================== */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.2s, transform 0.1s;
}

.btn:active { opacity: 0.8; transform: scale(0.98); }
.btn-primary { background: var(--accent); color: white; }
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger { background: var(--error); color: white; margin-top: 12px; }
.btn-small {
  padding: 8px 16px;
  font-size: 14px;
  width: auto;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px;
  font-size: 24px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
}
.icon-btn:hover { color: var(--text); }

/* ===================== Header ===================== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.3s;
}

header h1 { font-size: 20px; font-weight: 700; }

.header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* ===================== Tabs ===================== */
.tabs {
  display: flex;
  padding: 8px 8px;
  gap: 2px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  transition: background 0.3s, border-color 0.3s;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab.active {
  background: var(--bg-surface);
  color: var(--text);
}

/* ===================== Panels ===================== */
#panels-container {
  position: relative;
  touch-action: pan-y;
}

.panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: calc(100dvh - 110px);
}

.panel.hidden { display: none; }

/* ===================== Result Area ===================== */
#result-area, #command-result-area, #transcribe-result-area {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

.placeholder {
  color: var(--text-dim);
  text-align: center;
  padding: 40px 20px;
  line-height: 1.6;
}

.result-text {
  font-size: 18px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  user-select: text;
  -webkit-user-select: text;
}

.raw-text {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  user-select: text;
  -webkit-user-select: text;
}

/* ===================== Status Bar ===================== */
.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 8px 20px;
  font-size: 13px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
}

/* ===================== Waveform ===================== */
.waveform-canvas {
  display: block;
  width: calc(100% - 40px);
  height: 48px;
  margin: 0 20px;
  border-radius: 8px;
  background: var(--bg-surface);
}

/* ===================== Record Button ===================== */
.record-area {
  display: flex;
  justify-content: center;
  padding: 24px 0 16px;
}

.audio-ring {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.3s;
}

.audio-ring.active {
  box-shadow: 0 0 0 12px var(--accent-glow), 0 0 40px var(--accent-glow);
  animation: pulse-ring 1.5s ease-in-out infinite;
}

.audio-ring.transcribe-active {
  box-shadow: 0 0 0 12px var(--transcribe-glow), 0 0 40px var(--transcribe-glow);
  animation: pulse-ring-transcribe 1.5s ease-in-out infinite;
}

.audio-ring.command-active {
  box-shadow: 0 0 0 12px var(--command-glow), 0 0 40px var(--command-glow);
  animation: pulse-ring-cmd 1.5s ease-in-out infinite;
}

.audio-ring.processing {
  box-shadow: 0 0 0 8px rgba(59, 130, 246, 0.3);
  animation: pulse-processing 1s ease-in-out infinite;
}

@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 0 0 8px var(--accent-glow); }
  50% { box-shadow: 0 0 0 16px var(--accent-glow), 0 0 60px var(--accent-glow); }
}

@keyframes pulse-ring-transcribe {
  0%, 100% { box-shadow: 0 0 0 8px var(--transcribe-glow); }
  50% { box-shadow: 0 0 0 16px var(--transcribe-glow), 0 0 60px var(--transcribe-glow); }
}

@keyframes pulse-ring-cmd {
  0%, 100% { box-shadow: 0 0 0 8px var(--command-glow); }
  50% { box-shadow: 0 0 0 16px var(--command-glow), 0 0 60px var(--command-glow); }
}

@keyframes pulse-processing {
  0%, 100% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.2); }
  50% { box-shadow: 0 0 0 12px rgba(59, 130, 246, 0.4); }
}

.record-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: var(--bg-card);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.record-btn:active, .record-btn.active {
  background: var(--accent);
  color: white;
  transform: scale(0.95);
}

.record-btn.processing {
  border-color: #3b82f6;
  color: #3b82f6;
  animation: spin 1.5s linear infinite;
}

@keyframes spin { 100% { transform: rotate(360deg); } }

.transcribe-btn { border-color: var(--transcribe); color: var(--transcribe); }
.transcribe-btn:active, .transcribe-btn.active {
  background: var(--transcribe);
  color: white;
}

.command-btn { border-color: var(--command); color: var(--command); }
.command-btn:active, .command-btn.active {
  background: var(--command);
  color: white;
}

/* ===================== Action Bar ===================== */
.action-bar {
  display: flex;
  gap: 12px;
  padding: 0 20px 20px;
}

.action-bar .btn { width: auto; flex: 1; }

/* ===================== Command Input ===================== */
.command-input-area { padding: 16px 20px; }

.command-input-area label {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: block;
}

.command-input-area textarea {
  width: 100%;
  padding: 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  resize: vertical;
  font-family: inherit;
  outline: none;
}

.command-input-area textarea:focus { border-color: var(--command); }

/* ===================== Search Bar ===================== */
.search-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search-bar input {
  width: 100%;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.search-bar input:focus { border-color: var(--accent); }

/* ===================== History ===================== */
.history-list {
  padding: 16px;
  overflow-y: auto;
}

.history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  transition: background 0.3s, border-color 0.3s;
}

.history-item .text {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 8px;
  user-select: text;
  -webkit-user-select: text;
}

.history-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.history-meta .badge {
  background: var(--bg-surface);
  padding: 2px 8px;
  border-radius: 4px;
}

/* ===================== Management Panels ===================== */
.manage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.manage-header h2 { font-size: 18px; }

.manage-list {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.manage-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  transition: background 0.3s, border-color 0.3s;
}

.manage-item-content { flex: 1; min-width: 0; }

.manage-item-content .trigger {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.manage-item-content .content-preview {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manage-item-content .word {
  font-size: 16px;
  font-weight: 500;
}

.manage-item-content .category {
  font-size: 12px;
  color: var(--text-dim);
}

.delete-btn {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  padding: 6px;
  font-size: 18px;
  line-height: 1;
  border-radius: 6px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.delete-btn:active { background: rgba(239, 68, 68, 0.1); }

/* ===================== Inline Form ===================== */
.inline-form {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inline-form input,
.inline-form textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.inline-form input:focus,
.inline-form textarea:focus { border-color: var(--accent); }

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions .btn { flex: 1; }

/* ===================== Toast Notifications ===================== */
#toast-container {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  pointer-events: auto;
  animation: toast-in 0.3s ease-out;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.toast.toast-error { background: var(--error); color: white; }
.toast.toast-success { background: var(--success); color: #1a1a2e; }
.toast.toast-info { background: #3b82f6; color: white; }
.toast.toast-warning { background: var(--warning); color: #1a1a2e; }

.toast.toast-exit { animation: toast-out 0.3s ease-in forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-20px); }
}

/* ===================== Modal ===================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: fade-in 0.2s;
}

@keyframes fade-in { from { opacity: 0; } }

.modal-content {
  background: var(--bg-card);
  width: 100%;
  max-height: 80dvh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  animation: slide-up 0.3s ease-out;
  transition: background 0.3s;
}

@keyframes slide-up { from { transform: translateY(100%); } }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.modal-body { padding: 20px; }

.setting-group { margin-bottom: 20px; }

.setting-group label {
  display: block;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.setting-group select,
.setting-group input {
  width: 100%;
  padding: 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.setting-group select:focus,
.setting-group input:focus { border-color: var(--accent); }

/* ===================== Stats Dashboard ===================== */
.stats-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  transition: background 0.3s, border-color 0.3s;
}

.stat-card.wide { grid-column: 1 / -1; }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-breakdown {
  margin-top: 12px;
  text-align: left;
}

.stat-breakdown-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.stat-breakdown-item:last-child { border-bottom: none; }
.stat-breakdown-item .label { color: var(--text-dim); }
.stat-breakdown-item .value { font-weight: 600; }

.history-audio { margin-top: 8px; }
.history-audio audio { width: 100%; height: 32px; border-radius: 6px; }

/* ===================== Safe Area ===================== */
@supports (padding-top: env(safe-area-inset-top)) {
  header { padding-top: calc(12px + env(safe-area-inset-top)); }
  .record-area { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  #toast-container { top: calc(12px + env(safe-area-inset-top)); }
}
