/* ============================================================
   کۆگاکان — ڕووکار
   ڕەنگەکان لە پاڵێتی پشکنیوی بنەڕەتی وەرگیراون:
     خانەی ١ (شین)  #2a78d6 / #3987e5  → کڕین
     خانەی ٣ (ئاوی) #1baf7a / #199e70  → قازانج
   فرۆشتن = کڕین + قازانج، بۆیە ڕەنگێکی بێلایەن وەردەگرێت (تەواوەکە).
   ============================================================ */

:root {
  color-scheme: light;

  --surface-0: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border:    #e2e1dc;
  --border-strong: #cfcec8;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #7a7973;

  --cost:   #2a78d6;
  --profit: #1baf7a;
  --sales:  #0b0b0b;

  --cost-soft:   #e7f0fc;
  --profit-soft: #e2f6ee;

  --danger:    #e34948;
  --danger-bg: #fdecec;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(11, 11, 11, .05), 0 6px 18px rgba(11, 11, 11, .05);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --border:    #32322f;
    --border-strong: #45453f;

    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #93928a;

    --cost:   #3987e5;
    --profit: #199e70;
    --sales:  #ffffff;

    --cost-soft:   #17273a;
    --profit-soft: #133026;

    --danger:    #e66767;
    --danger-bg: #3a1e1e;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.65;
}

a { color: inherit; }

code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: .1em .4em;
  direction: ltr;
  display: inline-block;
}

/* ---------------- سەرەوە ---------------- */

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 20px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--cost);
  color: #fff;
  flex: none;
}

.who {
  color: var(--text-muted);
  font-size: .9rem;
  direction: ltr;
}

/* ---------------- هێڵی ڕێنیشاندەری خوارەوە ---------------- */

.bottomnav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -1px 10px rgba(11, 11, 11, .05);
}

.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 9px 6px 10px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 600;
  /* ناوچەی دەستلێدان بەپێی پێوەری مۆبایل */
  min-height: 56px;
}

.bn-item svg { display: block; }

.bn-item:hover { color: var(--text-secondary); }

.bn-item.is-active { color: var(--cost); }

/* بۆشایی لە خوارەوە تاکو ناوەڕۆک لەژێر هێڵەکەدا نەشاردرێتەوە */
body.has-bottomnav { padding-bottom: 74px; }

/* ---------------- ناوەڕۆک ---------------- */

.wrap {
  max-width: 1160px;
  margin: 0 auto;
  padding: 28px 20px 56px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; margin: 0; }
h3 { font-size: 1rem; margin: 0; }

.muted { color: var(--text-muted); margin: 0; font-size: .9rem; }

/* ناوەڕۆکی لاتینی/ژمارەیی کە نابێت لە ناوەڕاستدا بشکێت (وەک بەروار) */
.nb { white-space: nowrap; }

.section-title {
  margin: 36px 0 14px;
  font-size: 1.05rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .9rem;
  margin-bottom: 10px;
}
.back-link:hover { color: var(--text-primary); }

/* ---------------- فلتەری بەروار ---------------- */

.rangebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 22px;
}

.range-presets { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  text-decoration: none;
  font-size: .87rem;
  padding: 5px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--surface-1);
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.is-active {
  background: var(--text-primary);
  border-color: var(--text-primary);
  color: var(--surface-1);
  font-weight: 600;
}

.range-custom {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .86rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.range-custom input[type="date"] {
  font: inherit;
  font-size: .86rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-1);
  color: var(--text-primary);
  color-scheme: inherit;
}

.range-custom button {
  font: inherit;
  font-size: .86rem;
  padding: 5px 14px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
}
.range-custom button:hover { border-color: var(--text-muted); }

/* ---------------- کارتی ژمارە گەورەکان ---------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.kpi {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

/* هێڵی ڕەنگ لە سەرەوەی کارتەکە — ناسنامەی ژمارەکە */
.kpi::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  height: 3px;
  background: var(--text-muted);
}
.kpi-sales::before  { background: var(--sales); }
.kpi-cost::before   { background: var(--cost); }
.kpi-profit::before { background: var(--profit); }

.kpi-label {
  font-size: .9rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.2;
  direction: ltr;
  text-align: right;
}

.kpi-cost   .kpi-value { color: var(--cost); }
.kpi-profit .kpi-value { color: var(--profit); }

.kpi-unit {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ---------------- کارتی کۆگاکان ---------------- */

.store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.store-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.store-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tag {
  font-size: .72rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  direction: ltr;
  white-space: nowrap;
}

.mini-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
}

.mini { margin: 0; }

.mini dt {
  font-size: .76rem;
  color: var(--text-muted);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* خاڵی ڕەنگ بۆ ناسنامە — دەق هەمیشە بە ڕەنگی دەق دەمێنێتەوە */
.mini dt::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--text-muted);
  flex: none;
}
.mini.is-sales  dt::before { background: var(--sales); }
.mini.is-cost   dt::before { background: var(--cost); }
.mini.is-profit dt::before { background: var(--profit); }

.mini dd {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  direction: ltr;
  text-align: right;
}
.mini.is-cost   dd { color: var(--cost); }
.mini.is-profit dd { color: var(--profit); }

.store-meta {
  font-size: .82rem;
  color: var(--text-muted);
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.dot { opacity: .5; }

/* کۆگایەک کە هێشتا دیتابەیسی بۆ دانەنراوە */
.store-card.is-pending {
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}

.store-card.is-pending h3 { color: var(--text-muted); }

.store-card.is-pending .mini dd {
  color: var(--text-muted);
  font-weight: 600;
}

.store-card.is-pending .mini dt::before { background: var(--border-strong); }

.tag-pending {
  color: var(--text-muted);
  background: transparent;
  border-style: dashed;
}

.store-link {
  margin-top: auto;
  align-self: flex-start;
  text-decoration: none;
  font-size: .87rem;
  font-weight: 600;
  color: var(--cost);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.store-link:hover { text-decoration: underline; }

/* ---------------- خشتە ---------------- */

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}

.legend {
  display: flex;
  gap: 14px;
  font-size: .8rem;
  color: var(--text-secondary);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}
.legend .sw-cost   { background: var(--cost); }
.legend .sw-profit { background: var(--profit); }

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .89rem;
}

th, td {
  padding: 11px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

td.num { direction: ltr; text-align: left; font-variant-numeric: tabular-nums; }
td.name { white-space: normal; min-width: 180px; text-align: right; }
td.c-cost   { color: var(--cost);   font-weight: 600; }
td.c-profit { color: var(--profit); font-weight: 600; }

tfoot td {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 2px solid var(--border-strong);
}

/* ------- بارە کۆکراوەکان: کڕین + قازانج = فرۆشتن ------- */

.bar-cell { width: 200px; min-width: 160px; }

.bar {
  display: flex;
  height: 12px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-2);
  /* ٢px کەلێنی ڕووکار لە نێوان دوو بەشەکە */
  gap: 2px;
}

.bar-seg { height: 100%; }
.bar-seg.s-cost   { background: var(--cost); border-radius: 4px 0 0 4px; }
.bar-seg.s-profit { background: var(--profit); border-radius: 0 4px 4px 0; }

/* لە RTL دا سەرەتای بار لە ڕاستەوە دەبێت */
[dir="rtl"] .bar-seg.s-cost   { border-radius: 0 4px 4px 0; }
[dir="rtl"] .bar-seg.s-profit { border-radius: 4px 0 0 4px; }

/* ---------------- زانیاری زیادە ---------------- */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 12px;
}

.fact {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.fact dt {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.fact dd {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  direction: ltr;
  text-align: right;
}

/* ---------------- ئاگاداری ---------------- */

.alert {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 12px 15px;
  font-size: .9rem;
  margin-bottom: 18px;
}

.alert-sm { margin: 0; font-size: .85rem; padding: 9px 12px; }

.note {
  margin-top: 26px;
  font-size: .85rem;
  color: var(--text-muted);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  line-height: 1.8;
}

.note strong { color: var(--text-secondary); }

.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ---------------- پێداچوونەوە ---------------- */

.foot {
  max-width: 1160px;
  margin: 0 auto;
  padding: 20px;
  color: var(--text-muted);
  font-size: .8rem;
  display: flex;
  gap: 8px;
  justify-content: center;
  border-top: 1px solid var(--border);
}

/* ---------------- چوونەژوورەوە ---------------- */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--surface-0);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 34px 30px;
  text-align: center;
}

.login-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--cost);
  color: #fff;
  display: grid;
  place-items: center;
}

.login-card h1 { font-size: 1.35rem; margin: 0 0 4px; }

.login-sub {
  color: var(--text-muted);
  font-size: .88rem;
  margin: 0 0 22px;
}

.login-card form { text-align: right; }

.login-card label {
  display: block;
  font-size: .84rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 5px;
}

.login-card input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  margin-bottom: 15px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--surface-1);
  color: var(--text-primary);
}

.login-card input:focus {
  outline: 2px solid var(--cost);
  outline-offset: 1px;
  border-color: var(--cost);
}

.login-card button {
  width: 100%;
  font: inherit;
  font-weight: 700;
  padding: 11px;
  border: 0;
  border-radius: 9px;
  background: var(--cost);
  color: #fff;
  cursor: pointer;
  margin-top: 4px;
}
.login-card button:hover { filter: brightness(1.07); }

.login-card .alert { text-align: right; }

/* ---------------- دڵنیاکردنەوەی دەرچوون ---------------- */

.confirm-wrap {
  display: grid;
  place-items: center;
  min-height: 58vh;
  padding: 20px 0;
}

.confirm-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.confirm-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: var(--danger-bg);
  color: var(--danger);
}

.confirm-card h1 { font-size: 1.25rem; margin: 0 0 8px; }

.confirm-text {
  color: var(--text-secondary);
  font-size: .92rem;
  margin: 0 0 24px;
  line-height: 1.8;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.confirm-actions form { margin: 0; }

.btn-danger,
.btn-cancel {
  font: inherit;
  font-weight: 700;
  font-size: .92rem;
  padding: 10px 22px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-block;
  text-decoration: none;
  line-height: 1.5;
}

.btn-danger {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.07); }

.btn-cancel {
  border: 1px solid var(--border-strong);
  background: var(--surface-1);
  color: var(--text-secondary);
}
.btn-cancel:hover { border-color: var(--text-muted); color: var(--text-primary); }

/* ---------------- مۆبایل ---------------- */

@media (max-width: 760px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.7rem; }
  .topbar-inner { height: auto; padding: 12px 16px; flex-wrap: wrap; }
  .wrap { padding: 20px 16px 44px; }
  .bar-cell { display: none; }
}

@media print {
  .topbar, .bottomnav, .rangebar, .store-link, .foot, .back-link { display: none; }
  body { background: #fff; }
  .kpi, .store-card, .panel { box-shadow: none; }
}
