/* ─── DESIGN TOKENS (iOS-style) ─── */
:root {
  --bg: #F2F2F7;
  --bg-elev: #FFFFFF;
  --bg-grouped: #FFFFFF;
  --text: #000000;
  --text-secondary: #3C3C43;
  --text-tertiary: #8E8E93;
  --separator: rgba(60, 60, 67, 0.18);
  --primary: #6B2D8B;       /* brand purple (Vienawell-inspired) */
  --primary-light: #B58CD0;
  --accent-gold: #C9A84C;
  --accent-pink: #F2C4DE;
  --success: #34C759;
  --warning: #FF9500;
  --danger: #FF3B30;
  --info: #007AFF;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);

  --header-h: 56px;
  --tabbar-h: 64px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Nền gradient rất nhẹ, trung tính (sáng) */
  --bg-gradient: linear-gradient(180deg, #F7F7FA 0%, #EFEFF3 100%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --bg-elev: #1B1E24;
    --bg-grouped: #1B1E24;
    --text: #FFFFFF;
    --text-secondary: #EBEBF5;
    --text-tertiary: #8E8E93;
    --separator: rgba(120, 120, 128, 0.24);
    /* Nền xám-than trung tính, gradient rất nhẹ (gần phẳng) → chữ rõ, dịu mắt */
    --bg-gradient: linear-gradient(180deg, #16181D 0%, #0E0F13 100%);
  }
}

/* ─── RESET ─── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html {
  height: 100%;
  background: var(--bg-gradient) no-repeat;
  background-attachment: fixed;
  background-color: var(--bg);   /* fallback + vùng overscroll */
}
body {
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: transparent;       /* để lộ gradient của html */
  color: var(--text);
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ─── LAYOUT ─── */
.safe-top    { height: var(--safe-top); background: var(--bg-elev); }
.safe-bottom { height: var(--safe-bottom); background: var(--bg-elev); }

.app-header {
  position: sticky; top: var(--safe-top); z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  background: var(--bg-elev);
  border-bottom: 0.5px solid var(--separator);
  backdrop-filter: saturate(180%) blur(20px);
}
.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--primary);
  transition: background 0.15s;
}
.icon-btn:active { background: rgba(107, 45, 139, 0.12); }

.product-pill {
  flex: 1;
  height: 40px;
  padding: 0 16px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--bg);
  border-radius: 20px;
  font-weight: 600; font-size: 15px;
  color: var(--text);
}
.product-pill:active { opacity: 0.6; }

.app-main {
  min-height: calc(100vh - var(--header-h) - var(--tabbar-h) - var(--safe-top) - var(--safe-bottom));
  padding-bottom: 24px;
}

.loading {
  padding: 40px;
  text-align: center;
  color: var(--text-tertiary);
}

/* ─── BOTTOM TAB BAR ─── */
.tab-bar {
  position: sticky; bottom: var(--safe-bottom); z-index: 50;
  height: var(--tabbar-h);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg-elev);
  border-top: 0.5px solid var(--separator);
  backdrop-filter: saturate(180%) blur(20px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--text-tertiary);
  font-size: 10px; font-weight: 500;
  padding-top: 6px;
}
.tab.active { color: var(--primary); }
.tab svg { stroke: currentColor; }
.tab span { letter-spacing: -0.02em; }

/* ─── COMMON VIEW BLOCKS ─── */
.view { padding: 16px; }
.view h1 {
  font-size: 34px; font-weight: 800; letter-spacing: -0.02em;
  margin: 8px 0 16px;
}
.view h2 {
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
  margin: 24px 0 8px;
}
.section-title {
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  color: var(--text-tertiary);
  margin: 24px 16px 8px;
  letter-spacing: 0.04em;
}

/* Card lists (iOS inset-grouped style) */
.list {
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  margin: 0 0 16px;
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  min-height: 56px;
  border-bottom: 0.5px solid var(--separator);
  font-size: 16px;
}
.row:last-child { border-bottom: none; }
.row:active { background: var(--bg); }
.row-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white;
  flex-shrink: 0;
  font-weight: 700;
}
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 500; }
.row-sub { font-size: 13px; color: var(--text-tertiary); margin-top: 2px; }
.row-chevron {
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-tertiary);
  border-bottom: 2px solid var(--text-tertiary);
  transform: rotate(-45deg);
  flex-shrink: 0;
}

/* Cards */
.card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow-sm);
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.card-sub { font-size: 13px; color: var(--text-tertiary); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 50px;
  padding: 0 24px;
  border-radius: var(--radius-md);
  font-weight: 600; font-size: 17px;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--primary); color: white; width: 100%; }
.btn-secondary { background: var(--bg-elev); color: var(--primary); width: 100%; }
.btn-danger { background: var(--danger); color: white; width: 100%; }

/* Badges */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: rgba(52, 199, 89, 0.15); color: var(--success); }
.badge-warning { background: rgba(255, 149, 0, 0.15); color: var(--warning); }
.badge-danger  { background: rgba(255, 59, 48, 0.15); color: var(--danger); }
.badge-info    { background: rgba(0, 122, 255, 0.15); color: var(--info); }
.badge-neutral { background: var(--bg); color: var(--text-tertiary); }

/* Stage card grid (Pipeline view) */
.stage-grid {
  display: grid; grid-template-columns: 1fr;
  gap: 12px;
}
.stage-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex; gap: 14px; align-items: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s;
}
.stage-card:active { transform: scale(0.98); }
.stage-num {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.stage-body { flex: 1; min-width: 0; }
.stage-name { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.stage-desc { font-size: 13px; color: var(--text-tertiary); margin-top: 2px; }

/* Colors for 7 stages */
.stage-1 { background: linear-gradient(135deg, #FF9500, #FF6B00); }
.stage-2 { background: linear-gradient(135deg, #5E5CE6, #5856D6); }
.stage-3 { background: linear-gradient(135deg, #FF2D55, #FF375F); }
.stage-4 { background: linear-gradient(135deg, #34C759, #30B350); }
.stage-5 { background: linear-gradient(135deg, #007AFF, #0051D5); }
.stage-6 { background: linear-gradient(135deg, #AF52DE, #8E44AD); }
.stage-7 { background: linear-gradient(135deg, #FFD60A, #C9A84C); color: #4A0820; }

/* Empty state */
.empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-tertiary);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-title { font-weight: 600; font-size: 17px; color: var(--text-secondary); margin-bottom: 4px; }
.empty-desc { font-size: 14px; line-height: 1.4; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 16px 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-elev);
  border: none;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: 2px solid var(--primary); }
.form-textarea { min-height: 100px; resize: vertical; }
