/* ============ Cafe Kok — mobile-first RTL ============ */
:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #241d15;
  --muted: #8a7c6b;
  --line: #ece4d8;
  --brand: #7c4a21;
  --brand-soft: #f3e7d8;
  --brand-2: #b07a45;
  --ok: #1b7a3d;
  --ok-soft: #e9f7ee;
  --danger: #b3261e;
  --danger-soft: #fdecec;
  --warn-soft: #fff7e0;
  --warn-ink: #8a6100;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 40, 10, .06);
  --tabbar-h: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Vazirmatn, 'Segoe UI', Tahoma, sans-serif;
  line-height: 1.7;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

/* ---------- app bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--brand); color: #fff;
  padding: 12px 16px calc(12px);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  font-size: 17px; font-weight: 700;
  box-shadow: 0 2px 8px rgba(60,40,10,.18);
}
.appbar-icon { color: #fff; text-decoration: none; font-size: 20px; padding: 2px 8px; opacity: .9; }
.appbar-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.appbar-logo { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; background: #fff; padding: 2px; flex: none; }
.appbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- main ---------- */
.view { max-width: 560px; margin: 0 auto; padding: 14px 14px 28px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card h3 { font-size: 14px; margin: 14px 0 8px; color: var(--muted); }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { background: var(--card); border-radius: 20px; box-shadow: 0 10px 40px rgba(60,40,10,.12); padding: 34px 26px; width: 100%; max-width: 360px; text-align: center; }
.login-logo { display: block; width: 88px; height: 88px; margin: 0 auto; object-fit: contain; }
.login-card h1 { font-size: 20px; margin: 8px 0 2px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.login-card label { display: block; text-align: right; font-size: 13px; margin: 12px 0 6px; color: #5c4f40; }
.login-card input {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff;
}
.login-card input:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px; font-size: 13px; margin-top: 12px; }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; margin: 10px 0 5px; color: #5c4f40; }
input[type=text], input[type=number], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); }
input[readonly] { background: #faf7f2; color: var(--muted); }
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; min-width: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn {
  display: inline-block; border: 0; border-radius: 10px; cursor: pointer;
  padding: 12px 18px; font-size: 15px; font-family: inherit; font-weight: 600;
  background: var(--brand-soft); color: var(--brand); text-decoration: none; text-align: center;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- lists ---------- */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  color: var(--ink); text-decoration: none; background: #fff;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--brand-soft); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; }
.row-sub { font-size: 12.5px; color: var(--muted); }
.row-end { text-align: left; white-space: nowrap; }
.row-big { font-weight: 700; font-size: 15px; }
.chev { color: #c9bda9; font-size: 18px; }

/* ---------- home ---------- */
.home-hero { text-align: center; padding: 22px 16px; }
.home-logo { display: block; width: 72px; height: 72px; margin: 0 auto 8px; object-fit: contain; }
.home-hero .big-btn {
  display: block; margin: 14px auto 0; padding: 15px 42px; border-radius: 14px;
  background: var(--brand); color: #fff; font-size: 17px; font-weight: 700; text-decoration: none;
  box-shadow: 0 6px 18px rgba(124,74,33,.35);
}
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-decoration: none; color: var(--ink); display: block; }
.stat-num { font-size: 26px; font-weight: 800; color: var(--brand); }
.stat-label { font-size: 13px; color: var(--muted); }

/* ---------- chips ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 10px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 5px 14px; font-size: 13px; white-space: nowrap; cursor: pointer; font-family: inherit;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- badges ---------- */
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 11.5px; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-soft { background: var(--brand-soft); color: var(--brand); }

/* ---------- search ---------- */
.search { position: relative; margin-bottom: 10px; }
.search input { padding-right: 40px; }
.search::after { content: '🔍'; position: absolute; right: 12px; top: 8px; font-size: 15px; opacity: .5; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { font-variant-numeric: tabular-nums; }

/* ---------- invoice items ---------- */
.inv-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }
.inv-item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.inv-item-head .t { font-size: 13px; color: var(--muted); font-weight: 700; }
.inv-preview { background: var(--brand-soft); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; margin-top: 10px; color: var(--brand); }
.total-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; margin-top: 14px;
  z-index: 5; box-shadow: 0 -2px 14px rgba(0,0,0,.14);
}

/* ---------- success ---------- */
.success-view { text-align: center; padding: 30px 16px; }
.success-ico { font-size: 52px; }
.success-view h2 { color: var(--ok); }
.success-box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-align: right; margin: 16px 0; }

/* ---------- history timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: 0; }
.tl-date { font-size: 12px; color: var(--muted); min-width: 84px; white-space: nowrap; }
.tl-body { flex: 1; }

/* ---------- price highlight ---------- */
.price-final { font-size: 18px; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); font-size: 12.5px; }
.sep { border-top: 1px solid var(--line); margin: 12px 0; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--tabbar-h) + 18px); right: 50%; transform: translateX(50%);
  background: var(--ink); color: #fff; border-radius: 999px; padding: 10px 20px;
  font-size: 14px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw;
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.tab-ico { font-size: 20px; line-height: 1; }
.tab.on { color: var(--brand); font-weight: 700; }
.tab-accent .tab-ico {
  background: var(--brand); color: #fff; width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; margin-top: -26px;
  box-shadow: 0 4px 12px rgba(124,74,33,.4); font-size: 24px; font-weight: 400;
}
.tab-accent.on .tab-ico { background: var(--brand); color: #fff; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }
.skeleton { background: linear-gradient(90deg,#f1ece4 25%,#faf7f2 50%,#f1ece4 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); height: 90px; }
@keyframes sk { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- OCR رسید با هوش مصنوعی ---------- */
.ocr-card { border: 1.5px dashed var(--brand-2); }
.ocr-hint { margin: 4px 0 10px; }
.ocr-status {
  background: var(--brand-soft); color: var(--brand); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; margin-top: 10px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.ocr-status.err { background: var(--danger-soft); color: var(--danger); }
.ocr-spin {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--brand-2); border-top-color: transparent;
  animation: ocrspin .8s linear infinite;
}
@keyframes ocrspin { to { transform: rotate(360deg); } }
.ocr-review-head { font-size: 13px; font-weight: 700; color: #5c4f40; margin: 12px 0 8px; }
.ocr-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; background: #fff; }
.ocr-raw { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 6px; }
.ocr-badge { font-size: 11px; font-weight: 700; border-radius: 999px; padding: 2px 8px; }
.ocr-badge.ok { background: var(--ok-soft); color: var(--ok); }
.ocr-badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.ocr-mat { margin-top: 2px; }
.ocr-currency {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px;
  background: var(--warn-soft); color: var(--warn-ink); border-radius: 10px;
  padding: 8px 12px; font-size: 13px; margin-top: 10px;
}
.ocr-cur-toggle {
  border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; color: var(--brand); text-decoration: underline dashed;
}
.ocr-row-err select { border-color: var(--danger); box-shadow: 0 0 0 2px rgba(220,38,38,.15); }

@media (min-width: 640px) { .view { padding-top: 20px; } }
