/**
 * ParrotPadMD Scratchpad - Mobile-First Styles
 */

/* CSS Variables - matching main site */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --border: #334155;
  --shadow: rgba(0, 0, 0, 0.3);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App container - full viewport with safe areas */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
}

.logo-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 28px;
  height: 28px;
}

.logo-text {
  font-size: 1.125rem;
  font-weight: 600;
}

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

.user-display {
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.usage-display {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  background: var(--bg-tertiary);
  padding: 4px 10px;
  border-radius: 6px;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Sign out button with hover label */
.btn-signout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.75rem;
  font-family: inherit;
}

.btn-signout:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.signout-label {
  display: none;
}

.btn-signout:hover .signout-label {
  display: inline;
}

@media (min-width: 768px) {
  .signout-label {
    display: inline;
  }
}

/* Main content area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: hidden;
  position: relative;
}

/* Transcript container */
.transcript-container {
  flex: 1;
  display: flex;
  min-height: 0;
}

.transcript-area {
  width: 100%;
  height: 100%;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 1.125rem;
  line-height: 1.6;
  resize: none;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.transcript-area:focus {
  border-color: var(--accent);
}

.transcript-area::placeholder {
  color: var(--text-muted);
}

/* Recording state */
.app-container.recording .transcript-area {
  border-color: var(--error);
  background: linear-gradient(var(--bg-secondary), var(--bg-secondary)),
              linear-gradient(var(--error), var(--error));
  background-origin: border-box;
  background-clip: padding-box, border-box;
}

/* Waveform visualization */
.waveform-container {
  display: none;
  justify-content: center;
  align-items: flex-end;
  gap: 6px;
  height: 48px;
  margin: 12px 0;
}

.app-container.recording .waveform-container {
  display: flex;
}

.waveform-bar {
  width: 8px;
  min-height: 8px;
  max-height: 48px;
  background: var(--accent);
  border-radius: 4px;
  transition: height 0.05s ease-out;
}

/* Recording timer */
.recording-timer {
  display: none;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--error);
  margin-bottom: 8px;
}

.app-container.recording .recording-timer {
  display: block;
}

/* Action bar */
.action-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  border-radius: 8px;
}

.btn-action:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

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

.btn-action svg {
  width: 24px;
  height: 24px;
}

/* Record button */
.btn-record {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: var(--bg-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 4px 12px var(--shadow);
}

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

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

.btn-record:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Default state - show mic, hide stop */
.btn-record .mic-icon {
  display: block;
}

.btn-record .stop-icon {
  display: none;
}

/* Recording state for record button */
.app-container.recording .btn-record {
  background: var(--error);
  animation: pulse 1.5s ease-in-out infinite;
}

.app-container.recording .btn-record .mic-icon {
  display: none;
}

.app-container.recording .btn-record .stop-icon {
  display: block;
}

/* Warming-up state (orange, waiting for first transcription) */
.app-container.warming-up .btn-record {
  background: var(--warning);
  animation: pulse-warning 1.5s ease-in-out infinite;
}

.app-container.warming-up .recording-timer {
  color: var(--warning);
}

@keyframes pulse-warning {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
  }
  50% {
    box-shadow: 0 0 0 16px rgba(245, 158, 11, 0);
  }
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 0 0 16px rgba(239, 68, 68, 0);
  }
}

/* Status bar */
.status-bar {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 100px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-tertiary);
  padding: 10px 20px;
  border-radius: 24px;
  box-shadow: 0 4px 12px var(--shadow);
  transition: transform 0.3s ease;
  z-index: 100;
  pointer-events: none;
}

.status-bar.visible {
  transform: translateX(-50%) translateY(0);
}

.status-text {
  font-size: 0.875rem;
  color: var(--text-primary);
}

.status-bar.success {
  background: var(--success);
}

.status-bar.error {
  background: var(--error);
}

/* Offline banner */
.offline-banner {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top) + 60px);
  left: 16px;
  right: 16px;
  background: var(--warning);
  color: var(--bg-primary);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 100;
}

.offline-banner.visible {
  display: flex;
}

/* Copy success state */
.btn-copy.copied {
  color: var(--success);
}

.btn-copy.copied svg {
  stroke: var(--success);
}

/* Tablet and desktop adjustments */
@media (min-width: 768px) {
  .app-main {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
  }

  .transcript-area {
    font-size: 1.25rem;
  }

  .btn-record {
    width: 96px;
    height: 96px;
  }

  .btn-record svg {
    width: 40px;
    height: 40px;
  }

  .action-bar {
    gap: 48px;
  }
}

/* Large screens */
@media (min-width: 1024px) {
  .app-header {
    padding: 16px 24px;
  }

  .app-main {
    max-width: 800px;
    padding: 24px;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .btn-record,
  .waveform-bar,
  .status-bar {
    animation: none;
    transition: none;
  }
}

/* Dark mode is default, but support light mode if system prefers */
@media (prefers-color-scheme: light) {
  /* Keep dark theme for now - medical apps often prefer dark */
}

/* Loading state */
.app-container.loading .transcript-area {
  opacity: 0.5;
  pointer-events: none;
}

/* Processing indicator in transcript */
.processing-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 4px;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Macro Panel */
.macro-panel {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
  width: calc(100% - 32px);
  max-width: 400px;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.macro-panel.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

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

.macro-panel-title {
  font-weight: 600;
  color: var(--text-primary);
}

.macro-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s ease;
}

.macro-panel-close:hover {
  color: var(--error);
}

.macro-list {
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
}

.macro-list::-webkit-scrollbar {
  width: 4px;
}

.macro-list::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 2px;
}

.macro-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.macro-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.macro-item:last-child {
  margin-bottom: 0;
}

.macro-item:hover {
  background: var(--accent);
  color: var(--bg-primary);
}

.macro-item:hover .macro-shortcut {
  background: rgba(255, 255, 255, 0.2);
  color: var(--bg-primary);
}

.macro-shortcut {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.macro-info {
  flex: 1;
  min-width: 0;
}

.macro-name {
  font-weight: 500;
  font-size: 0.875rem;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.macro-trigger {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.macro-item:hover .macro-trigger {
  color: rgba(255, 255, 255, 0.7);
}

.macro-panel-hint {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

.macro-panel-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.7rem;
}

/* Help Panel */
.help-panel {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px var(--shadow);
  width: calc(100% - 32px);
  max-width: 400px;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.help-panel.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

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

.help-panel-title {
  font-weight: 600;
  color: var(--text-primary);
}

.help-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s ease;
}

.help-panel-close:hover {
  color: var(--error);
}

.help-panel-content {
  max-height: 300px;
  overflow-y: auto;
  padding: 12px 16px;
}

.help-section {
  margin-bottom: 16px;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.help-commands {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.help-cmd {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--accent);
  font-family: 'SF Mono', Consolas, monospace;
}

.help-panel-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.help-panel-footer a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
}

.help-panel-footer a:hover {
  text-decoration: underline;
}
