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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --bg-input: #1a1a3e;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b0;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --success: #2ecc71;
  --warning: #f39c12;
  --error: #e74c3c;
  --border: #2a2a4a;
  --radius: 12px;
  --radius-sm: 8px;
}

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

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

.hidden { display: none !important; }

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: underline;
  font-weight: 600;
}
.btn-link:hover { color: var(--accent-hover); }

/* ==================== FORMS ==================== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ==================== LOGIN PAGE ==================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}

.container {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 32px 24px;
  border: 1px solid var(--border);
}

.logo {
  text-align: center;
  margin-bottom: 28px;
}

.logo-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
}

.auth-form .btn-primary {
  width: 100%;
  margin-top: 8px;
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span {
  padding: 0 12px;
}

#google-signin-container {
  display: flex;
  justify-content: center;
}

.error-msg {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

/* ==================== APP PAGE ==================== */
.app-page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
}

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

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.connected { background: var(--success); }
.status-dot.disconnected { background: var(--error); }
.status-dot.connecting { background: var(--warning); animation: pulse-dot 1s infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.app-main {
  flex: 1;
  padding: 16px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ==================== STT MODE ==================== */
.stt-mode-selector {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.radio-label input[type="radio"] {
  accent-color: var(--accent);
}

/* ==================== TTS CONTROLS ==================== */
.tts-controls {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.2s;
}

.toggle-label input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-label input:checked + .toggle-slider::after {
  left: 21px;
  background: white;
}

.tts-controls {
  gap: 12px;
}

.btn-tts-stop {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: var(--error);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  animation: pulse-dot 0.8s infinite;
}
.btn-tts-stop:hover { background: #c0392b; }

.btn-speak {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.btn-speak:hover { color: var(--accent); }
.btn-speak.speaking { color: var(--accent); animation: pulse-dot 0.8s infinite; }

/* ==================== RECORD BUTTON ==================== */
.record-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
}

.record-btn {
  position: relative;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.record-btn:hover {
  background: var(--accent);
}

.record-btn:active {
  transform: scale(0.95);
}

.record-btn.recording {
  background: var(--success);
  animation: none;
}

.record-btn.recording .record-pulse {
  display: block;
  border-color: var(--success);
}

.record-btn-inner {
  z-index: 1;
}

.record-pulse {
  display: none;
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 3px solid var(--success);
  animation: pulse-ring 1.2s ease-out infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}

.record-status {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
}

.transcript-preview {
  margin-top: 8px;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-primary);
  max-width: 100%;
  word-break: break-word;
  text-align: center;
}

/* ==================== MANUAL INPUT ==================== */
.manual-input {
  margin-bottom: 24px;
}

#text-command-form {
  display: flex;
  gap: 8px;
}

#text-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
}

#text-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ==================== COMMANDS LIST ==================== */
.commands-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.commands-section h2 {
  font-size: 1rem;
  color: var(--text-secondary);
}

.btn-danger {
  background: var(--error);
  color: white;
}
.btn-danger:hover { background: #c0392b; }

.command-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.2s;
}
.btn-delete:hover { color: var(--error); }

.commands-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 40px 20px;
}

.command-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  transition: border-color 0.2s;
}

.command-card.status-pending { border-left: 3px solid var(--warning); }
.command-card.status-processing { border-left: 3px solid var(--accent); }
.command-card.status-done { border-left: 3px solid var(--success); }
.command-card.status-error { border-left: 3px solid var(--error); }

.command-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.command-id {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.command-status {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.command-status.pending { background: rgba(243, 156, 18, 0.2); color: var(--warning); }
.command-status.processing { background: rgba(233, 69, 96, 0.2); color: var(--accent); }
.command-status.done { background: rgba(46, 204, 113, 0.2); color: var(--success); }
.command-status.error { background: rgba(231, 76, 60, 0.2); color: var(--error); }

.command-text {
  font-size: 0.95rem;
  line-height: 1.4;
  margin-bottom: 4px;
}

.command-response {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 70vh;
  overflow-y: auto;
}

.command-time {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ==================== TABS ==================== */
.tab-bar {
  display: flex;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-btn:hover:not(.active) {
  color: var(--text-primary);
}

.notif-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent);
  color: white;
  border-radius: 9px;
  font-size: 0.7rem;
  font-weight: 700;
}

/* ==================== NOTIFICATIONS ==================== */
.notifications-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.notifications-section h2 {
  font-size: 1rem;
  color: var(--text-secondary);
}

.notifications-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notification-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.notification-text {
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.notification-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.notification-time {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 400px) {
  .login-card {
    padding: 24px 16px;
  }

  .stt-mode-selector {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }
}
