:root {
  --bg: #f2f6ff;
  --bg-soft: #e8effc;
  --card: #ffffff;
  --line: #d5e2f5;
  --text: #1a2e49;
  --muted: #6c809f;
  --accent: #2f7df6;
  --accent-dark: #1a4da8;
  --ok: #2dbd75;
  --warn: #ff9d42;
  --danger: #e5484d;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --radius: 16px;
  --shadow: 0 8px 24px rgba(26, 77, 168, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Play', system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 360px at 0% -8%, #dfeaff 0%, transparent 55%),
    radial-gradient(700px 320px at 100% 0%, #e7f3ff 0%, transparent 50%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; }
a { color: var(--accent); text-decoration: none; }

#app { min-height: 100%; min-height: 100dvh; }
.boot {
  display: grid; place-items: center; min-height: 100dvh;
  color: var(--muted); font-size: 15px;
}

.screen {
  max-width: 520px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 20px);
  animation: fade .22s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.topbar h1 {
  margin: 0; font-size: 22px; font-weight: 700; flex: 1;
  letter-spacing: -0.02em;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
  background: linear-gradient(145deg, var(--accent), #5aa6ff);
  box-shadow: 0 6px 16px rgba(47, 125, 246, 0.35);
}
.icon-btn {
  width: 40px; height: 40px; border: 1px solid var(--line);
  background: var(--card); border-radius: 12px; color: var(--text);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow); margin-bottom: 10px;
}
.card-tap { cursor: pointer; transition: transform .12s ease, border-color .12s; }
.card-tap:active { transform: scale(0.985); border-color: var(--accent); }

.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stack { display: grid; gap: 10px; }

.stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px;
}
.stat {
  background: linear-gradient(160deg, #fff 0%, #f4f8ff 100%);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px;
}
.stat b { display: block; font-size: 18px; margin-top: 4px; }
.stat span { color: var(--muted); font-size: 12px; }

.badge {
  display: inline-flex; align-items: center; padding: 3px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  background: #eaf1ff; color: var(--accent-dark);
}
.badge.ok { background: #e6f8ef; color: #1e8f55; }
.badge.warn { background: #fff1e4; color: #c56a14; }
.badge.danger { background: #fdecec; color: #c03438; }
.badge.gray { background: #eef1f6; color: #5a6b82; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 12px 16px;
  background: linear-gradient(180deg, #3d88f8, var(--accent));
  color: #fff; font-weight: 700; cursor: pointer;
  box-shadow: 0 8px 18px rgba(47, 125, 246, 0.28);
}
.btn:active { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.ghost {
  background: #fff; color: var(--text); border: 1px solid var(--line);
  box-shadow: none;
}
.btn.danger { background: linear-gradient(180deg, #f06a6d, var(--danger)); box-shadow: none; }
.btn.sm { padding: 8px 12px; font-size: 13px; border-radius: 10px; }

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea,
.sheet-panel input, .sheet-panel select, .sheet-panel textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; background: #fff; color: var(--text); outline: none;
  -webkit-appearance: none; appearance: none; min-height: 46px;
  box-sizing: border-box;
}
.field input:focus, .field select:focus, .field textarea:focus,
.sheet-panel input:focus, .sheet-panel select:focus, .sheet-panel textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,125,246,.15);
}
.field textarea, .sheet-panel textarea { min-height: 88px; resize: vertical; }
.field select, .sheet-panel select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px; background-repeat: no-repeat;
  padding-right: 36px;
}
.sheet-actions {
  position: sticky; bottom: 0; z-index: 2;
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 28%);
  padding-top: 12px; margin-top: 4px;
}
.client-picker { position: relative; }
.client-picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% - 4px); z-index: 8;
  max-height: 220px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 4px;
}
.client-picker-item {
  display: block; width: 100%; text-align: left;
  border: 0; background: transparent; border-radius: 10px;
  padding: 12px 12px; color: var(--text); cursor: pointer; font-size: 14px;
}
.client-picker-item:active, .client-picker-item:hover { background: #eaf1ff; }
.client-picker-empty {
  padding: 14px 12px; color: var(--muted); font-size: 13px; text-align: center;
}

.search {
  display: flex; gap: 8px; margin-bottom: 12px;
}
.search input {
  flex: 1; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; background: #fff;
}

.tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; height: 0; }
.tabs > * {
  flex: 0 0 auto;
  white-space: nowrap;
}
.tab {
  border: 1px solid var(--line); background: #fff;
  border-radius: 999px; padding: 8px 12px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.tab.active {
  background: var(--accent-dark); color: #fff; border-color: var(--accent-dark);
}
.home-order-status { margin-bottom: 10px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-width: 520px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding: 6px 6px calc(6px + var(--safe-b));
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.nav button {
  border: 0; background: transparent; color: var(--muted);
  display: grid; gap: 2px; place-items: center; font-size: 10px; cursor: pointer;
}
.nav button.active { color: var(--accent-dark); font-weight: 700; }
.nav svg { width: 22px; height: 22px; }

.login-wrap {
  min-height: 100dvh; display: grid; align-content: center;
  max-width: 420px; margin: 0 auto; padding: 24px 18px;
}
.login-hero {
  margin-bottom: 22px;
}
.login-hero .brand-mark { width: 52px; height: 52px; font-size: 18px; margin-bottom: 14px; }
.login-hero h1 { margin: 0 0 6px; font-size: 28px; }
.alert {
  background: #fdecec; color: #9b1c1f; border-radius: 12px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}
.alert.info { background: #eaf1ff; color: var(--accent-dark); }

.sheet {
  position: fixed; inset: 0; z-index: 50; background: rgba(16, 32, 58, 0.45);
  display: grid; align-items: end;
}
.sheet-panel {
  background: #fff; border-radius: 20px 20px 0 0; padding: 16px 16px calc(18px + var(--safe-b));
  max-height: 88vh; overflow-x: hidden; overflow-y: auto;
  -webkit-overflow-scrolling: touch; animation: up .2s ease;
}
.sheet-panel input[type="hidden"] { display: none; min-height: 0; padding: 0; border: 0; }
@keyframes up { from { transform: translateY(24px); } to { transform: none; } }
.sheet-handle {
  width: 42px; height: 4px; border-radius: 99px; background: #d5deec; margin: 0 auto 12px;
}

.empty {
  text-align: center; color: var(--muted); padding: 28px 12px;
}
.fab {
  position: fixed; right: max(16px, calc(50% - 244px));
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 54px; height: 54px; border-radius: 18px; border: 0;
  background: linear-gradient(145deg, #3d88f8, var(--accent-dark));
  color: #fff; font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 12px 28px rgba(26, 77, 168, 0.35); z-index: 30;
}

.timeline-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline-item:last-child { border-bottom: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--tag, var(--accent)) 18%, white);
  color: var(--tag, var(--accent-dark));
}

.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 12px;
}
.cal-cell {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid transparent;
  display: grid; place-items: center; font-size: 12px; background: transparent; color: var(--text);
}
.cal-cell.has { background: #eaf1ff; border-color: #c9daf7; font-weight: 700; }
.cal-cell.today { outline: 2px solid var(--accent); }
.cal-cell.muted { color: #b0bfd4; }
.cal-head { font-size: 11px; color: var(--muted); text-align: center; padding: 4px 0; }
.cal-cell { position: relative; flex-direction: column; gap: 2px; }
.cal-cell.selected { background: #d6e6ff; border-color: var(--accent); font-weight: 700; }
.cal-dot {
  font-size: 8px; font-style: normal; line-height: 1;
  background: var(--accent); color: #fff; border-radius: 6px;
  padding: 1px 3px; min-width: 12px; text-align: center;
}
.cal-switch { margin-bottom: 10px; }
.cal-actions {
  display: flex; flex-direction: row; gap: 8px; margin-bottom: 12px;
}
.cal-actions .btn { flex: 1; }
.day-panel { margin-top: 12px; }
.day-timeline { display: grid; gap: 8px; }
.timeline-row {
  display: grid; grid-template-columns: 48px 1fr; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
}
.timeline-time { font-weight: 700; color: var(--accent-dark); font-size: 13px; padding-top: 2px; }
.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 8px;
}
.week-col {
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
  padding: 6px 4px; min-height: 88px; text-align: center; cursor: pointer;
  color: var(--text);
}
.week-col.today { outline: 2px solid var(--accent); }
.week-col.selected { background: #eaf1ff; border-color: var(--accent); }
.week-col-head { font-size: 11px; color: var(--muted); line-height: 1.25; margin-bottom: 4px; }
.week-col-count { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.week-pill {
  font-size: 9px; background: #eaf1ff; color: var(--accent-dark);
  border-radius: 6px; padding: 2px 3px; margin-top: 2px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.week-pill.task { background: #fff1e4; color: #c56a14; }

.pin-card { padding: 18px 14px 12px; }
.pin-dots {
  display: flex; justify-content: center; gap: 14px; margin: 8px 0 22px;
}
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--accent); background: transparent;
  transition: background .12s ease, transform .12s ease;
}
.pin-dot.on {
  background: var(--accent-dark); border-color: var(--accent-dark);
  transform: scale(1.08);
}
.pin-pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  max-width: 280px; margin: 0 auto;
}
.pin-key {
  height: 56px; border-radius: 16px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: 22px; font-weight: 700;
  cursor: pointer; box-shadow: 0 4px 12px rgba(26, 77, 168, 0.06);
}
.pin-key:active { transform: scale(0.96); background: var(--bg-soft); }
.pin-key.spacer { visibility: hidden; pointer-events: none; border: 0; box-shadow: none; }

.chart-card { margin-bottom: 12px; }
.chart-bars {
  display: flex; align-items: flex-end; gap: 2px;
  height: 92px; margin-top: 12px; overflow-x: auto;
  padding-bottom: 2px;
}
.chart-col {
  flex: 1 1 0; min-width: 6px; max-width: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  height: 100%;
}
.chart-bar {
  width: 100%; border-radius: 4px 4px 2px 2px; min-height: 2px;
}
.chart-day {
  font-size: 8px; color: var(--muted); margin-top: 4px; line-height: 1;
  height: 10px;
}
.chart-day.muted-day { opacity: 0; }
