/* ==================================================================
   سامانه‌ی مدیریت زمان کلاب
   موبایل‌محور، راست‌به‌چپ، بدون فریم‌ورک.
   هدف‌های لمسی حداقل ۴۸ پیکسل.
   ================================================================== */

:root {
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #fafbfc;
  --border:      #dfe3e8;
  --text:        #1c2430;
  --text-muted:  #6b7684;

  --free:        #1a9a5f;
  --free-bg:     #e8f7ef;
  --busy:        #d6323f;
  --busy-bg:     #fdebec;
  --disabled:    #8a94a1;
  --disabled-bg: #eef0f2;
  --paused:      #b26a00;
  --paused-bg:   #fff4e0;

  --primary:     #2563d9;
  --primary-ink: #ffffff;
  --warn:        #b26a00;
  --warn-bg:     #fff4e0;

  --radius:      12px;
  --radius-sm:   8px;
  --tap:         48px;          /* حداقل اندازه‌ی هدف لمسی */
  --shadow:      0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg:   0 8px 28px rgba(16, 24, 40, .16);

  --font: Vazirmatn, "Vazir", "Segoe UI", "Tahoma", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #11151b;
    --surface:     #1a2029;
    --surface-2:   #202832;
    --border:      #2c3541;
    --text:        #e8ecf1;
    --text-muted:  #98a3b1;

    --free:        #4cc78a;
    --free-bg:     #14301f;
    --busy:        #f0656f;
    --busy-bg:     #331519;
    --disabled:    #7b8695;
    --disabled-bg: #232a33;
    --paused:      #e0a44a;
    --paused-bg:   #33280f;

    --primary:     #5b8def;
    --warn:        #e0a44a;
    --warn-bg:     #33280f;
    --shadow:      0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg:   0 8px 28px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.4; font-weight: 700; }

/* ------------------------------------------------------ نوار بالا */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.topbar-main, .topbar-side { display: flex; align-items: center; gap: .75rem; }
.brand { font-weight: 700; }

.nav { display: flex; gap: .25rem; }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.is-active { background: var(--primary); color: var(--primary-ink); }

.clock { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.user-name { color: var(--text-muted); }

.page { max-width: 1100px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.page-title { margin-bottom: 1rem; }

.section-title {
  margin: 1.5rem 0 .75rem;
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ------------------------------------------------------ دکمه‌ها */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: var(--tap);
  padding: 0 1.1rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter .15s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-danger  { background: var(--busy);    border-color: var(--busy);    color: #fff; }
.btn-ghost   { background: transparent; }

.btn-lg { min-height: 56px; font-size: 1.05rem; padding: 0 1.75rem; }
.btn-sm { min-height: 40px; padding: 0 .85rem; font-size: .9rem; }
.btn-xs { min-height: 34px; padding: 0 .7rem;  font-size: .85rem; }
.btn-block { width: 100%; }

.icon-btn {
  min-width: 40px; min-height: 40px;
  font-size: 1.1rem; line-height: 1;
  background: transparent; border: 0; color: var(--text-muted);
  border-radius: var(--radius-sm); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ------------------------------------------------------ نوار روز کاری */

.day-bar {
  display: flex; flex-wrap: wrap; gap: .75rem 1rem;
  align-items: center; justify-content: space-between;
  padding: .85rem 1rem; margin-bottom: .75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.day-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem .75rem; }
.day-label { color: var(--text-muted); font-size: .9rem; }
.day-total {
  font-size: 1.5rem; font-weight: 800; color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.day-meta { color: var(--text-muted); font-size: .85rem; }
.day-actions { display: flex; gap: .5rem; }
.day-actions .btn { min-width: 6.5rem; }

.live-summary {
  display: flex; flex-wrap: wrap; gap: .5rem;
  padding: .6rem .9rem; margin-bottom: 1rem;
  font-size: .95rem; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.live-summary .sep { opacity: .5; }

.hero-note { max-width: 34rem; margin-top: .75rem; text-align: center; }

.modal-wide { width: min(760px, calc(100vw - 1.5rem)); }

/* ------------------------------------------------------ گرید دستگاه‌ها */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .75rem;
}

.device-card {
  display: flex; flex-direction: column; gap: .35rem;
  min-height: 116px; padding: .8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.device-card.is-free     { border-inline-start-color: var(--free);     background: var(--free-bg); }
.device-card.is-busy     { border-inline-start-color: var(--busy);     background: var(--busy-bg); }
.device-card.is-paused   { border-inline-start-color: var(--paused);   background: var(--paused-bg); }
.device-card.is-disabled { border-inline-start-color: var(--disabled); background: var(--disabled-bg); opacity: .75; }

.device-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.device-name { font-weight: 700; white-space: nowrap; }
.device-status { font-size: .8rem; color: var(--text-muted); text-align: start; }
.is-free .device-status     { color: var(--free); }
.is-busy .device-status     { color: var(--busy); }
.is-paused .device-status   { color: var(--paused); }
.is-disabled .device-status { color: var(--disabled); }

.device-customer {
  font-size: .9rem; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.device-timer {
  font-size: 1.25rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--busy);
}
/* تایمر متوقف رنگ دیگری می‌گیرد تا از یک نگاه معلوم باشد نمی‌شمرد. */
.is-paused .device-timer { color: var(--paused); }

.device-actions {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-top: auto;
}
.device-actions .btn { flex: 1 1 auto; }

/* ------------------------------------------------------ سشن‌ها */

.session-list { display: flex; flex-direction: column; gap: .75rem; }

.session-card.is-paused { border-inline-start: 4px solid var(--paused); background: var(--paused-bg); }
.session-card.is-paused .session-elapsed { color: var(--paused); }
.paused-note { color: var(--paused); }

.session-card {
  padding: .9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.session-head { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; }
.session-head h3 { margin: 0; font-size: 1.05rem; }
.session-meta { margin: 0; font-size: .85rem; color: var(--text-muted); }
.session-elapsed {
  font-size: 1.15rem; font-weight: 700;
  font-variant-numeric: tabular-nums; color: var(--text-muted);
}

.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .7rem 0; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .25rem .6rem; font-size: .85rem;
  border: 1px solid var(--border); border-radius: 999px;
}
.chip-open { background: var(--busy-bg);     border-color: var(--busy);     color: var(--busy); }
.chip-paused { background: var(--paused-bg); border-color: var(--paused); color: var(--paused); }
.chip-done { background: var(--disabled-bg); color: var(--text-muted); }
.chip-timer, .chip-min { font-variant-numeric: tabular-nums; font-weight: 700; }

.session-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ------------------------------------------------------ دکمه‌ی شناور */

.fab {
  position: fixed;
  inset-block-end: max(1rem, env(safe-area-inset-bottom));
  inset-inline-end: 1rem;
  z-index: 25;
  display: inline-flex; align-items: center; gap: .5rem;
  min-height: 56px; padding: 0 1.5rem;
  font: inherit; font-weight: 700;
  color: var(--primary-ink); background: var(--primary);
  border: 0; border-radius: 999px;
  box-shadow: var(--shadow-lg); cursor: pointer;
}
.fab span { font-size: 1.35rem; line-height: 1; }

/* ------------------------------------------------------ گفت‌وگو */

.modal {
  width: min(520px, calc(100vw - 1.5rem));
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(10, 14, 20, .55); }

.modal-inner { display: flex; flex-direction: column; max-height: 85vh; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem; overflow-y: auto; }
.modal-desc { margin: 0 0 1rem; color: var(--text-muted); }
.modal-foot {
  display: flex; gap: .5rem; justify-content: flex-end;
  padding: .75rem 1rem; border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ------------------------------------------------------ فرم */

.form { display: flex; flex-direction: column; gap: .85rem; }

label { display: block; font-size: .9rem; color: var(--text-muted); }

input, select, textarea {
  display: block; width: 100%;
  min-height: var(--tap);
  margin-top: .3rem; padding: .5rem .75rem;
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
input[type="checkbox"] {
  width: 22px; height: 22px; min-height: 22px; margin: 0;
  accent-color: var(--primary);
}
label.check { display: flex; align-items: center; gap: .5rem; min-height: var(--tap); }

.picker { padding: .75rem; margin: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.picker legend { padding: 0 .4rem; font-size: .85rem; color: var(--text-muted); }

.device-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .4rem; }
.pick {
  display: flex; align-items: center; gap: .5rem;
  min-height: var(--tap); padding: .4rem .6rem;
  background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer;
}
.pick:has(input:checked) { border-color: var(--primary); background: var(--free-bg); }
.pick.is-disabled { opacity: .5; cursor: not-allowed; }
.pick input { flex: 0 0 auto; }
/* نام دستگاه نباید بشکند؛ توضیح کناری در صورت کمبود جا کوتاه می‌شود. */
.pick-name { font-weight: 600; color: var(--text); white-space: nowrap; }
.pick-note {
  flex: 1 1 auto; min-width: 0;
  text-align: start; font-size: .75rem; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.advanced { padding: .5rem 0; }
.advanced summary { min-height: 40px; display: flex; align-items: center; cursor: pointer; color: var(--text-muted); font-size: .9rem; }

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

.inline-form {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end;
  padding: .85rem; margin-bottom: 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.inline-form label { flex: 1 1 8rem; }
.cell-input { min-height: 38px; margin: 0; padding: .25rem .5rem; font-size: .9rem; }

/* ------------------------------------------------------ رسید */

.receipt { font-variant-numeric: tabular-nums; }
.receipt-customer { margin: 0; font-size: 1.15rem; }
.receipt-count { margin: 0 0 .75rem; color: var(--text-muted); font-size: .9rem; }
.receipt-lines { display: flex; flex-direction: column; gap: .35rem; }
.receipt-line { display: flex; align-items: baseline; gap: .5rem; }
.receipt-dots { flex: 1; border-bottom: 1px dotted var(--border); }
.receipt-minutes { font-weight: 600; }
.receipt-total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: .85rem; padding-top: .75rem;
  border-top: 2px solid var(--border); font-size: 1.05rem;
}
.receipt-total strong { font-size: 1.35rem; color: var(--primary); }
.receipt-range { margin: .5rem 0 0; color: var(--text-muted); font-size: .9rem; }

/* ------------------------------------------------------ گزارش */

.report-toolbar { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.report-toolbar .spacer { flex: 1; }
.report-head { margin-bottom: 1.25rem; }
.report-meta { margin: 0; color: var(--text-muted); }

.hero-number {
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: 1.75rem 1rem; margin-bottom: 1rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.hero-label { font-size: .9rem; color: var(--text-muted); }
.hero-value {
  font-size: clamp(2.75rem, 12vw, 4.5rem); line-height: 1.1;
  font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums;
}
.hero-unit { color: var(--text-muted); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .75rem; }
.stat {
  display: flex; flex-direction: column; align-items: center;
  padding: .9rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.stat span { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat label { color: var(--text-muted); font-size: .85rem; }

/* ------------------------------------------------------ جدول */

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .6rem .75rem; text-align: right; white-space: nowrap; }
.table th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; }
.table tbody tr { border-top: 1px solid var(--border); }
.table td { font-variant-numeric: tabular-nums; }
.table-clickable tbody tr { cursor: pointer; }
.table-clickable tbody tr:hover { background: var(--surface-2); }
.row-warn { background: var(--warn-bg); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85rem; }

/* ------------------------------------------------------ تب */

.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tab {
  min-height: 44px; padding: 0 1rem;
  font: inherit; font-weight: 600; color: var(--text-muted);
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; }
.filters label { flex: 0 1 12rem; }

/* ------------------------------------------------------ پیام‌ها */

.alert { padding: .7rem .9rem; margin: 0 0 .75rem; border-radius: var(--radius-sm); font-size: .92rem; }
.alert-error { background: var(--busy-bg); color: var(--busy); border: 1px solid var(--busy); }
.alert-ok    { background: var(--free-bg); color: var(--free); border: 1px solid var(--free); }

.badge { display: inline-block; padding: .1rem .5rem; font-size: .78rem; border-radius: 999px; }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-open { background: var(--free-bg); color: var(--free); }
.badge-paused { background: var(--paused-bg); color: var(--paused); }

.empty { padding: 1.5rem; color: var(--text-muted); text-align: center; }

.toast-host {
  position: fixed;
  inset-block-start: 4.5rem;
  inset-inline-start: 50%;
  transform: translateX(50%);
  z-index: 60;
  display: flex; flex-direction: column; gap: .5rem;
  pointer-events: none;
}
.toast {
  padding: .65rem 1rem;
  color: #fff; background: #2b3440;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast-error { background: var(--busy); }
.toast-ok    { background: var(--free); }
.toast.is-leaving { opacity: 0; transition: opacity .3s; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

/* ------------------------------------------------------ ورود و نصب */

.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
}
.auth-card {
  width: min(420px, 100%);
  padding: 2rem 1.5rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.auth-card h1 { text-align: center; }
.auth-sub { margin: 0 0 1.5rem; color: var(--text-muted); text-align: center; }
.install-card { width: min(560px, 100%); }
.install-card h2 { margin-top: 1rem; font-size: .95rem; color: var(--text-muted); }

/* ------------------------------------------------------ حالت آفلاین */

.dash[data-state="offline"] .live-summary::after {
  content: 'اتصال قطع است — تلاش دوباره…';
  color: var(--warn);
}

/* ------------------------------------------------------ چاپ */

@media print {
  .topbar, .fab, .no-print, .toast-host, .session-actions { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .page { max-width: none; padding: 0; }
  .modal { position: static; display: block; border: 0; box-shadow: none; max-height: none; }
  .modal::backdrop { display: none; }
  .table-wrap, .hero-number, .stat, .session-card { box-shadow: none; border-color: #999; }
  .hero-value { color: #000; }
}

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

@media (max-width: 560px) {
  .topbar { padding: .5rem .75rem; }
  .topbar-main { width: 100%; justify-content: space-between; }
  .topbar-side { width: 100%; justify-content: space-between; }
  .page { padding: .75rem .75rem 6rem; }
  .device-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .session-head { flex-direction: column; gap: .35rem; }
  .day-bar { flex-direction: column; align-items: stretch; }
  .day-actions .btn { flex: 1; }
  .session-actions .btn { flex: 1 1 auto; }
  .fab { inset-inline-end: .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
