/* ============================================================
   WhatsApp Scheduler — "Calm & Refined" design system
   Warm paper, ink text, terracotta accent, serif display.
   ============================================================ */

:root {
  --paper:      #f3eee5;
  --paper-2:    #ede6d9;
  --surface:    #fbf8f2;
  --surface-2:  #f7f2e9;
  --ink:        #262019;
  --ink-soft:   #5c5346;
  --muted:      #938979;
  --line:       #e3d9c8;
  --line-soft:  #ece4d5;

  --accent:     #b1502c;   /* terracotta */
  --accent-dk:  #8f3f22;
  --accent-sft: #f0dccf;
  --accent-tint:#f7ebe1;

  --ok:         #4a6d4e;   /* deep sage */
  --ok-sft:     #dfe8dc;
  --fail:       #a8412c;
  --fail-sft:   #f1ddd6;
  --miss:       #8a8172;
  --miss-sft:   #e8e1d3;

  --radius:     12px;
  --radius-sm:  9px;
  --shadow:     0 1px 2px rgba(50,38,24,.05), 0 6px 20px -8px rgba(50,38,24,.14);
  --shadow-lg:  0 10px 40px -12px rgba(50,38,24,.28);
  --ring:       0 0 0 3px var(--accent-sft);

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans:  "Hanken Grotesk", -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background-image:
    radial-gradient(circle at 12% -8%, rgba(177,80,44,.05), transparent 42%),
    radial-gradient(circle at 100% 0%, rgba(74,109,78,.045), transparent 38%);
  background-attachment: fixed;
  min-height: 100vh;
}

[x-cloak] { display: none !important; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; color: var(--ink); margin: 0; letter-spacing: -.01em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-sft); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: .95rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: .62rem 1.15rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  transition: background .15s, transform .06s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-dk); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--muted); }

.btn-quiet {
  background: transparent;
  color: var(--ink-soft);
  padding: .45rem .7rem;
}
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }

.btn-danger { background: transparent; color: var(--fail); border: 1.5px solid transparent; }
.btn-danger:hover { background: var(--fail-sft); }

.btn-sm { padding: .4rem .8rem; font-size: .85rem; }
.btn-block { width: 100%; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.4rem;
  background: rgba(251,248,242,.82);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.wordmark {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.32rem;
  letter-spacing: -.02em;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: .5rem;
}
.wordmark .mark-dot { color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: .32rem .7rem;
  border-radius: 100px;
  cursor: pointer;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-live { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-sft); }
.dot-off  { background: var(--fail); box-shadow: 0 0 0 3px var(--fail-sft); }

.who { font-size: .88rem; color: var(--ink-soft); font-weight: 600; padding: 0 .35rem; }

/* ---------- Shell ---------- */
.shell { max-width: 780px; margin: 0 auto; padding: 1.8rem 1.4rem 5rem; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.4rem;
}
.page-head h1 { font-size: 2rem; line-height: 1.1; }
.page-head .sub { color: var(--muted); font-size: .92rem; margin-top: .25rem; }

/* ---------- Cards / schedule list ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sched {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.05rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: .8rem;
  transition: border-color .15s, transform .08s;
}
.sched:hover { border-color: var(--accent-sft); }
.sched.paused { opacity: .62; }
.sched-body { flex: 1; min-width: 0; }
.sched-name { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; margin-bottom: .12rem; }
.sched-meta { font-size: .88rem; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: .1rem .7rem; }
.sched-meta .to { color: var(--accent); font-weight: 600; }
.sched-when { color: var(--muted); }
.sched-actions { display: flex; align-items: center; gap: .35rem; flex-shrink: 0; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  width: 34px; height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { background: var(--fail-sft); color: var(--fail); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Toggle switch ---------- */
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; cursor: pointer; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--line);
  border-radius: 100px;
  transition: background .18s;
}
.switch .track::after {
  content: ""; position: absolute;
  width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .18s;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 3.2rem 1.5rem;
  color: var(--muted);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.empty h3 { font-size: 1.25rem; color: var(--ink-soft); margin-bottom: .4rem; }
.empty p { margin: 0 0 1.2rem; font-size: .92rem; }

/* ---------- Connection banner ---------- */
.banner {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.2rem;
  background: var(--accent-tint);
  border: 1px solid var(--accent-sft);
  border-radius: var(--radius);
  margin-bottom: 1.4rem;
}
.banner .b-body { flex: 1; }
.banner .b-title { font-weight: 700; color: var(--accent-dk); }
.banner .b-sub { font-size: .86rem; color: var(--ink-soft); }
.qr-wrap { text-align: center; padding: 1rem 0 .2rem; }
.qr-wrap img { width: 210px; height: 210px; border-radius: var(--radius-sm); border: 1px solid var(--line); background:#fff; padding:6px; }
.qr-wrap p { font-size: .86rem; color: var(--ink-soft); margin: 0 0 .8rem; }

/* ---------- Drawers (slide-over) ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(38,32,25,.38);
  backdrop-filter: blur(2px);
  z-index: 50;
  animation: fade .18s ease;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(480px, 100vw);
  background: var(--paper);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  display: flex; flex-direction: column;
  animation: slideIn .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 1.3rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.drawer-head h2 { font-size: 1.35rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.3rem; }
.drawer-foot {
  padding: 1rem 1.3rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex; gap: .7rem;
}
.close-x { font-size: 1.5rem; line-height: 1; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1.15rem; }
.field > label {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: .45rem;
}
.input, .textarea, select.input {
  width: 100%;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .68rem .85rem;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, select.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.textarea { resize: vertical; min-height: 110px; line-height: 1.55; }
.hint { font-size: .82rem; color: var(--muted); margin-top: .4rem; }

.phone-group { display: flex; align-items: stretch; }
.phone-group .cc {
  display: grid; place-items: center;
  padding: 0 .8rem;
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-weight: 600; color: var(--ink-soft);
}
.phone-group .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* variable + day chips */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 0; }
.chip {
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 600;
  padding: .3rem .65rem;
  border-radius: 100px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .12s;
  user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* segmented control */
.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--sans);
  font-weight: 600;
  font-size: .9rem;
  color: var(--ink-soft);
  padding: .5rem .4rem;
  border-radius: 7px;
  cursor: pointer;
  transition: all .14s;
}
.seg button.on { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* preview */
.preview {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: .8rem .95rem;
  font-size: .95rem;
  color: var(--ink);
  white-space: pre-wrap;
  line-height: 1.55;
  margin-top: .5rem;
}
.preview.muted { color: var(--muted); font-style: italic; border-left-color: var(--line); }

/* time inputs */
.time-row { display: flex; align-items: center; gap: .5rem; }
.time-row input { width: 68px; text-align: center; }
.time-sep { font-weight: 700; font-size: 1.15rem; color: var(--ink-soft); }
.inline-row { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.inline-row input[type=number] { width: 72px; text-align: center; }
.inline-row .input { width: auto; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: .18rem .6rem;
  border-radius: 100px;
  font-size: .76rem;
  font-weight: 700;
  text-transform: capitalize;
}
.badge-sent   { background: var(--ok-sft); color: var(--ok); }
.badge-failed { background: var(--fail-sft); color: var(--fail); }
.badge-missed { background: var(--miss-sft); color: var(--miss); }

/* ---------- Contact / list rows ---------- */
.row {
  display: flex; align-items: center; gap: .8rem;
  padding: .7rem .3rem;
  border-bottom: 1px solid var(--line-soft);
}
.row:last-child { border-bottom: none; }
.row-body { flex: 1; min-width: 0; }
.row-name { font-weight: 600; }
.row-sub { font-size: .84rem; color: var(--muted); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent-dk);
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 600; font-size: 1.05rem;
  flex-shrink: 0;
}

/* ---------- Menu popover ---------- */
.menu-pop {
  position: absolute; right: 1.4rem; top: 3.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 45;
  min-width: 210px;
  overflow: hidden;
  animation: fade .12s ease;
}
.menu-pop button {
  display: flex; align-items: center; gap: .6rem;
  width: 100%; text-align: left;
  border: none; background: transparent;
  font-family: var(--sans); font-size: .95rem; color: var(--ink);
  padding: .72rem 1rem;
  cursor: pointer;
}
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop button.danger { color: var(--fail); }
.menu-pop .divider { height: 1px; background: var(--line-soft); }

/* ---------- toolbar for drawers ---------- */
.toolbar { display: flex; gap: .55rem; margin-bottom: 1rem; align-items: center; }
.search {
  flex: 1;
  font-size: .95rem;
  padding: .55rem .8rem;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.search:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

.check-row {
  display: flex; align-items: center; gap: .7rem;
  padding: .55rem .2rem;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- errors / toast ---------- */
.err { color: var(--fail); font-size: .88rem; margin-top: .6rem; font-weight: 600; }
.form-err {
  background: var(--fail-sft); color: var(--accent-dk);
  padding: .6rem .8rem; border-radius: var(--radius-sm);
  font-size: .88rem; font-weight: 600; margin-bottom: 1rem;
}
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: .75rem 1.3rem; border-radius: 100px;
  font-size: .9rem; font-weight: 600; z-index: 80;
  box-shadow: var(--shadow-lg);
  animation: fade .2s ease;
}

/* ---------- spinner ---------- */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
.spinner.dark { border-color: var(--line); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- staggered load ---------- */
.enter { opacity: 0; transform: translateY(8px); animation: enter .5s cubic-bezier(.2,.8,.2,1) forwards; }
@keyframes enter { to { opacity: 1; transform: none; } }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1.4rem;
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 2.4rem 2rem;
  text-align: center;
}
.login-card .brand {
  font-family: var(--serif); font-weight: 600; font-size: 1.9rem;
  letter-spacing: -.02em; margin-bottom: .3rem;
}
.login-card .brand .mark-dot { color: var(--accent); }
.login-card .tagline { color: var(--muted); font-size: .95rem; margin-bottom: 2rem; }

.user-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .9rem; }
.user-tile {
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem .8rem;
  cursor: pointer;
  transition: all .15s;
}
.user-tile:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.user-tile .avatar { margin: 0 auto .6rem; width: 52px; height: 52px; font-size: 1.4rem; }
.user-tile .u-name { font-weight: 600; }
.user-tile.add { border-style: dashed; }
.user-tile.add .avatar { background: var(--surface); color: var(--muted); border: 1.5px solid var(--line); }

/* PIN pad */
.pin-row { display: flex; gap: .7rem; justify-content: center; margin: 1.5rem 0; }
.pin-box {
  width: 52px; height: 62px;
  font-family: var(--serif); font-size: 1.8rem; font-weight: 600; text-align: center;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.pin-box:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .topbar { padding: .75rem 1rem; }
  .wordmark { font-size: 1.15rem; }
  .who { display: none; }
  .shell { padding: 1.3rem 1rem 5rem; }
  .page-head { flex-direction: column; align-items: stretch; gap: .8rem; }
  .page-head h1 { font-size: 1.7rem; }
  .page-head .btn { width: 100%; }
  .drawer { width: 100vw; }
  .menu-pop { right: 1rem; left: 1rem; min-width: auto; }
}
