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

:root {
  --bg: #F2F3F7;
  --card-bg: #1A1C25;
  --card-bg2: #12131A;
  --accent: #6C63FF;
  --accent2: #5B5FEF;
  --green: #1FA971;
  --red: #E5484D;
  --orange: #F5A623;
  --cyan: #17C3B2;
  --purple: #9B59B6;
  --text: #1A1C25;
  --text-inv: #F0F0F8;
  --text-muted: #8B8FA8;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.1);
  --header-h: 96px;
  --nav-h: 60px;
}

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

button { cursor: pointer; border: none; background: none; font-family: inherit; }
select { font-family: inherit; }

/* ── Header ──────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: #fff;
  padding: 10px 16px 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.header-row { display: flex; gap: 8px; margin-bottom: 8px; }
.dropdown {
  flex: 1; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1.5px solid #E0E1EA; background: var(--bg);
  font-size: .85rem; color: var(--text);
  appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238B8FA8' fill='none' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px;
}
.period-tabs {
  display: flex; gap: 4px; padding-bottom: 10px; align-items: center;
}
.tab-btn {
  flex: 1; padding: 6px 0; border-radius: 20px;
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
  transition: all .2s;
}
.tab-btn.active { background: var(--accent); color: #fff; }
.notif-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--bg);
  font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Progress Banner ─────────────────────────────────────────────────── */
.progress-banner {
  display: flex; align-items: center; justify-content: space-between;
  background: #2A2C3A; color: var(--text-inv);
  padding: 10px 16px; font-size: .82rem;
}
.badge-in-progress {
  background: var(--orange); color: #fff;
  border-radius: 6px; padding: 2px 8px; font-size: .72rem; font-weight: 700;
}
.hidden { display: none !important; }

/* ── Main scroll area ────────────────────────────────────────────────── */
.main-content {
  padding: 12px 12px calc(var(--nav-h) + 16px);
  min-height: calc(100vh - var(--header-h) - var(--nav-h));
}

/* ── Loading ─────────────────────────────────────────────────────────── */
.loading-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 20px; gap: 16px; color: var(--text-muted);
}
.spinner {
  width: 36px; height: 36px; border: 3px solid #E0E1EA;
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: #fff; border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card-dark {
  background: var(--card-bg); color: var(--text-inv);
  border-radius: var(--radius); padding: 20px; margin-bottom: 12px;
}
.card-title {
  font-size: .7rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px;
}
.card-title-dark { color: rgba(255,255,255,.5); }
.card-heading { font-size: 1.05rem; font-weight: 700; margin-bottom: 2px; }
.card-sub { font-size: .8rem; color: var(--text-muted); }
.card-sub-dark { font-size: .8rem; color: rgba(255,255,255,.45); }

/* ── KPI Header card ─────────────────────────────────────────────────── */
.kpi-card {
  background: linear-gradient(135deg, #1A1C25 0%, #2A2D3E 100%);
  color: var(--text-inv); border-radius: var(--radius);
  padding: 20px; margin-bottom: 12px;
}
.kpi-compare-row {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  font-size: .75rem; color: rgba(255,255,255,.6); margin-bottom: 14px;
}
.kpi-compare-row .positive { color: var(--green); font-weight: 600; }
.kpi-compare-row .negative { color: var(--red); font-weight: 600; }
.kpi-main-row {
  display: flex; justify-content: space-around; margin-bottom: 14px;
}
.kpi-big { text-align: center; }
.kpi-big .val { font-size: 1.4rem; font-weight: 800; }
.kpi-big .lbl { font-size: .7rem; color: rgba(255,255,255,.5); margin-top: 2px; }
.kpi-forecast {
  background: rgba(255,255,255,.08); border-radius: 10px;
  padding: 8px 12px; font-size: .82rem; text-align: center;
}
.kpi-forecast strong { color: var(--green); }
.hint-scroll { text-align: center; font-size: .7rem; color: rgba(255,255,255,.25); margin-top: 10px; }

/* ── Insights carousel ───────────────────────────────────────────────── */
.carousel-wrap { overflow: hidden; margin: 0 -12px; padding: 0 12px; }
.carousel-track {
  display: flex; gap: 10px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none; padding-bottom: 4px;
}
.carousel-track::-webkit-scrollbar { display: none; }
.insight-card {
  min-width: 240px; border-radius: var(--radius);
  padding: 16px; scroll-snap-align: start; flex-shrink: 0;
}
.insight-card.green { background: linear-gradient(135deg, #1A5C40, #1FA971); color: #fff; }
.insight-card.red   { background: linear-gradient(135deg, #5C1A1A, #E5484D); color: #fff; }
.insight-card.orange{ background: linear-gradient(135deg, #5C3A1A, #F5A623); color: #fff; }
.insight-card.blue  { background: linear-gradient(135deg, #1A3058, #4A90D9); color: #fff; }
.insight-badge {
  display: inline-block; font-size: .65rem; font-weight: 800;
  letter-spacing: .1em; background: rgba(255,255,255,.2);
  border-radius: 4px; padding: 2px 6px; margin-bottom: 8px;
}
.insight-title { font-size: .95rem; font-weight: 700; margin-bottom: 4px; }
.insight-sub { font-size: .78rem; opacity: .8; }
.carousel-dots { display: flex; justify-content: center; gap: 5px; margin-top: 8px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #D0D1DC; }
.dot.active { background: var(--accent); }

/* ── Metrics grid ────────────────────────────────────────────────────── */
.metrics-scroll {
  display: flex; overflow-x: auto; gap: 10px; scrollbar-width: none;
  padding-bottom: 4px; margin: 0 -12px; padding-left: 12px; padding-right: 12px;
}
.metrics-scroll::-webkit-scrollbar { display: none; }
.metric-card {
  min-width: 140px; background: #fff; border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); flex-shrink: 0;
}
.metric-icon { font-size: 1.4rem; margin-bottom: 6px; }
.metric-name { font-size: .72rem; color: var(--text-muted); margin-bottom: 4px; }
.metric-val { font-size: 1.2rem; font-weight: 800; }
.metric-change { font-size: .72rem; margin-top: 3px; }
.metric-change.up { color: var(--green); }
.metric-change.down { color: var(--red); }

/* ── Timeline ────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 32px; }
.timeline::before {
  content: ''; position: absolute; left: 12px; top: 0; bottom: 0;
  width: 2px; background: #E0E1EA;
}
.tl-item { position: relative; margin-bottom: 12px; }
.tl-icon {
  position: absolute; left: -26px; top: 12px;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; background: #E8E9F3;
}
.tl-card {
  border-radius: var(--radius-sm); padding: 12px 14px;
  color: #fff; font-size: .82rem;
}
.tl-card.green  { background: linear-gradient(135deg,#1A5C40,#1FA971); }
.tl-card.red    { background: linear-gradient(135deg,#5C1A1A,#E5484D); }
.tl-card.cyan   { background: linear-gradient(135deg,#0E3D3A,#17C3B2); }
.tl-card.dark   { background: linear-gradient(135deg,#2A2C3A,#3E4160); }
.tl-card.purple { background: linear-gradient(135deg,#2E1A5C,#9B59B6); }
.tl-card.orange { background: linear-gradient(135deg,#5C3A1A,#F5A623); }
.tl-title { font-weight: 700; margin-bottom: 2px; }
.tl-date  { font-size: .72rem; opacity: .7; margin-bottom: 4px; }
.tl-detail{ opacity: .85; }

/* ── Channels stacked bar ────────────────────────────────────────────── */
.channel-bar {
  height: 10px; border-radius: 5px; overflow: hidden;
  display: flex; margin-bottom: 12px;
}
.channel-bar-seg { height: 100%; transition: width .4s; }
.channel-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0; border-bottom: 1px solid #F0F1F7;
  font-size: .83rem;
}
.channel-row:last-child { border-bottom: none; }
.channel-name { font-weight: 600; }
.channel-pct  { color: var(--text-muted); margin-left: auto; margin-right: 12px; }
.channel-rev  { font-weight: 700; }

/* ── Price changes ───────────────────────────────────────────────────── */
.price-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.08);
}
.price-item:last-child { border-bottom: none; }
.price-bar-strip {
  width: 4px; height: 40px; border-radius: 2px; flex-shrink: 0;
}
.price-name { font-weight: 600; font-size: .85rem; flex: 1; }
.price-values { text-align: right; }
.price-prev { font-size: .72rem; color: rgba(255,255,255,.45); text-decoration: line-through; }
.price-curr { font-size: .9rem; font-weight: 700; color: var(--red); }
.price-badge {
  font-size: .65rem; font-weight: 800; letter-spacing: .08em;
  background: rgba(229,72,77,.25); color: var(--red);
  border-radius: 4px; padding: 2px 5px;
}

/* ── ABC/BCG ─────────────────────────────────────────────────────────── */
.bcg-summary { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.bcg-summary::-webkit-scrollbar { display: none; }
.bcg-card {
  min-width: 130px; flex-shrink: 0; border-radius: var(--radius-sm);
  padding: 12px; font-size: .8rem;
}
.bcg-card.stars   { background: linear-gradient(135deg,#4A3800,#F5A623); color:#fff; }
.bcg-card.cows    { background: linear-gradient(135deg,#1A3058,#4A90D9); color:#fff; }
.bcg-card.questions{background: linear-gradient(135deg,#2E1A5C,#9B59B6); color:#fff; }
.bcg-card.dogs    { background: linear-gradient(135deg,#2A2C3A,#5A5C7A); color:#fff; }
.bcg-count { font-size: 1.4rem; font-weight: 800; }
.bcg-label { font-weight: 700; margin: 2px 0; }
.bcg-advice{ font-size: .7rem; opacity: .8; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  padding: 5px 12px; border-radius: 20px; font-size: .75rem; font-weight: 600;
  border: 1.5px solid #E0E1EA; color: var(--text-muted); background: #fff;
  transition: all .15s;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.dish-row {
  display: flex; align-items: center; padding: 9px 0;
  border-bottom: 1px solid #F0F1F7; font-size: .82rem; gap: 8px;
}
.dish-row:last-child { border-bottom: none; }
.dish-name { flex: 1; font-weight: 600; }
.dish-qty  { color: var(--text-muted); width: 50px; text-align: right; }
.dish-rev  { font-weight: 700; width: 80px; text-align: right; }
.dish-badge{
  font-size: .62rem; font-weight: 800; border-radius: 4px; padding: 2px 5px;
}
.dish-badge.stars    { background: #FFF3CC; color: #8B6914; }
.dish-badge.cows     { background: #CCE0FF; color: #1A3058; }
.dish-badge.questions{ background: #EDD6FF; color: #4A1A7A; }
.dish-badge.dogs     { background: #EBEBEB; color: #555; }

/* ── Foodcost alerts ─────────────────────────────────────────────────── */
.fc-row {
  padding: 10px 0; border-bottom: 1px solid #F0F1F7; font-size: .83rem;
}
.fc-row:last-child { border-bottom: none; }
.fc-name  { font-weight: 600; margin-bottom: 4px; }
.fc-track { height: 5px; border-radius: 3px; background: #E0E1EA; overflow: hidden; }
.fc-fill  { height: 100%; border-radius: 3px; transition: width .4s; }
.fc-fill.green  { background: var(--green); }
.fc-fill.yellow { background: var(--orange); }
.fc-fill.red    { background: var(--red); }
.fc-pct   { font-size: .75rem; font-weight: 700; }
.fc-pct.green  { color: var(--green); }
.fc-pct.yellow { color: var(--orange); }
.fc-pct.red    { color: var(--red); }

/* ── Forecast calculator ─────────────────────────────────────────────── */
.calc-card {
  background: #fff; border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.slider-wrap { margin: 14px 0; }
.slider-labels {
  display: flex; justify-content: space-between;
  font-size: .68rem; color: var(--text-muted); margin-top: 4px;
}
input[type=range] {
  width: 100%; accent-color: var(--accent);
  height: 6px; border-radius: 3px;
}
.forecast-result {
  background: linear-gradient(135deg,#1A5C40,#1FA971);
  border-radius: var(--radius-sm); padding: 14px; color: #fff; margin-top: 10px;
}
.forecast-val { font-size: 1.3rem; font-weight: 800; margin-bottom: 4px; }
.forecast-delta { font-size: .82rem; opacity: .9; }
.forecast-tip { font-size: .72rem; opacity: .7; margin-top: 6px; }
.restory-footer {
  text-align: center; font-size: .68rem; color: var(--text-muted);
  margin-top: 6px; letter-spacing: .06em;
}

/* ── Chart container ─────────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 180px; margin-top: 10px; }

/* ── Tooltip overlay ─────────────────────────────────────────────────── */
.tooltip-overlay {
  position: fixed; background: rgba(26,28,37,.92); color: #fff;
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: .82rem;
  z-index: 999; pointer-events: none; max-width: 200px;
  box-shadow: 0 4px 20px rgba(0,0,0,.3);
}

/* ── Chat screen ─────────────────────────────────────────────────────── */
.chat-screen {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--header-h) - var(--nav-h));
}
.chat-threads-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; background: #fff; border-bottom: 1px solid #E0E1EA;
}
.chat-threads-list {
  flex: 1; overflow-y: auto; background: #fff;
  border-right: 1px solid #E0E1EA; max-width: 220px;
}
.thread-item {
  padding: 12px; border-bottom: 1px solid #F0F1F7;
  font-size: .82rem; cursor: pointer; transition: background .15s;
}
.thread-item.active { background: #EEF0FF; font-weight: 600; }
.thread-item:hover  { background: #F5F6FB; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; font-size: .84rem; line-height: 1.45; }
.msg.user      { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.assistant { background: #fff; box-shadow: var(--shadow); align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-input-row {
  display: flex; gap: 8px; padding: 10px 12px; background: #fff;
  border-top: 1px solid #E0E1EA;
}
.chat-input {
  flex: 1; border: 1.5px solid #E0E1EA; border-radius: 20px;
  padding: 8px 14px; font-size: .85rem; outline: none; resize: none;
  font-family: inherit;
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-typing { font-size: .78rem; color: var(--text-muted); padding: 0 12px 6px; }
.new-thread-btn {
  padding: 6px 12px; border-radius: 16px; background: var(--accent); color: #fff;
  font-size: .78rem; font-weight: 700;
}

/* ── Management / Notifications modal ───────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.5); display: flex; align-items: flex-end;
}
.modal-sheet {
  background: #fff; width: 100%; border-radius: var(--radius) var(--radius) 0 0;
  max-height: 85vh; overflow-y: auto; padding: 20px 16px 32px;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.modal-title { font-size: 1rem; font-weight: 700; }
.modal-close  { font-size: 1.1rem; color: var(--text-muted); padding: 4px; }
.notif-period-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.notif-tab {
  flex: 1; padding: 7px 0; border-radius: 20px; font-size: .8rem; font-weight: 600;
  border: 1.5px solid #E0E1EA; color: var(--text-muted);
}
.notif-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.form-row { margin-bottom: 14px; }
.form-label { font-size: .78rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.form-input {
  width: 100%; border: 1.5px solid #E0E1EA; border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: .85rem; font-family: inherit; outline: none;
}
.form-input:focus { border-color: var(--accent); }
.form-textarea { min-height: 120px; resize: vertical; }
.next-send-info { font-size: .78rem; color: var(--text-muted); margin-top: 6px; }
.btn-row { display: flex; gap: 8px; margin-top: 16px; }
.btn-primary {
  flex: 1; padding: 11px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-size: .88rem; font-weight: 700;
}
.btn-secondary {
  flex: 1; padding: 11px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--accent); color: var(--accent);
  font-size: .88rem; font-weight: 700; background: transparent;
}
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.toggle { position: relative; width: 46px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; border-radius: 13px;
  background: #CCC; transition: background .2s; cursor: pointer;
}
.toggle-slider::before {
  content: ''; position: absolute; width: 20px; height: 20px;
  left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── FAB ─────────────────────────────────────────────────────────────── */
.fab-group {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + 16px);
  display: flex; flex-direction: column; gap: 10px; z-index: 50;
}
.fab {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.2rem;
  box-shadow: 0 4px 14px rgba(108,99,255,.4);
  display: flex; align-items: center; justify-content: center;
}
.fab-support { background: #2A2C3A; }

/* ── Bottom nav ──────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h); background: #fff;
  border-top: 1px solid #E0E1EA; display: flex; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1; font-size: .78rem; font-weight: 600; color: var(--text-muted);
  transition: all .15s; border-radius: 10px; margin: 6px 4px;
}
.nav-btn.active { background: var(--accent); color: #fff; }

/* ── Editor modal ────────────────────────────────────────────────────── */
.editor-messages { max-height: 35vh; overflow-y: auto; margin-bottom: 12px; }
.editor-msg { padding: 8px 12px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: .82rem; }
.editor-msg.user      { background: #EEF0FF; }
.editor-msg.assistant { background: #F5F6FB; border-left: 3px solid var(--accent); }
.editor-apply-btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  background: var(--green); color: #fff; font-size: .82rem; font-weight: 700;
  margin-top: 6px;
}
.version-badge {
  display: inline-block; font-size: .68rem; background: #EEF0FF;
  color: var(--accent); border-radius: 4px; padding: 2px 6px; font-weight: 700;
}
