/* ─────────────────────────────────────────────────────────────
   ظاهر پایه — معادل ویجت‌های UI/ در پروژه فلاتر
   MyScaffold · MyAppBar · AppDrawer · MyBtn · MyEditText · MyList
   ───────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-gray);
  color: var(--text-black);
  font-family: 'IRANYekanX', 'Vazirmatn', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.9;
  direction: rtl;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; }

:focus-visible {
  outline: 2px solid var(--attention);
  outline-offset: 2px;
  border-radius: 4px;
}

/* اعداد همیشه با ارقام فارسی و جهت درست نمایش داده می‌شوند */
.num { font-variant-numeric: tabular-nums; unicode-bidi: isolate; direction: ltr; display: inline-block; }

/* ═══════════ چیدمان اصلی ═══════════ */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

.appbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--appbar-h);
  padding: 0 6px;
  background: var(--primary);
  color: var(--text-always-white);
  box-shadow: var(--shadow-2);
}
.appbar__title {
  flex: 1;
  font-weight: 700;
  font-size: 15px;
  padding-inline-start: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.appbar__sub {
  display: block;
  font-weight: 400;
  font-size: 11px;
  opacity: .78;
  line-height: 1.4;
}

.iconbtn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard);
}
.iconbtn:hover { background: rgba(255,255,255,.14); }
.iconbtn svg { width: 22px; height: 22px; }

.page {
  flex: 1;
  padding: var(--gap);
  padding-bottom: 96px;
  max-width: 1100px;
  width: 100%;
  margin-inline: auto;
}

/* ═══════════ کشو ═══════════ */
.drawer {
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;
  width: var(--drawer-w);
  max-width: 86vw;
  z-index: 950;
  background: var(--primary);
  color: var(--text-always-white);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-3);
  overflow-y: auto;
}
.drawer__head {
  padding: 20px 16px 16px;
  background: var(--primary-dark);
}
.drawer__avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--attention);
  display: grid; place-items: center;
  color: var(--primary-dark);
  overflow: hidden;
}
.drawer__avatar img { width: 100%; height: 100%; object-fit: cover; }
.drawer__store { font-weight: 700; margin-top: 10px; }
.drawer__user  { font-size: 12px; opacity: .75; }

.drawer__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 0;
  width: 100%;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-align: start;
  transition: background var(--dur-fast) var(--ease-standard);
}
.drawer__item:hover { background: rgba(255,255,255,.09); }
.drawer__item.active { background: rgba(255,255,255,.14); }
.drawer__item svg { width: 20px; height: 20px; flex: none; opacity: .9; }

/* ═══════════ کارت و لیست ═══════════ */
.card {
  background: var(--bg-white);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.card + .card { margin-top: var(--gap); }

.tile {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 0;
  background: var(--bg-white);
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-fast) var(--ease-standard),
              box-shadow var(--dur-fast) var(--ease-standard);
}
.tile:hover  { transform: translateY(-1px); box-shadow: var(--shadow-2); }
.tile:active { transform: scale(.995); }
.tile__body  { flex: 1; min-width: 0; }
.tile__title { font-weight: 700; }
.tile__sub   { font-size: 12px; color: var(--text-gray); }

.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  flex: none;
  display: grid; place-items: center;
  background: var(--attention);
  color: var(--text-always-white);
  overflow: hidden;
  font-weight: 700;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.list { display: flex; flex-direction: column; gap: var(--gap); }

/* ═══════════ دکمه‌ها — معادل MyBtn ═══════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-sm);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: transform var(--dur-fast) var(--ease-standard),
              filter var(--dur-fast) var(--ease-standard),
              box-shadow var(--dur-fast) var(--ease-standard);
}
.btn:hover:not(:disabled)  { filter: brightness(1.06); box-shadow: var(--shadow-2); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }

.btn--attention   { background: var(--attention); color: var(--text-always-white); }
.btn--primary     { background: var(--primary);   color: var(--text-always-white); }
.btn--green       { background: var(--green);     color: var(--text-always-white); }
.btn--red         { background: var(--red);       color: var(--text-always-white); }
.btn--transparent { background: transparent; color: var(--text-black);
                    box-shadow: inset 0 0 0 1px var(--bg-gray); }
.btn--block       { width: 100%; }

.fab {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-start: 20px;
  z-index: 70;
  width: 56px; height: 56px;
  border: 0; border-radius: 18px;
  background: var(--attention);
  color: var(--text-always-white);
  box-shadow: var(--shadow-2);
  cursor: pointer;
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }

/* ═══════════ ورودی‌ها — معادل MyEditText ═══════════ */
.field { margin-bottom: 12px; }
.field__label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-gray);
  margin-bottom: 4px;
  transition: color var(--dur-fast) var(--ease-standard);
}
.field:focus-within .field__label { color: var(--attention); }

.field__box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-white);
  border: 1.5px solid transparent;
  border-radius: var(--r-sm);
  padding: 0 12px;
  transition: border-color var(--dur-mid) var(--ease-standard),
              background var(--dur-mid) var(--ease-standard);
}
/* رفتار فوکوس دقیقا مثل resolveFillColor در MyEditText.dart */
.field:focus-within .field__box {
  border-color: var(--attention);
  background: color-mix(in srgb, var(--attention) 8%, var(--bg-white));
}
.field--error .field__box { border-color: var(--red); }
.field__box input,
.field__box textarea,
.field__box select {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 11px 0;
}
.field__box input::placeholder { color: var(--hint); }
.field__hint { font-size: 11px; color: var(--text-gray); margin-top: 3px; }
.field__hint--error { color: var(--red); }

/* ═══════════ دیالوگ / بات‌شیت ═══════════ */
.dialog {
  position: fixed;
  z-index: 960;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  transform: translate(50%, -50%);
  width: min(420px, 92vw);
  background: var(--bg-light);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  padding: 18px;
}
.dialog__title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; margin-bottom: 10px;
}
.dialog__desc { color: var(--text-black); margin-bottom: 16px; white-space: pre-line; }
.dialog__actions { display: flex; gap: 8px; }
.dialog__actions .btn { flex: 1; }

.sheet {
  position: fixed;
  z-index: 960;
  inset-inline: 0;
  inset-block-end: 0;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-light);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 8px 16px 24px;
  box-shadow: var(--shadow-3);
}
.sheet__grip {
  width: 42px; height: 4px;
  border-radius: 3px;
  background: var(--bg-gray);
  margin: 6px auto 14px;
}

/* ═══════════ توست ═══════════ */
#toasts {
  position: fixed;
  inset-block-end: 16px;
  inset-inline: 0;
  z-index: 980;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(520px, 92vw);
  padding: 11px 16px;
  border-radius: var(--r-md);
  background: var(--primary-dark);
  color: var(--text-always-white);
  box-shadow: var(--shadow-3);
  display: flex; align-items: center; gap: 8px;
}
.toast--error { background: var(--red); }
.toast--ok    { background: var(--green); }

/* ═══════════ پرده‌ی انتظار — معادل Waiting.dart ═══════════ */
#waiting {
  position: fixed;
  inset: 0;
  z-index: 990;
  display: none;
  place-items: center;
  background: var(--scrim);
  backdrop-filter: blur(2px);
}
#waiting.show { display: grid; }
#waiting .box {
  background: var(--bg-light);
  padding: 22px 26px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-width: 220px;
  text-align: center;
  white-space: pre-line;
}

/* ═══════════ حالت خالی ═══════════ */
.empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 56px 20px; text-align: center; color: var(--text-gray);
}
.empty svg { width: 54px; height: 54px; opacity: .45; }

/* ═══════════ صفحه‌ی ورود ═══════════ */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login__card {
  width: min(400px, 100%);
  background: var(--bg-light);
  border-radius: var(--r-xl);
  padding: 28px 24px;
  box-shadow: var(--shadow-3);
}
.login__logo {
  width: 68px; height: 68px;
  margin: 0 auto 14px;
  border-radius: 22px;
  background: var(--attention);
  display: grid; place-items: center;
  color: var(--text-always-white);
}
.login__title { text-align: center; font-weight: 700; font-size: 17px; }
.login__sub   { text-align: center; color: var(--text-gray); font-size: 12px; margin-bottom: 20px; }

/* ═══════════ نوار وضعیت سینک ═══════════ */
.syncbar {
  font-size: 11px;
  padding: 0 12px;
  color: var(--text-always-white);
  background: var(--primary-dark);
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--dur-slow) var(--ease-standard),
              padding var(--dur-slow) var(--ease-standard);
}
.syncbar.show { max-height: 40px; padding: 6px 12px; }

/* ═══════════ رسپانسیو ═══════════ */
@media (min-width: 900px) {
  .page { padding: 16px; }
  .fab  { inset-block-end: 28px; inset-inline-start: max(28px, calc(50vw - 550px + 28px)); }
}
