/* styles.css — responsive RTL UI for the adjustment calculator */
:root {
  --bg: #f2f5f7;
  --card: #ffffff;
  --ink: #1b2733;
  --muted: #66788a;
  --line: #dde5ec;
  --brand: #0f4c5c;
  --brand-2: #1b7f8e;
  --accent: #e07a1f;
  --ok: #0b7a45;
  --bad: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 42, 67, .08), 0 6px 18px rgba(16, 42, 67, .06);
}

* { box-sizing: border-box; }

/* 'hidden' must beat author display rules (grid/flex/label) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Vazirmatn, "Segoe UI", Tahoma, "B Nazanin", sans-serif;
  font-size: 15px;
  line-height: 1.7;
}

.app-header {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  padding: 18px 16px 14px;
  text-align: center;
}
.app-header h1 { margin: 0; font-size: 1.35rem; letter-spacing: .2px; }
.app-header .sub { margin: 4px 0 0; opacity: .85; font-size: .85rem; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 6px;
  padding: 8px;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs button {
  flex: 1 1 auto;
  min-width: 96px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  border-radius: 999px;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 700;
}

main { max-width: 1180px; margin: 0 auto; padding: 14px; }

.page { display: none; }
.page.active { display: block; }

.mode-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.mode-toggle button {
  flex: 1;
  padding: 10px;
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: #fff;
  cursor: pointer;
  color: var(--muted);
}
.mode-toggle button.active {
  border-color: var(--accent);
  background: #fff6ec;
  color: var(--accent);
}

.period-box {
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 8px 10px 10px;
  margin: 0;
}
.period-box legend { font-size: .8rem; font-weight: 700; color: var(--brand); padding: 0 6px; }
.period-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.info-item { background: #f7fafc; border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; }
.info-item .k { font-size: .72rem; color: var(--muted); font-weight: 700; }
.info-item .v { font-size: .92rem; font-weight: 700; word-break: break-word; }
/* فیلد افقی تمام‌عرض (مثلاً «عنوان پروژه») بالای بقیهٔ اطلاعات */
.info-item.info-full { grid-column: 1 / -1; }

/* results */
.res-hero {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.res-hero .k { font-size: .85rem; opacity: .9; }
.res-hero .v { font-size: 2.1rem; font-weight: 800; line-height: 1.2; }
.res-hero .v1 { font-size: 1rem; opacity: .9; }

.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
/* بلوک دوم نتایج (شرح فصل) از بلوک اول جدا بماند */
.res-grid + .res-grid { margin-top: 8px; }
.res-item { background: #f7fafc; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.res-item .k { font-size: .74rem; color: var(--muted); font-weight: 700; }
.res-item .v { font-size: 1.05rem; font-weight: 800; direction: ltr; text-align: right; }
.res-item .v.dir-rtl { direction: rtl; text-align: right; }
.res-item.ok .v { color: var(--ok); }
.res-item.accent { background: #fff6ec; border-color: #f3d5b2; }
.res-item.accent .v { color: var(--accent); }
.res-item.muted .v { color: var(--muted); }
.res-desc { font-size: .85rem; color: var(--muted); margin-top: 8px; }
.res-error { color: var(--bad); font-weight: 700; }

.factors-box { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }

/* tables */
.table-wrap { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 10px; }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: .84rem; }
.table-wrap th, .table-wrap td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  white-space: nowrap;
  text-align: center;
}
.table-wrap thead th {
  position: sticky;
  top: 0;
  background: #eaf1f6;
  z-index: 2;
  font-size: .78rem;
}
.table-wrap td.fa, .table-wrap th.fa { text-align: right; white-space: normal; min-width: 130px; }
.table-wrap tr:nth-child(even) td { background: #fafcfe; }
.table-wrap td.num { direction: ltr; }

/* جدول «شاخص مصرف کننده کل» — ستون‌های فشرده‌تر:
   هدرهای ماه فارسی هستند و بدون این قانون هر ستون ≥۱۳۰px می‌شود */
.table-wrap table.cpi-grid th,
.table-wrap table.cpi-grid td { padding: 4px 5px; }
.table-wrap table.cpi-grid th.fa,
.table-wrap table.cpi-grid td.fa { min-width: 0; }

/* ستون‌های تاریخ (میلادی/شمسی) در جدول نرخ‌ها — وسط‌چین */
.table-wrap th.date, .table-wrap td.date { text-align: center; white-space: nowrap; }

/* دکمهٔ «پاک کردن بازه» دقیقاً هم‌اندازه و هم‌سطح کادرهای تاریخ کنارش */
#rates-clear {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font-size: .93rem;
  border-width: 1.5px;
  border-color: var(--line);
  background: #eef3f7;
  color: var(--brand);
}

.help-list li { margin-bottom: 8px; }

.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: .78rem;
  padding: 8px 12px 26px;
  line-height: 1.9;
}
.app-footer .dot { padding: 0 6px; opacity: .6; }

/* ---- password lock (only the encrypted build uses it) ---- */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.lock-box {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 22px 18px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
}
.lock-box h2 { margin: 0 0 6px; font-size: 1.05rem; color: var(--brand); }
.lock-box input[type="password"] {
  width: 100%;
  margin: 12px 0 8px;
  padding: 11px 12px;
  font: inherit;
  text-align: center;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
.lock-remember {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 2px 0 14px;
  font-size: .82rem;
  font-weight: 400;
  color: var(--muted);
}
.lock-remember input { width: auto; }
.lock-btn {
  width: 100%;
  padding: 11px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.lock-btn:hover { background: var(--brand-2); }
.lock-msg { min-height: 1.2em; margin: 8px 0 4px; color: var(--bad); font-size: .85rem; }
.ghost-btn {
  margin-top: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: .85rem;
  color: var(--brand);
  background: #eef3f7;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.ghost-btn:hover { background: #e3ecf3; }


.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 1.02rem; color: var(--brand); }

.hint { color: var(--muted); font-size: .8rem; font-weight: 400; }
code { background: #eef3f7; padding: 1px 6px; border-radius: 6px; font-size: .85em; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: 1.05fr .95fr; }
  .results-card { position: sticky; top: 64px; }
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px 12px;
}
label { display: block; font-size: .82rem; color: var(--muted); font-weight: 700; }
.wide { grid-column: 1 / -1; }
select, input[type="text"], input[type="search"] {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  font-size: .93rem;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 10px;
}
select:focus, input:focus { outline: none; border-color: var(--brand-2); }

/* ---------------- نمودارها ---------------- */
.chart-card {
  position: relative;
  min-height: 380px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}
.chart-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: flex-start;
  margin: 0 auto;
  padding: 6px 6px 8px;
  font-size: .84rem;
}
.chart-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 66px;
}
.chart-stats .stat span { font-size: .72rem; color: var(--muted); }
.chart-stats .stat b { font-size: 1.05rem; font-weight: 700; color: var(--brand); }
.chart-stats .stat b.up { color: var(--ok); }
.chart-stats .stat b.down { color: var(--bad); }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 6px auto;
  font-size: .86rem;
}
.chart-legend .item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: #f4f6f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.chart-legend .swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  border: 1px solid rgba(0,0,0,.15);
}
.chart-holder {
  position: relative;
  width: 100%;
}
#ch-canvas {
  width: 100%;
  height: 360px;
  display: block;
  margin: 8px auto;
  background: #fff;
}
.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: rgba(15, 23, 42, .94);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: .78rem;
  line-height: 1.55;
  min-width: 110px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
}
.chart-tip .t { color: #9fb3c8; font-size: .7rem; }
.chart-tip .v { font-size: 1rem; font-weight: 700; color: #fff; }
.chart-tip .s { color: #cbd5e1; font-size: .7rem; }
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f4f6f8;
}
.seg button {
  flex: 1 1 auto;
  font: inherit;
  font-size: .8rem;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button:hover { background: #e9eef2; color: var(--ink); }
.seg button.active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(15, 76, 92, .35);
}
.seg button:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 1px;
}
.chart-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.chart-actions button {
  font-size: .9rem;
  padding: 6px 14px;
}
#ch-hint { margin-top: 6px; }

/* ---------------- قیمت لحظه‌ای (تب نرخ‌های بازار) ---------------- */
.live-box {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  background: #f7fafc;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-top: 10px;
}
.live-main {
  flex: 1 1 240px;
  text-align: center;
  padding: 6px 4px;
}
.live-sym { font-size: .85rem; color: var(--muted); font-weight: 700; }
.live-price {
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--brand);
  direction: ltr;
  line-height: 1.3;
  margin-top: 2px;
}
.live-unit { font-size: .9rem; color: var(--muted); font-weight: 700; }
.live-sub { font-size: .84rem; color: var(--ink); margin-top: 2px; }
.live-when { font-size: .74rem; color: var(--muted); margin-top: 4px; }
.live-cmp {
  flex: 1 1 250px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: center;
}
.live-cmp-title { font-size: .74rem; color: var(--muted); font-weight: 700; }
.live-cmp button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: .84rem;
  padding: 7px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink);
  text-align: right;
}
.live-cmp button:hover { border-color: var(--brand-2); background: #f2f8fa; }
.live-cmp button .v { font-weight: 700; color: var(--brand); direction: ltr; }
@media (max-width: 560px) {
  .live-price { font-size: 1.7rem; }
}
