:root {
  --bg: #f8fafc;
  --navy: #0f2942;
  --coral: #f97316;
  --teal: #0d9488;
  --slate: #64748b;
  --danger: #dc2626;
  --card: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 41, 66, 0.06);
  --font-body: "Vazirmatn", Tahoma, sans-serif;
  --font-display: "Estedad", var(--font-body);
}

body {
  font-family: var(--font-body);
}
h1, h2, h3, .brand-name {
  font-family: var(--font-display);
  font-weight: 700;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--navy);
}
body.green .crisis-badge { background: var(--teal); }
body.yellow .crisis-badge { background: var(--coral); }
body.red .crisis-badge { background: var(--danger); }

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.brand-lockup-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-size: 1.05rem; font-weight: 700; }
.brand-subtitle { font-size: 0.72rem; font-weight: 400; opacity: 0.85; font-family: var(--font-body); }
.brand-logo { display: block; flex-shrink: 0; border-radius: 6px; }
.brand-lockup--auth { color: #f8fafc; justify-content: center; margin-bottom: 12px; }
.brand-lockup--auth .brand-subtitle { color: #94a3b8; }
.brand-lockup--header .brand-name { color: var(--navy); }
.brand-lockup--app { color: #fff; }
.brand-lockup--app .brand-subtitle { color: #94a3b8; }

.brand-subtitle-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 2px 6px 2px 4px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.brand-subtitle-btn:hover,
.brand-subtitle-btn:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(148, 163, 184, 0.55);
  outline: none;
}

.brand-subtitle-btn .brand-subtitle {
  opacity: 1;
}

.brand-subtitle-chevron {
  font-size: 0.65rem;
  color: #94a3b8;
  line-height: 1;
}

.brand-lockup-home {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
}

.brand-lockup:has(.brand-subtitle-btn) {
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}
.app-topbar .btn.ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.crisis-badge { color: #fff; padding: 6px 12px; border-radius: 999px; font-size: .85rem; }

.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.hero h1 { font-size: 1.35rem; margin-top: 0; }
.page-title { margin: 0 0 12px; font-size: 1.2rem; }

.btn {
  display: inline-block; border: none; border-radius: var(--radius);
  padding: 12px 16px; font-size: 1rem; cursor: pointer;
  text-decoration: none; text-align: center; font-family: inherit;
}
.btn.primary { background: var(--coral); color: #fff; }
.btn.secondary { background: var(--teal); color: #fff; }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid #94a3b8; }
.btn.success { background: var(--teal); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.block { display: block; width: 100%; margin-top: 8px; }
.touch-lg { min-width: 52px; min-height: 52px; font-size: 1.2rem; }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.tabs a {
  padding: 10px 14px; border-radius: 999px; background: #e2e8f0;
  color: var(--navy); text-decoration: none; white-space: nowrap;
}
.tabs a.active { background: var(--navy); color: #fff; }

.progress-bar {
  height: 12px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin: 8px 0;
}
.progress-fill { display: block; height: 100%; background: var(--teal); }
/* سنجهٔ درصد: گرادیان روی کل تراک (پایین=نارنجی، بالا=سبز)، نه فشرده روی عرض fill */
.progress-bar--meter {
  direction: ltr;
}
.progress-bar--meter > .progress-fill {
  --progress-track: max(var(--progress, 100), 1);
  background: linear-gradient(90deg, var(--coral), var(--teal));
  background-repeat: no-repeat;
  background-position: left center;
  background-size: calc(100% * 100 / var(--progress-track)) 100%;
}

/* سنجهٔ باتری (segment_meter): مواجهه / EPA */
.segment-meter {
  display: inline-flex;
  align-items: stretch;
  gap: 3px;
  padding: 3px 4px;
  width: min(100%, 96px);
  min-height: 18px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  direction: ltr;
}
.segment-meter__cell {
  flex: 1 1 0;
  min-width: 0;
  height: 12px;
  border-radius: 3px;
  background: #e2e8f0;
}
/* رنگ سلول پر فقط از tier — بدون tier پیش‌فرض teal نداریم */
.segment-meter--tier-red .segment-meter__cell--filled {
  background: var(--danger);
}
.segment-meter--tier-yellow .segment-meter__cell--filled {
  background: var(--coral);
}
.segment-meter--tier-green .segment-meter__cell--filled {
  background: #059669;
}
.segment-meter__cell--claimed-highlight {
  background: var(--coral);
}
.segment-meter-meta {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #334155;
  line-height: 1.3;
}

.banner.red { background: #fee2e2; color: var(--danger); padding: 12px; border-radius: var(--radius); margin-bottom: 12px; }
.tag, .tags .tag { display: inline-block; background: #f1f5f9; padding: 4px 8px; border-radius: 8px; font-size: .8rem; margin: 2px; }
.non-neg { border-right: 4px solid var(--danger); }
.reason { color: var(--slate); line-height: 1.7; }
.row-btns { display: flex; gap: 8px; align-items: center; }
.patient-row, .prof-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #e2e8f0;
}
.stack-form input, .stack-form select, .stack-form textarea {
  width: 100%; padding: 12px; margin: 6px 0 12px; border-radius: 10px; border: 1px solid #cbd5e1;
  font-size: 1rem;
}
.status-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.status-green { background: var(--teal); color: #fff; }
.status-yellow { background: var(--coral); color: #fff; }
.status-red { background: var(--danger); color: #fff; }
.status-buttons .btn.status-green,
.status-buttons .btn.status-yellow,
.status-buttons .btn.status-red {
  color: #fff;
}
.status-buttons .btn.status-green:hover,
.status-buttons .btn.status-yellow:hover,
.status-buttons .btn.status-red:hover {
  filter: brightness(0.95);
  color: #fff;
}
.messages .msg { padding: 10px; margin: 8px 16px; border-radius: 8px; background: #ecfdf5; }
.hidden { display: none; }
.app-footer { text-align: center; padding: 16px; color: var(--slate); font-size: .85rem; }
.app-footer a { color: var(--navy); }
.narrow { max-width: 420px; margin: 0 auto; }

@media (min-width: 640px) {
  .app-main { padding: 24px; }
}

/* --- Brand loader (splash + inline) --- */
html.dideban-booting body > :not(#dideban-app-loader) {
  visibility: hidden;
}

.dideban-loader--splash {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.dideban-loader--splash[hidden] {
  display: none;
}

.dideban-loader--inline {
  display: flex;
  justify-content: center;
  margin: 0 auto 20px;
}

.dideban-loader-mark {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  overflow: visible;
}

.dideban-loader-logo {
  display: block;
  width: 80px;
  height: 80px;
  border-radius: 6px;
}

.dideban-loader-signal {
  position: absolute;
  left: calc(100% - 7px);
  top: -59px;
  width: 66px;
  height: 66px;
  overflow: visible;
  pointer-events: none;
  z-index: 2;
}

.dideban-loader-dot {
  fill: var(--coral);
}

.dideban-loader-arc {
  fill: none;
  stroke: var(--coral);
  stroke-width: 2.75;
  stroke-linecap: round;
  opacity: 0;
  animation-duration: 1.2s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

.dideban-loader-arc--1 {
  animation-name: dideban-signal-arc-1;
}

.dideban-loader-arc--2 {
  animation-name: dideban-signal-arc-2;
}

.dideban-loader-arc--3 {
  animation-name: dideban-signal-arc-3;
}

@keyframes dideban-signal-arc-1 {
  0%,
  100% {
    opacity: 0;
  }
  8%,
  75% {
    opacity: 1;
  }
}

@keyframes dideban-signal-arc-2 {
  0%,
  100% {
    opacity: 0;
  }
  8%,
  24% {
    opacity: 0;
  }
  32%,
  75% {
    opacity: 1;
  }
}

@keyframes dideban-signal-arc-3 {
  0%,
  100% {
    opacity: 0;
  }
  32%,
  48% {
    opacity: 0;
  }
  56%,
  75% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dideban-loader-arc {
    animation: dideban-signal-arc-reduced 2s ease-in-out infinite;
    opacity: 0.35;
  }

  .dideban-loader-arc--2 {
    opacity: 0.55;
  }

  .dideban-loader-arc--3 {
    opacity: 0.75;
  }

  @keyframes dideban-signal-arc-reduced {
    0%,
    100% {
      opacity: 0.4;
    }
    50% {
      opacity: 1;
    }
  }
}