/* SOP Trainer EN — Quiet specialty-coffee editorial design system */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=IBM+Plex+Mono:wght@300;400;500&family=Fraunces:opsz,wght@9..144,400;9..144,500&display=swap');

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

:root {
  /* ── Color palette ────────────────────────────── */
  --bg:           #FAF7F2;
  --surface:      #FFFFFF;
  --surface-2:    #F2EDE4;
  --surface-ink:  #1F1A14;
  --text:         #1F1A14;
  --text-2:       #5B544A;
  --text-3:       #9A9183;
  --border:       #E8E1D4;
  --border-s:     #D6CDBA;

  --accent:       #3F704D;
  --accent-soft:  #E6EEE6;
  --accent-ink:   #264A33;
  --accent-light: #A8D0B0;

  --warn:         #B06A1F;
  --warn-soft:    #F7ECDC;
  --warn-ink:     #7A4513;

  --danger:       #A8331F;
  --danger-soft:  #F4E3DE;
  --danger-ink:   #7A2114;

  --info:         #3B5A78;
  --info-soft:    #E4ECF4;
  --info-ink:     #274A6A;

  /* ── Legacy color aliases (kept so existing inline-styled views still resolve) ── */
  --green:        var(--accent);
  --orange:       var(--warn);
  --red:          var(--danger);
  --green-bg:     var(--accent-soft);
  --orange-bg:    var(--warn-soft);
  --red-bg:       var(--danger-soft);

  /* ── Layout / shape ───────────────────────────── */
  --tab-h:        60px;
  --max-w:        480px;

  --r:            12px;
  --r-xs:         4px;
  --r-sm:         8px;
  --r-md:         12px;
  --r-lg:         18px;
  --r-full:       999px;

  /* ── Shadows ──────────────────────────────────── */
  --shadow-sm:    0 1px 2px rgba(31, 26, 20, 0.04), 0 0 0 1px rgba(31, 26, 20, 0.04);
  --shadow-md:    0 4px 16px rgba(31, 26, 20, 0.08), 0 0 0 1px rgba(31, 26, 20, 0.04);
  --shadow-focus: 0 0 0 3px rgba(63, 112, 77, 0.22);

  /* ── Type ─────────────────────────────────────── */
  --mono:    'IBM Plex Mono', ui-monospace, monospace;
  --serif:   'Fraunces', Georgia, 'Times New Roman', serif;
  --sans:    'Inter', -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  max-width: var(--max-w);
  min-height: 100vh;
  position: relative;
  background: var(--bg);
  animation: pageEnter 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── Page shell ──────────────────────────────── */
.page        { padding: 20px 20px calc(var(--tab-h) + 24px); min-height: 100vh; }
.page-notab  { padding: 20px; min-height: 100vh; }

/* ─── Bottom Tab ──────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: var(--max-w);
  height: var(--tab-h);
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.tab-item {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--text-3);
  text-decoration: none;
  border: none; background: none; padding: 0;
  position: relative;
  transition: color 180ms ease;
  font-family: var(--mono);
  font-weight: 500;
}
.tab-item.active        { color: var(--text); }
.tab-item.active::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 2px;
  border-radius: var(--r-full);
  background: var(--accent);
}
.tab-item .tab-icon     { font-size: 20px; line-height: 1; }
@media (max-width: 360px) {
  .tab-item             { font-size: 9px; }
  .tab-item .tab-icon   { font-size: 18px; }
}

/* ─── Cards ───────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 18px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  transition: transform 120ms ease, background 160ms ease;
}
.card:active {
  transform: scale(0.985);
}
.card-dark,
.hero {
  background: linear-gradient(180deg, #2A241B 0%, var(--surface-ink) 100%);
  color: #fff;
  border-radius: var(--r-lg);
  padding: 22px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-md);
  transition: transform 140ms ease;
}
.card-dark:active,
.hero:active {
  transform: scale(0.99);
}

/* ─── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
  cursor: pointer; border: none;
  transition: background 160ms ease, color 160ms ease, border-color 160ms ease, transform 100ms ease;
  text-decoration: none;
  font-family: inherit;
}
.btn:active          { transform: scale(0.97); }
.btn-primary         { background: var(--text); color: var(--bg); }
.btn-primary:hover   { background: var(--accent); }
.btn-accent          { background: var(--accent); color: #fff; }
.btn-accent:hover    { background: var(--accent-ink); }
.btn-outline         {
  background: transparent;
  border: 1px solid var(--border-s);
  color: var(--text);
}
.btn-outline:hover   { background: var(--surface-2); }
.btn-ghost           { background: transparent; color: var(--text-2); }
.btn-ghost:hover     { background: var(--surface-2); color: var(--text); }
.btn-danger          {
  background: transparent;
  border: 1px solid rgba(168, 51, 31, 0.30);
  color: var(--danger);
}
.btn-danger:hover    { background: var(--danger-soft); }
.btn-full            { width: 100%; padding: 14px 18px; }

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

/* ─── Form ────────────────────────────────────── */
.form-group { margin-bottom: 22px; }
.form-label {
  display: block;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
  font-family: var(--mono);
}
.form-input {
  width: 100%;
  padding: 12px 0;
  border: none;
  border-bottom: 1px solid var(--border-s);
  border-radius: 0;
  font-size: 16px; /* prevents iOS zoom */
  font-weight: 400;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  transition: border-color 180ms ease, border-width 0ms;
}
.form-input:focus       {
  border-bottom: 1.5px solid var(--accent);
  padding-bottom: 11.5px; /* keep total height stable when border thickens */
}
.form-input::placeholder { color: var(--text-3); }
textarea.form-input     { padding: 10px 0; resize: vertical; min-height: 80px; font-size: 15px; }
select.form-input       { cursor: pointer; }

/* ─── Progress bar ────────────────────────────── */
.progress-track {
  background: var(--surface-2);
  border-radius: var(--r-full);
  height: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width 480ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── Tags / badges ───────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  font-family: var(--sans);
  line-height: 1.3;
  white-space: nowrap;
}
.tag-outline  {
  background: var(--surface-2);
  color: var(--text-2);
}
.tag-green    {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.tag-orange   {
  background: var(--warn-soft);
  color: var(--warn-ink);
}
.tag-dark     {
  background: var(--text);
  color: var(--bg);
}

/* ─── Section label ───────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 28px 0 12px;
  font-family: var(--mono);
}

/* ─── Info rows ───────────────────────────────── */
.info-row {
  display: flex; align-items: flex-start;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px; line-height: 1.65;
}
.info-row:last-child { border-bottom: none; }
.info-row .info-icon  { flex-shrink: 0; font-size: 13px; opacity: 0.5; margin-top: 2px; }
.info-row .info-text  { flex: 1; }
.info-row .info-label {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--text-3); font-family: var(--mono); margin-bottom: 3px;
  font-weight: 500;
}

/* ─── Alerts ──────────────────────────────────── */
.alert {
  padding: 12px 14px;
  border-radius: var(--r-md);
  font-size: 13px; line-height: 1.55;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.alert-warning {
  background: var(--warn-soft);
  color: var(--warn-ink);
  border-color: rgba(176, 106, 31, 0.20);
}
.alert-success {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-color: rgba(63, 112, 77, 0.20);
}
.alert-error   {
  background: var(--danger-soft);
  color: var(--danger-ink);
  border-color: rgba(168, 51, 31, 0.22);
}

/* ─── Stats grid ──────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface-2);
  padding: 14px 14px;
  text-align: left;
  border-radius: var(--r-md);
}
.stat-card.warn {
  background: var(--warn-soft);
}
.stat-num {
  font-size: 28px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.01em;
  font-family: var(--serif);
  color: var(--text);
}
.stat-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-top: 6px;
  font-family: var(--mono);
  font-weight: 500;
}
.stat-card.warn .stat-num   { color: var(--warn); }
.stat-card.warn .stat-label { color: var(--warn); opacity: 0.8; }

/* ─── Avatar ──────────────────────────────────── */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ─── Header bar ──────────────────────────────── */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 0 0;
  margin-bottom: 22px;
  gap: 12px;
}
.header-title {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.015em;
  font-family: var(--serif);
  line-height: 1.25;
}
.header-sub {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 6px;
  letter-spacing: 0.18em;
  font-family: var(--mono);
  text-transform: uppercase;
}

/* ─── Empty state ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 56px 20px 24px;
}
.empty-state .empty-icon {
  width: 96px; height: 96px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 48px;
}
.empty-state .empty-title {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}
.empty-state .empty-body {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  max-width: 28em;
  margin: 0 auto 20px;
}

/* ─── Skeleton loading ────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, #EEE7D8 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-md);
  min-height: 16px;
}

/* ─── Utility ─────────────────────────────────── */
.flex           { display: flex; }
.flex-between   { display: flex; justify-content: space-between; align-items: center; }
.gap-8          { gap: 8px; }
.gap-12         { gap: 12px; }
.mt-8           { margin-top: 8px; }
.mt-16          { margin-top: 16px; }
.mt-24          { margin-top: 24px; }
.text-secondary { color: var(--text-2); }
.text-sm        { font-size: 13px; }
.text-xs        { font-size: 11px; }
.font-bold      { font-weight: 600; }
.hidden         { display: none !important; }

/* ─── Focus ring (keyboard) ───────────────────── */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--r-sm);
}

/* ─── Keyframes ───────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes pageEnter {
  0%   { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}
@keyframes toastUp {
  0%   { opacity: 0; transform: translateY(40px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ─── Print ───────────────────────────────────── */
@media print {
  .tab-bar, #btn-back-report, #btn-print-report, .btn-reset-progress { display: none !important; }
  body { background: #fff; }
  #app { max-width: 100%; box-shadow: none; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid var(--border); }
}
