/* ========== Variables ========== */
:root {
  --purple-50: #F5F3FF;
  --purple-100: #EDE9FE;
  --purple-200: #DDD6FE;
  --purple-400: #A78BFA;
  --purple-500: #8B5CF6;
  --purple-600: #7C3AED;
  --purple-700: #6D28D9;
  --purple-800: #5B21B6;
  --purple-900: #4C1D95;

  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;

  --green-500: #22C55E;
  --red-500: #EF4444;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ========== Reset & Base ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ========== Screens ========== */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.screen.hidden {
  display: none;
}

/* ========== Setup Screen ========== */
.setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 20px;
}

.setup-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.setup-container h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.setup-subtitle {
  color: var(--gray-500);
  font-size: 16px;
  margin-bottom: 40px;
}

.setup-form {
  width: 100%;
  max-width: 360px;
}

.setup-form label,
.settings-dialog label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.setup-form input,
.settings-dialog input,
.settings-dialog select {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  margin-bottom: 20px;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}

.setup-form input:focus,
.settings-dialog input:focus,
.settings-dialog select:focus {
  border-color: var(--purple-500);
}

.btn-test-voice {
  background: none;
  border: none;
  color: var(--purple-600);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 16px;
  margin-top: -12px;
  display: block;
}

/* ========== Buttons ========== */
.btn {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--purple-600);
  color: white;
}

.btn-primary:active {
  background: var(--purple-700);
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

.btn-danger {
  background: none;
  color: var(--red-500);
  font-size: 14px;
  margin-top: 24px;
  padding: 12px;
}

/* ========== Main Screen ========== */
#main-screen {
  background: var(--gray-50);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 4px;
  padding-top: calc(env(safe-area-inset-top) + 16px);
}

header h1 {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--purple-600), var(--purple-400));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.icon-btn:active {
  background: var(--gray-200);
}

/* ========== Action Cards ========== */
.actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px 0;
  flex: 1;
  align-content: center;
}

.action-card {
  background: white;
  border: none;
  border-radius: var(--radius);
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
}

.action-card:active {
  transform: scale(0.95);
  box-shadow: var(--shadow-lg);
}

.action-icon {
  font-size: 40px;
}

.action-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-700);
}

/* ========== Voice Screen ========== */
.voice-container,
.search-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 20px 0;
  padding-top: calc(env(safe-area-inset-top) + 20px);
}

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--purple-600);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 24px;
}

.voice-container h2,
.search-container h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.voice-hint {
  color: var(--gray-500);
  font-size: 15px;
  margin-bottom: 32px;
}

/* ========== Voice Circle ========== */
.voice-circle {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple-500), var(--purple-700));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(124, 58, 237, 0.3);
  transition: transform 0.2s;
  margin-bottom: 24px;
}

.voice-circle:active {
  transform: scale(0.93);
}

.voice-circle.listening {
  animation: breathe 1.5s ease-in-out infinite;
}

.mic-icon {
  font-size: 40px;
  z-index: 1;
}

.pulse-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 3px solid var(--purple-400);
  opacity: 0;
}

.voice-circle.listening .pulse-ring {
  animation: pulse 1.5s ease-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

/* ========== Transcript ========== */
.transcript-box {
  background: white;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  min-height: 60px;
}

.transcript-box p {
  font-size: 16px;
  line-height: 1.5;
  color: var(--gray-800);
}

/* ========== Text Fallback ========== */
.text-fallback {
  width: 100%;
  max-width: 360px;
  margin-bottom: 16px;
}

.or-divider {
  text-align: center;
  color: var(--gray-300);
  font-size: 13px;
  margin-bottom: 12px;
}

.text-fallback textarea {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}

.text-fallback textarea:focus {
  border-color: var(--purple-500);
}

/* ========== Voice Actions ========== */
.voice-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}

.voice-actions .btn {
  flex: 1;
}

/* ========== Search Results ========== */
.search-container {
  align-items: stretch;
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.task-result {
  background: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  text-align: left;
  font-size: 15px;
  line-height: 1.4;
  color: var(--gray-800);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, background 0.15s;
  width: 100%;
}

.task-result:active {
  transform: scale(0.98);
  background: var(--purple-50);
}

.no-results {
  text-align: center;
  color: var(--gray-500);
  padding: 40px 20px;
  font-size: 15px;
}

/* ========== Loading Overlay ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: white;
  font-size: 17px;
  font-weight: 600;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== Result Dialog ========== */
.dialog {
  background: white;
  border-radius: var(--radius);
  padding: 32px 24px 24px;
  width: calc(100% - 48px);
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.dialog-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.dialog h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.dialog p {
  color: var(--gray-500);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 24px;
}

/* ========== Settings Dialog ========== */
.settings-dialog {
  text-align: left;
}

.settings-dialog h3 {
  text-align: center;
  margin-bottom: 20px;
}

.settings-actions {
  display: flex;
  gap: 12px;
}

.settings-actions .btn {
  flex: 1;
}

/* ========== Schedule Display ========== */
.schedule-content {
  text-align: left;
  width: 100%;
}

.schedule-section {
  margin-bottom: 16px;
}

.schedule-section h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--purple-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.schedule-item {
  padding: 8px 0;
  font-size: 15px;
  line-height: 1.4;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
}

.schedule-item:last-child {
  border-bottom: none;
}

.schedule-time {
  font-weight: 600;
  color: var(--gray-900);
}

.schedule-empty {
  color: var(--gray-400);
  font-style: italic;
}

/* ========== Utility ========== */
.hidden {
  display: none !important;
}

/* ========== Safe area for PWA ========== */
@supports (padding-top: env(safe-area-inset-top)) {
  #main-screen {
    padding-top: 0;
  }
}
