/*
 * MultiStageTimers — Kitchen Coordination Tool
 * Touch-first design for iPad/desktop kitchen use
 */

/* === Reset & Base === */

*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --color-bg: #fafaf8;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #6b6b6b;
  --color-border: #e0ddd8;
  --color-primary: #2d6a4f;
  --color-primary-hover: #1b4332;
  --color-danger: #c1292e;
  --color-danger-hover: #9b1d20;
  --color-warning: #e09f3e;
  --color-success: #2d6a4f;

  /* Recipe color chips */
  --recipe-0: #4361ee;
  --recipe-1: #e07a5f;
  --recipe-2: #81b29a;
  --recipe-3: #f2cc8f;
  --recipe-4: #9b5de5;
  --recipe-5: #00bbf9;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);

  --tap-target: 44px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Menlo", "Monaco", monospace;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  padding: 0;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* === Typography === */

h1 { font-size: 1.75rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.35rem; margin: 1.5rem 0 0.5rem; color: var(--color-text); }
h3 { font-size: 1.1rem; margin: 1.25rem 0 0.5rem; }
p { margin: 0 0 0.75rem; line-height: 1.5; }
a { color: var(--color-primary); }

/* === Layout === */

main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
}

/* === Navigation === */

.top-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.top-nav strong {
  margin-right: auto;
  font-size: 1.1rem;
}

.top-nav a {
  text-decoration: none;
  color: var(--color-text);
  padding: 0.5rem 0;
  min-height: var(--tap-target);
  display: flex;
  align-items: center;
}

.top-nav form {
  display: inline;
}

.top-nav button {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.5rem 0;
  min-height: var(--tap-target);
}

/* === Flash Messages === */

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.flash-alert {
  background: #fde8e8;
  color: var(--color-danger);
  border: 1px solid #f5c6c6;
}

.flash-notice {
  background: #e8f5e9;
  color: var(--color-success);
  border: 1px solid #c8e6c9;
}

/* === Buttons === */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target);
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  user-select: none;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover { background: #f0eeeb; }

.btn-primary {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text-muted);
}

.btn-danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

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

.btn-small {
  min-height: 36px;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

.btn-done {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 0.75rem 1.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  touch-action: manipulation;
  animation: pulse-done 2s ease-in-out infinite;
}

.btn-done:hover { background: var(--color-primary-hover); }

@keyframes pulse-done {
  0%, 100% { box-shadow: 0 0 0 0 rgba(45, 106, 79, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(45, 106, 79, 0); }
}

/* === Forms === */

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="datetime-local"],
.form-group textarea,
.form-group select {
  width: 100%;
  min-height: var(--tap-target);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--color-surface);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.login-form {
  max-width: 400px;
  margin: 2rem auto;
}

.login-form input[type="submit"] {
  width: 100%;
  min-height: var(--tap-target);
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

.error-messages {
  background: #fde8e8;
  border: 1px solid #f5c6c6;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.error-messages h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--color-danger);
}

.error-messages ul {
  margin: 0;
  padding-left: 1.25rem;
}

/* === Recipe List === */

.recipe-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.recipe-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.recipe-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}

.recipe-card h2 a {
  text-decoration: none;
  color: var(--color-text);
}

.recipe-meta {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin: 0 0 0.5rem;
}

.recipe-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* === Recipe Steps (Show) === */

.step-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.step-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.step-item:last-child { border-bottom: none; }

.step-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.step-badge-timed, .step-item.step-timed .step-badge {
  background: #e3f2fd;
  color: #1565c0;
}

.step-badge-action, .step-item.step-action .step-badge {
  background: #fff3e0;
  color: #e65100;
}

.step-duration {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.step-instruction {
  width: 100%;
  margin: 0.25rem 0 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* === Recipe Form (Steps) === */

.step-fields {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.step-fields-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.step-fields-row .step-name { flex: 2; min-width: 150px; }
.step-fields-row .step-type { flex: 0 0 120px; }
.step-fields-row .step-duration { flex: 1; min-width: 140px; }
.step-fields-row .step-estimated-duration { flex: 1; min-width: 140px; }

.step-fields-detail {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}

.duration-inputs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.duration-inputs span {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.duration-part {
  width: 60px;
  min-height: var(--tap-target);
  text-align: center;
}

/* === Recipe Selection (New Session) === */

.recipe-selection {
  display: grid;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.recipe-checkbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: var(--tap-target);
}

.recipe-checkbox input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* === Dashboard === */

.active-sessions {
  margin-bottom: 2rem;
}

.session-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}

.session-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.session-card h2 a {
  text-decoration: none;
  color: var(--color-text);
}

.session-card.session-completed {
  display: flex;
  justify-content: space-between;
  align-items: center;
  opacity: 0.7;
}

.serving-time {
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

.dashboard-actions {
  margin-top: 1.5rem;
}

.quick-start {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.recent-sessions {
  margin-top: 2rem;
}

.recent-sessions summary {
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0.5rem 0;
}

/* === Session Show === */

.session-header {
  margin-bottom: 1.5rem;
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.session-recipes-summary {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.session-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.start-hint {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

/* Status badges */
.badge-planned { color: var(--color-text-muted); font-weight: 600; }
.badge-active { color: var(--color-primary); font-weight: 600; }
.badge-paused { color: var(--color-warning); font-weight: 600; }
.badge-completed { color: var(--color-success); font-weight: 600; }
.badge-cancelled { color: var(--color-text-muted); font-weight: 600; text-decoration: line-through; }

/* === Recipe Chips (color-coded) === */

.recipe-chip {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
}

.recipe-0 { background: var(--recipe-0); }
.recipe-1 { background: var(--recipe-1); }
.recipe-2 { background: var(--recipe-2); color: var(--color-text); }
.recipe-3 { background: var(--recipe-3); color: var(--color-text); }
.recipe-4 { background: var(--recipe-4); }
.recipe-5 { background: var(--recipe-5); }

/* === Timeline === */

.timeline {
  margin-top: 1rem;
}

.timeline h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 1.25rem 0 0.5rem;
}

.timeline-section {
  display: grid;
  gap: 0.5rem;
}

.timeline-hint {
  text-align: center;
  color: var(--color-text-muted);
  padding: 2rem 0;
  font-size: 1.1rem;
}

.timeline-completed {
  margin-top: 1.5rem;
}

.timeline-completed summary {
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0.5rem 0;
}

/* === Timeline Steps === */

.timeline-step {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.timeline-step.step-active,
.timeline-step.step-waiting_for_user {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.timeline-step.step-completed {
  opacity: 0.6;
  background: var(--color-bg);
}

.timeline-step.step-skipped {
  opacity: 0.4;
  text-decoration: line-through;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.step-name {
  font-size: 1.05rem;
}

.step-body {
  margin-top: 0.5rem;
}

.step-countdown {
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
  padding: 0.5rem 0;
}

.step-time {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.step-completed-at {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.step-details {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.step-details summary {
  cursor: pointer;
  color: var(--color-primary);
  font-size: 0.85rem;
}

.step-details p {
  margin: 0.5rem 0 0;
  color: var(--color-text-muted);
}

/* === Serving Time Banner === */

.serving-countdown {
  text-align: center;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
}

.serving-countdown .time {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
}

.serving-countdown.behind-schedule {
  border-color: var(--color-warning);
  background: #fff8e1;
}

/* === Step Variants === */

.step-variants-list {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
  width: 100%;
}

.variant-chip {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  background: #e8eaf6;
  color: #283593;
}

.variant-selection {
  margin: 0.75rem 0;
}

.variant-selection .form-group {
  margin-bottom: 0.75rem;
}

/* === Session Notes & History === */

.session-notes {
  margin-top: 2rem;
}

.notes-form textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  resize: vertical;
}

.history-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.history-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.history-header h2 a {
  text-decoration: none;
  color: var(--color-text);
}

.history-date {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.history-notes {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-style: italic;
}

/* === Recurring Tasks === */

.recurring-tasks-dashboard {
  margin-bottom: 1.5rem;
}

.task-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.task-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.task-card.task-overdue {
  border-color: var(--color-warning);
  background: #fff8e1;
}

.task-card.task-critical {
  border-color: var(--color-danger);
  background: #fde8e8;
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.task-interval {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.task-description {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin: 0.25rem 0 0.5rem;
}

.task-status {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}

.task-due {
  font-weight: 600;
  color: var(--color-text-muted);
}

.task-due.overdue {
  color: var(--color-danger);
}

.task-last-done {
  color: var(--color-text-muted);
}

.task-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

/* === Focus Mode === */

body.focus-mode {
  background: #0a0a0a;
  color: #f0f0f0;
}

body.focus-mode .top-nav {
  display: none;
}

body.focus-mode main {
  max-width: 100%;
  padding: 1rem;
}

body.focus-mode .session-header {
  text-align: center;
}

body.focus-mode .session-meta,
body.focus-mode .session-recipes-summary {
  justify-content: center;
}

body.focus-mode .session-controls {
  justify-content: center;
}

body.focus-mode .timeline-step {
  background: #1a1a1a;
  border-color: #333;
  color: #f0f0f0;
}

body.focus-mode .timeline-step.step-active,
body.focus-mode .timeline-step.step-waiting_for_user {
  border-color: #4ade80;
  background: #0f1f0f;
}

body.focus-mode .step-countdown {
  font-size: 5rem;
  color: #4ade80;
  text-align: center;
}

body.focus-mode .step-name {
  font-size: 1.5rem;
}

body.focus-mode .step-instruction {
  font-size: 1.15rem;
  color: #ccc;
}

body.focus-mode .step-time,
body.focus-mode .step-completed-at {
  color: #888;
}

body.focus-mode .timeline-step.step-completed {
  background: #111;
  border-color: #222;
}

body.focus-mode .btn-done {
  min-height: 80px;
  font-size: 1.75rem;
  background: #4ade80;
  color: #0a0a0a;
}

body.focus-mode .btn-done:hover {
  background: #22c55e;
}

body.focus-mode .serving-countdown {
  background: #1a1a1a;
  border-color: #333;
  color: #f0f0f0;
}

body.focus-mode .serving-countdown .time {
  font-size: 2rem;
  color: #4ade80;
}

body.focus-mode .timeline-section.timeline-pending {
  display: none;
}

body.focus-mode .timeline-completed {
  display: none;
}

body.focus-mode .timeline h2 {
  color: #888;
  text-align: center;
  display: none;
}

body.focus-mode .timeline-now {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

body.focus-mode .timeline-now .timeline-step {
  width: 100%;
  max-width: 700px;
}

/* === Responsive === */

@media (max-width: 600px) {
  main { padding: 0.75rem; }
  h1 { font-size: 1.4rem; }

  .step-countdown { font-size: 2rem; }

  .step-fields-row {
    flex-direction: column;
    align-items: stretch;
  }

  .step-fields-row .step-type { flex: 1; }

  .recipe-actions { flex-direction: column; }
  .recipe-actions .btn { width: 100%; }

  .session-controls { flex-direction: column; }
  .session-controls .btn { width: 100%; }
}

/* Large screens — more room for countdown */
@media (min-width: 768px) {
  .step-countdown {
    font-size: 3rem;
  }

  main {
    max-width: 900px;
    padding: 1.5rem 2rem 4rem;
  }

  body.focus-mode .step-countdown {
    font-size: 8rem;
  }

  body.focus-mode .step-name {
    font-size: 2rem;
  }

  body.focus-mode .step-instruction {
    font-size: 1.5rem;
  }

  body.focus-mode .btn-done {
    min-height: 100px;
    font-size: 2.5rem;
  }
}
