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

:root {
  --bg: #f0f2f8;
  --bg-card: #ffffff;
  --bg-input: #f5f6fa;
  --border: #e2e6f0;
  --text: #1a1d2e;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-light: #ede9fe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(99,102,241,0.15);
  --nav-h: 72px;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ===== App Shell ===== */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ===== Header ===== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--accent);
  z-index: 100;
  padding-top: env(safe-area-inset-top, 0px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.3px;
}

.header-badge {
  font-size: 20px;
  opacity: 0.6;
}
.header-badge.online { opacity: 1; color: #a7f3d0; }

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view { padding: 16px; }
.hidden { display: none !important; }

/* ===== Bottom Navigation ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  padding: 8px 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn:active { background: var(--bg); }

.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }

.nav-btn.active .nav-label { color: var(--accent); font-weight: 700; }
.nav-btn.active .nav-icon { filter: none; }

.nav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--error);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ===== Section Title ===== */
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
  padding-left: 4px;
}

/* ===== Upload Card ===== */
.upload-dropzone {
  background: white;
  border: 2.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  overflow: hidden;
}

.upload-dropzone.drag-over,
.upload-dropzone.has-file {
  border-color: var(--accent);
  background: var(--accent-light);
}

.upload-dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon-wrap {
  width: 72px;
  height: 72px;
  background: var(--accent-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 32px;
  transition: transform 0.2s;
}

.upload-dropzone.has-file .upload-icon-wrap { transform: scale(0.9); }

.upload-dropzone h2 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.upload-dropzone p {
  font-size: 13px;
  color: var(--text-muted);
}

.file-selected {
  margin-top: 14px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-dark);
  word-break: break-all;
}

/* ===== Options Card ===== */
.options-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

select, input[type="number"] {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}

select:focus, input[type="number"]:focus {
  border-color: var(--accent);
}

/* ===== Buttons ===== */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 14px;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-lg);
}

.btn-primary:active { transform: scale(0.98); opacity: 0.9; }
.btn-primary:disabled {
  background: var(--border);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-input);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--error-light);
  color: var(--error);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 18px;
  cursor: pointer;
  border: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Progress ===== */
.progress-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.progress-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

.progress-bar-track {
  height: 8px;
  background: var(--bg-input);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  transition: width 0.5s ease;
}

.progress-msg {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ===== Job Cards ===== */
.jobs-list { display: flex; flex-direction: column; gap: 10px; }

.job-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s;
  border: 2px solid transparent;
}

.job-card:active { transform: scale(0.99); }
.job-card.status-completed { border-color: transparent; }

.job-card-icon {
  font-size: 32px;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  background: var(--bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.job-card-body { flex: 1; min-width: 0; }

.job-card-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.job-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.job-card-status { flex-shrink: 0; }

/* ===== Status Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-pending { background: #e0f2fe; color: #0369a1; }
.badge-processing { background: var(--warning-light); color: #92400e; }
.badge-completed { background: var(--success-light); color: #065f46; }
.badge-error { background: var(--error-light); color: #991b1b; }

/* ===== Stats Row ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: white;
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 26px; font-weight: 800; color: var(--accent); line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-weight: 600; }

/* ===== Detail View ===== */
.detail-header-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.detail-file-name {
  font-size: 16px;
  font-weight: 700;
  word-break: break-all;
  margin-bottom: 6px;
}

.detail-meta { font-size: 13px; color: var(--text-muted); }

.action-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.export-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 40px rgba(0,0,0,0.15);
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.export-sheet.open { transform: translateY(0); }

.export-sheet-title {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  color: var(--text-muted);
}

.export-sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.export-sheet-overlay.open { opacity: 1; pointer-events: all; }

.export-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px;
  background: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  margin-bottom: 10px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.export-btn:active { background: var(--border); }
.export-btn-icon { font-size: 24px; width: 40px; text-align: center; }

/* ===== Transcript ===== */
.transcript-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0 14px;
}

.segment-card {
  background: white;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border-left: 4px solid transparent;
}

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

.speaker-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.speaker-input {
  font-size: 13px;
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 1.5px dashed transparent;
  outline: none;
  color: var(--text);
  padding: 2px 4px;
  border-radius: 4px;
  flex: 1;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
  min-width: 0;
}

.speaker-input:focus {
  background: var(--accent-light);
  border-bottom-color: var(--accent);
}

.segment-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

.text-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  outline: none;
  font-family: inherit;
  min-height: 24px;
  overflow: hidden;
  padding: 0;
}

.text-input:focus {
  background: #fafafa;
  border-radius: 6px;
  padding: 6px 8px;
  margin: -6px -8px;
}

/* Speaker colors */
.sc-0 { border-left-color: #6366f1; }
.sc-1 { border-left-color: #10b981; }
.sc-2 { border-left-color: #f59e0b; }
.sc-3 { border-left-color: #ef4444; }
.sc-4 { border-left-color: #8b5cf6; }
.sc-5 { border-left-color: #06b6d4; }

.dot-0 { background: #6366f1; }
.dot-1 { background: #10b981; }
.dot-2 { background: #f59e0b; }
.dot-3 { background: #ef4444; }
.dot-4 { background: #8b5cf6; }
.dot-5 { background: #06b6d4; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-icon { font-size: 56px; margin-bottom: 14px; }
.empty-state h2 { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--text-muted); }

/* ===== Processing State ===== */
.processing-card {
  background: white;
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.processing-anim {
  font-size: 52px;
  margin-bottom: 16px;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
}

/* ===== Spinner ===== */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(99,102,241,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

.spinner-lg {
  width: 36px; height: 36px;
  border-width: 3px;
  margin: 0 auto 16px;
  display: block;
}

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

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  left: 12px; right: 12px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast {
  background: #1a1d2e;
  color: white;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slide-down 0.3s ease;
  pointer-events: all;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.toast-success { background: #065f46; }
.toast-error { background: #991b1b; }

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

/* ===== Sticky save bar ===== */
.save-bar {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}

.save-bar-btn {
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 40px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s;
}

.save-bar-btn:active { transform: scale(0.97); }

/* ===== Back button ===== */
.back-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
