/* =========================================================
   کافه وال — چیدمان کلی (Shell / Grid / Topbar / Sidebar)
   هویت: لایت، گرم، فضای سفید زیاد و سایه‌های نرم
   ========================================================= */

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

html { height: 100%; }

body {
  min-height: 100%;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.75;
  color: var(--text-1);
  background-color: var(--bg-0);
  /* بافت گرم و ملایم پس‌زمینه */
  background-image:
    radial-gradient(1100px 620px at 92% -12%, rgba(185, 122, 61, 0.10), transparent 62%),
    radial-gradient(900px 600px at -14% 106%, rgba(139, 90, 60, 0.07), transparent 58%),
    linear-gradient(180deg, #F7F2EB 0%, #F4EEE5 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

body.modal-lock { overflow: hidden; }

img, svg { display: block; }

a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft-2); color: var(--text-1); }

/* ---- اسکرول‌بار ظریف ---- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: #C9B9A6; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---- اسکلت برنامه: نوار بالا + سایدبار + محتوا ---- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ================= نوار بالایی ================= */
.topbar {
  grid-column: 1 / -1;
  z-index: var(--z-topbar);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(63, 44, 29, 0.03);
}

.brand { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }

.brand-mark {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent-2), var(--accent-deep));
  box-shadow: var(--shadow-accent), var(--inset-hairline);
}
.brand-mark .icon { width: 23px; height: 23px; }

.brand-text { min-width: 0; }
.brand-name {
  font-size: 17px; font-weight: 800; letter-spacing: 0.2px;
  color: var(--text-1);
  line-height: 1.3;
}
.brand-tag { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.4; }

/* ساعت و تاریخ در مرکز */
.topbar-clock {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px 16px;
  border-radius: var(--r-pill);
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap;
}
.topbar-clock .icon { width: 16px; height: 16px; color: var(--accent); }
.topbar-clock .clock-time { font-weight: 800; color: var(--text-1); font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.topbar-clock .clock-sep { color: var(--line-strong); margin: 0 2px; }

.topbar-end { display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end; min-width: 0; }

.sync-chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 36px; padding: 0 13px;
  border-radius: var(--r-pill);
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 700; white-space: nowrap;
  cursor: default;
}
.sync-chip .icon { width: 15px; height: 15px; color: var(--warning); }
.sync-chip.is-synced .icon { color: var(--success); }
.sync-chip.is-synced { color: var(--text-3); }

/* پروفایل */
.profile { position: relative; }
.profile-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 12px; border-radius: var(--r-pill);
  background: var(--bg-1); border: 1px solid var(--line);
  color: var(--text-1); font: inherit; cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.profile-btn:hover { border-color: var(--line-strong); box-shadow: var(--shadow-2); }
.profile-name { font-size: var(--fs-sm); font-weight: 800; line-height: 1.3; }
.profile-role { font-size: 10px; color: var(--text-3); line-height: 1.2; }
.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-deep));
}
.profile-menu {
  position: absolute; top: calc(100% + 10px); inset-inline-end: 0;
  min-width: 200px; padding: 7px;
  border-radius: var(--r-md);
  background: var(--bg-1);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  display: none; z-index: calc(var(--z-topbar) + 5);
}
.profile-menu.open { display: block; animation: pop-in var(--t-fast) var(--ease); }
.profile-menu-head { padding: 9px 11px; border-bottom: 1px solid var(--line); margin-bottom: 7px; }
.profile-menu-head strong { display: block; font-size: var(--fs-sm); }
.profile-menu-head span { font-size: var(--fs-xs); color: var(--text-3); }
.profile-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 11px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-2); font: inherit; font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; text-align: start;
}
.profile-menu button:hover { background: var(--bg-2); color: var(--text-1); }
.profile-menu button[data-logout] { color: var(--danger); }
.profile-menu button[data-logout]:hover { background: var(--danger-soft); }

/* ================= سایدبار ================= */
.sidebar {
  z-index: var(--z-sidebar);
  display: flex; flex-direction: column; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-3);
  background: rgba(255, 255, 255, 0.62);
  backdrop-filter: blur(var(--glass-blur)); -webkit-backdrop-filter: blur(var(--glass-blur));
  border-inline-end: 1px solid var(--line);
  overflow-y: auto;
}

.side-caption {
  font-size: 10px; font-weight: 800; letter-spacing: 1.2px;
  color: var(--text-3); padding: 0 12px; margin-bottom: -6px;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 48px;
  padding: 0 13px;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: transparent; color: var(--text-2);
  font: inherit; font-size: var(--fs-md); font-weight: 700;
  cursor: pointer; text-align: start;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.nav-item .icon { width: 21px; height: 21px; flex: none; }
.nav-item:hover { background: var(--bg-1); color: var(--text-1); box-shadow: var(--shadow-1); }
.nav-item.active {
  background: linear-gradient(120deg, var(--accent-soft-2), var(--accent-soft));
  border-color: var(--accent-border);
  color: var(--accent-deep);
  box-shadow: var(--shadow-1);
}
.nav-badge {
  margin-inline-start: auto;
  min-width: 22px; height: 22px; padding: 0 7px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--warning-soft); border: 1px solid var(--warning-border);
  color: var(--warning); font-size: 11px; font-weight: 800;
}
.nav-badge[hidden] { display: none; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-2); }
.side-version {
  padding: 13px 15px; border-radius: var(--r-md);
  background: var(--bg-1); border: 1px solid var(--line);
  font-size: var(--fs-xs); color: var(--text-3); line-height: 1.9;
  box-shadow: var(--shadow-1);
}
.side-version strong { color: var(--text-2); display: block; font-size: var(--fs-sm); }

/* ================= ناحیه اصلی ================= */
.main { min-width: 0; overflow-y: auto; overflow-x: clip; }

.main-inner {
  max-width: 1440px;
  margin-inline: auto;
  padding: var(--pad-main);
  display: flex; flex-direction: column; gap: var(--sp-5);
}

/* ظرف محتوای هر صفحه — بلوک‌ها باید فاصله‌ی عمودی داشته باشند */
.view { display: flex; flex-direction: column; gap: var(--sp-5); }

/* انیمیشن ورود نرم هر صفحه */
.view-enter { animation: view-in var(--t-med) var(--ease); }
@keyframes view-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.96) translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* سربرگ صفحه */
.page-head { display: flex; align-items: flex-start; gap: var(--sp-4); flex-wrap: wrap; }
.page-head-text { min-width: 0; }
.page-title { margin: 0; font-size: var(--fs-2xl); font-weight: 800; line-height: 1.4; letter-spacing: -0.2px; }
.page-sub { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--text-3); }
.page-head-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }

/* انتخابگر تاریخ — یک کنترل یکپارچه: روز قبل، تاریخ، روز بعد */
.date-selector-group {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: none;
  background: var(--bg-1);
  padding: 4px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}

.date-nav {
  width: 36px;
  height: 36px;
  flex: none;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--accent-deep);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.date-nav .icon { width: 18px; height: 18px; }
.date-nav:hover { background: var(--accent-soft); }
.date-nav:active { background: var(--accent-soft-2); }
.date-nav:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* نمودار مینیمال */
.minimal-chart {
  width: 100%;
  height: auto;
  overflow: visible;
}

.bar-rect {
  transition: opacity 0.3s ease, fill 0.3s ease;
  transform-origin: bottom;
  animation: bar-rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  opacity: 0;
  transform: scaleY(0);
}

.chart-node:hover .bar-rect {
  opacity: 0.85;
}

@keyframes bar-rise {
  from { opacity: 0; transform: scaleY(0); }
  to { opacity: 1; transform: scaleY(1); }
}

.chart-node {
  animation-delay: var(--delay);
}

.bar-val, .bar-label {
  font-family: var(--font);
  pointer-events: none;
  animation: bar-fade 0.4s ease forwards;
  animation-delay: calc(var(--delay) + 0.2s);
  opacity: 0;
}

@keyframes bar-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.chart-wrap {
  position: relative;
  min-height: 220px;
  background: var(--bg-1);
  border-radius: var(--r-lg);
  padding: 15px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1);
}

.date-display {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 118px;
  height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--bg-2);
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.date-display:hover {
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.date-display:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.date-display .icon {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.hidden-date-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.skip-link {
  position: absolute; inset-inline-start: 12px; top: -48px; z-index: 200;
  padding: 8px 16px; border-radius: var(--r-sm);
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: var(--fs-sm);
  transition: top var(--t-fast);
}
.skip-link:focus { top: 12px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ================= ناوبری پایین موبایل ================= */
.bottom-nav {
  display: none;
  position: fixed; inset-inline: 0; bottom: 0; z-index: var(--z-bottomnav);
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  padding: 6px 6px env(safe-area-inset-bottom, 0px);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(22px) saturate(1.4); -webkit-backdrop-filter: blur(22px) saturate(1.4);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 22px rgba(63, 44, 29, 0.06);
  justify-content: space-around; align-items: stretch; gap: 2px;
}
.bottom-nav button {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; border-radius: var(--r-sm);
  color: var(--text-3); font: inherit; font-size: 10px; font-weight: 800;
  cursor: pointer; position: relative;
}
.bottom-nav button .icon { width: 22px; height: 22px; }
.bottom-nav button.active { color: var(--accent-deep); background: var(--accent-soft); }
.bottom-nav .bnav-badge {
  position: absolute; top: 4px; inset-inline-end: 16%;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
  border-radius: var(--r-pill); background: var(--warning); color: #fff;
  font-size: 9px; font-weight: 800;
}
.bottom-nav .bnav-badge[hidden] { display: none; }
