:root {
  --bg: #f3f5fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1e3a8a;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(30, 58, 138, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: Vazirmatn, Tahoma, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

button, input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ---------- Header ---------- */
.topbar {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #7c3aed 100%);
  color: #fff;
  padding: 18px 0 70px;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { margin: 0; font-size: 1.35rem; font-weight: 800; }
.brand p { margin: 0; opacity: 0.85; font-size: 0.9rem; }
.brand p span:not(:empty)::before { content: " • "; }
.logo {
  width: 52px; height: 52px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  display: grid; place-items: center;
  font-size: 1.6rem; font-weight: 900;
}
.top-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.clock { text-align: left; }
.clock-time { font-size: 1.6rem; font-weight: 800; letter-spacing: 1px; direction: ltr; text-align: left; }
.clock-date { font-size: 0.85rem; opacity: 0.85; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  font-size: 1.15rem;
  transition: background 0.2s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.3); }

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(22, 163, 74, 0.28);
  border: 1px solid rgba(134, 239, 172, 0.55);
  color: #dcfce7;
}
.sync-pill::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4ade80;
}
.sync-pill.offline {
  background: rgba(217, 119, 6, 0.3);
  border-color: rgba(253, 230, 138, 0.6);
  color: #fef3c7;
}
.sync-pill.offline::before { background: #fbbf24; }
.sync-pill.local {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.35);
  color: #f3f4f6;
}
.sync-pill.local::before { background: #d1d5db; }

/* ---------- Auth Screen ---------- */
.auth-wrap {
  max-width: 460px;
  margin: -50px auto 30px;
  padding: 0 20px;
}
.auth-card {
  padding: 26px;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: #f3f4f6;
  padding: 5px;
  border-radius: 14px;
  margin-bottom: 18px;
}
.auth-tab {
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}
.auth-tab.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}
.auth-welcome {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 0.88rem;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.pw-wrap input {
  padding-right: 42px !important;
}
.pw-toggle {
  position: absolute;
  right: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.05rem;
  padding: 4px 6px;
  border-radius: 8px;
  opacity: 0.7;
}
.pw-toggle:hover { opacity: 1; background: #f3f4f6; }

/* ---------- Top Banner ---------- */
.top-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.top-banner.warn {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

/* ---------- Account Box ---------- */
.account-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.account-box strong {
  display: inline-block;
  margin-right: 4px;
  color: var(--primary-dark);
}

/* ---------- Layout ---------- */
.container {
  max-width: 1200px;
  margin: -50px auto 0;
  padding: 0 20px 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  border: 1px solid rgba(229, 231, 235, 0.7);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.card-head.wrap { flex-wrap: wrap; }
.card h2 { margin: 0; font-size: 1.1rem; font-weight: 800; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Status card ---------- */
.status-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border-top: 5px solid #9ca3af;
}
.status-card.is-in { border-top-color: var(--success); }
.status-card.is-break { border-top-color: var(--warn); }
.status-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: #f3f4f6;
  color: #4b5563;
}
.badge::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.is-in .badge { background: #dcfce7; color: #15803d; }
.is-in .badge::before { animation: pulse 1.4s infinite; }
.is-break .badge { background: #fef3c7; color: #b45309; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.timer {
  font-size: 3.2rem;
  font-weight: 900;
  margin-top: 14px;
  direction: ltr;
  letter-spacing: 2px;
  color: var(--primary-dark);
}
.is-in .timer { color: var(--success); }
.is-break .timer { color: var(--warn); }
.timer-label { color: var(--muted); font-size: 0.9rem; margin-top: -6px; }
.session-info { min-height: 1.6em; font-size: 0.9rem; color: var(--muted); margin-top: 6px; }

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 14px;
}
.alerts { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.alert {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.88rem;
  text-align: right;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
.alert.warn { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert.danger { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert .btn { margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-xl { padding: 16px 20px; font-size: 1.2rem; border-radius: 14px; }
.btn-lg { padding: 12px 18px; font-size: 1rem; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; border-radius: 10px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3); }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 6px 18px rgba(22, 163, 74, 0.35); }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 6px 18px rgba(220, 38, 38, 0.3); }
.btn-danger:hover { background: #b91c1c; }
.btn-warn { background: #fef3c7; color: #92400e; }
.btn-warn:hover { background: #fde68a; }
.btn-ghost { background: #f3f4f6; color: var(--text); }
.btn-ghost:hover { background: #e5e7eb; }
.btn-icon { background: transparent; padding: 4px 8px; border-radius: 8px; cursor: pointer; border: none; font-size: 1rem; }
.btn-icon:hover { background: #f3f4f6; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Today stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.stat {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 800; }
.stat-value.stat-live { font-size: 1rem; color: var(--success); padding-top: 6px; }
.stat-main { background: #eff6ff; border-color: #bfdbfe; }
.stat-main .stat-value { color: var(--primary); }

/* ---------- Week card ---------- */
.week-top { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 130px; height: 130px; flex-shrink: 0; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 11; }
.ring-bg { stroke: #e5e7eb; }
.ring-fg {
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.6s ease, stroke 0.3s;
}
.ring-fg.done { stroke: var(--success); }
.ring-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-text strong { font-size: 1.45rem; font-weight: 900; line-height: 1.2; }
.ring-text span { font-size: 0.78rem; color: var(--muted); }
.week-info { flex: 1; }
.week-percent { font-size: 1.8rem; font-weight: 900; color: var(--primary-dark); }
.week-msg { margin: 4px 0 0; font-size: 0.9rem; color: var(--muted); }
.week-msg.ok { color: var(--success); font-weight: 700; }
.week-msg.danger { color: var(--danger); font-weight: 700; }

.days {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 18px;
}
.days.has-friday { grid-template-columns: repeat(7, 1fr); }
.day { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.day-bar {
  width: 100%;
  max-width: 38px;
  height: 80px;
  background: #f3f4f6;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
}
.day-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  border-radius: 10px;
  transition: height 0.5s ease;
}
.day.today .day-bar { outline: 2px solid var(--primary); outline-offset: 2px; }
.day.off .day-fill { background: linear-gradient(180deg, #fcd34d, #d97706); }
.day-name { font-size: 0.8rem; font-weight: 700; }
.day-val { font-size: 0.72rem; color: var(--muted); }

/* ---------- History ---------- */
.history-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.week-nav { display: flex; align-items: center; gap: 8px; }
.week-label { font-size: 0.9rem; font-weight: 700; min-width: 170px; text-align: center; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table th { color: var(--muted); font-weight: 700; font-size: 0.82rem; background: #f9fafb; }
.table td.note { white-space: normal; max-width: 260px; color: var(--muted); font-size: 0.85rem; }
.table td.useful { font-weight: 800; color: var(--primary); }
.table tfoot td { font-weight: 800; background: #f9fafb; border-bottom: none; }
.table .empty { text-align: center; color: var(--muted); padding: 30px; }
.table .row-actions { text-align: left; }
.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-right: 4px;
}
.tag-live { background: #dcfce7; color: #15803d; }
.tag-off { background: #fef3c7; color: #b45309; }

/* ---------- Weeks report ---------- */
.weeks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.week-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  background: #fff;
  text-align: right;
  transition: border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.week-item:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(37, 99, 235, 0.12); }
.week-item .wi-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.week-item .wi-range { font-size: 0.85rem; font-weight: 700; }
.week-item .wi-hours { font-size: 1.2rem; font-weight: 900; }
.week-item .wi-sub { font-size: 0.78rem; color: var(--muted); }
.mini-bar { height: 6px; background: #f3f4f6; border-radius: 6px; overflow: hidden; }
.mini-bar > div { height: 100%; background: var(--primary); border-radius: 6px; }
.week-item.pass .mini-bar > div { background: var(--success); }
.week-item.fail .mini-bar > div { background: var(--danger); }
.pill { font-size: 0.72rem; font-weight: 800; padding: 2px 10px; border-radius: 999px; }
.pill.pass { background: #dcfce7; color: #15803d; }
.pill.fail { background: #fee2e2; color: #b91c1c; }
.pill.current { background: #dbeafe; color: #1d4ed8; }
.empty-box { text-align: center; color: var(--muted); padding: 20px; grid-column: 1 / -1; }

/* ---------- Dialogs ---------- */
.dialog {
  border: none;
  border-radius: 20px;
  padding: 0;
  width: min(480px, calc(100vw - 30px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-height: calc(100vh - 40px);
}
.dialog::backdrop { background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(2px); }
.dialog form { padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.dialog h3 { margin: 0 0 4px; font-size: 1.2rem; }
.dialog h4 { margin: 4px 0 0; font-size: 0.95rem; }
.dialog hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }
.danger-title { color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 0.85rem; font-weight: 700; color: #374151; }
.field input, .field select, .field textarea, .date-row select {
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 9px 12px;
  background: #fff;
  width: 100%;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus, .date-row select:focus {
  outline: 2px solid #93c5fd;
  border-color: var(--primary);
}
.field input[dir="ltr"] { text-align: left; }
.field input[type="time"], .field input[type="number"] { text-align: right; }
.date-row { display: grid; grid-template-columns: 1fr 1.6fr 1.2fr; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 0.88rem; cursor: pointer; }
.check input { margin-top: 6px; width: 18px; height: 18px; flex-shrink: 0; }
.hint { margin: 0; font-size: 0.82rem; color: var(--muted); }
.hint:empty, .form-error:empty { display: none; }
.form-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 0.85rem;
}
.dialog-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 30px);
  background: #111827;
  color: #fff;
  padding: 12px 22px;
  border-radius: 14px;
  font-size: 0.92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  max-width: calc(100vw - 30px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0 20px 30px; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .topbar { padding-bottom: 60px; }
  .brand h1 { font-size: 1.1rem; }
  .clock-time { font-size: 1.25rem; }
  .timer { font-size: 2.6rem; }
  .week-top { flex-direction: column; text-align: center; }
  .week-label { min-width: 0; }
  .card { padding: 18px; }
  .sync-pill { display: none; }
}
