/* ═══════════════════════════════════════
   TOKENS — dark (default)
   Agendato Design System v4.0
═══════════════════════════════════════ */
:root {
  /* ── Dark palette ── */
  --bg:    #09090f;
  --bg2:   #111118;
  --bg3:   #1a1a24;
  --bg4:   #22222e;
  --border:  rgba(255,255,255,.07);
  --border2: rgba(255,255,255,.12);
  --border3: rgba(255,255,255,.18);
  --text:  #f0f0f5;
  --text2: #9898aa;
  --text3: #55556a;

  /* ── Brand ── */
  --accent:  #6366f1;
  --accent2: #818cf8;
  --accent3: #a5b4fc;
  --abg:  rgba(99,102,241,.10);
  --abg2: rgba(99,102,241,.18);

  /* ── Semantic ── */
  --green: #22c55e; --gbg: rgba(34,197,94,.10);
  --red:   #ef4444; --rbg: rgba(239,68,68,.10);
  --amber: #f59e0b;

  /* ── Shadows ── */
  --shadow:  0 1px 3px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow2: 0 4px 24px rgba(0,0,0,.55), 0 1px 4px rgba(0,0,0,.3);

  /* ── Border radius system ── */
  --rs: 12px;   /* buttons / inputs / nav items */
  --r:  16px;   /* cards / panels / icons */
  --rl: 24px;   /* hero banners / modals */

  /* ── Layout ── */
  --sidebar:  256px;
  --header-h: 64px;

  /* ── Typography ── */
  --font: 'Inter', 'Inter var', ui-sans-serif, system-ui,
          -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* ── Safe areas ── */
  --sat: env(safe-area-inset-top,    0px);
  --sar: env(safe-area-inset-right,  0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left,   0px);

  --nav-h: 0px;
}

/* ── Light palette ── */
.light {
  --bg:    #ffffff;
  --bg2:   #f8fafc;
  --bg3:   #f1f5f9;
  --bg4:   #e2e8f0;
  --border:  #f1f5f9;
  --border2: #e2e8f0;
  --border3: #cbd5e1;
  --text:  #0f172a;
  --text2: #475569;
  --text3: #94a3b8;
  --accent:  #6366f1;
  --accent2: #4f46e5;
  --accent3: #818cf8;
  --abg:  rgba(99,102,241,.06);
  --abg2: rgba(99,102,241,.11);
  --green: #22c55e; --gbg: rgba(34,197,94,.09);
  --red:   #ef4444; --rbg: rgba(239,68,68,.07);
  --amber: #f59e0b;
  --shadow:  0 1px 3px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --shadow2: 0 4px 24px rgba(0,0,0,.10), 0 1px 4px rgba(0,0,0,.05);
}

/* ═══════════════════════════════════════
   RESET + BASE
═══════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; max-width: 100%; }
html { overscroll-behavior: none; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .25s, color .25s;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv01', 'cv03', 'cv04', 'cv11';
}

img { max-width: 100%; height: auto; display: block; }

/* ── Selection ── */
::selection     { background: rgba(99,102,241,.22); color: var(--text); }
::-moz-selection{ background: rgba(99,102,241,.22); color: var(--text); }

/* ═══════════════════════════════════════
   SCREENS
═══════════════════════════════════════ */
.screen { display: none; }
.screen.active { display: block; }

/* ═══════════════════════════════════════
   LOADING OVERLAY
═══════════════════════════════════════ */
#loading-overlay {
  position: fixed; inset: 0;
  background: #09090f; /* always dark — prevents flash */
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity .35s;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loading-logo-img {
  height: 48px; width: auto; object-fit: contain;
  margin-bottom: 20px; user-select: none; pointer-events: none;
}
.loading-bar-wrap {
  width: 120px; height: 2px;
  background: rgba(255,255,255,.1);
  border-radius: 9999px; overflow: hidden;
}
.loading-bar-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 9999px;
  animation: loadbar 1.4s ease-in-out infinite;
}
@keyframes loadbar {
  0%   { width: 0%;   margin-left: 0 }
  50%  { width: 70%;  margin-left: 15% }
  100% { width: 0%;   margin-left: 100% }
}
#loading-error {
  margin-top: 24px; font-size: 13px; color: var(--red);
  text-align: center; display: none; max-width: 280px; line-height: 1.5;
}

/* ═══════════════════════════════════════
   TOAST
═══════════════════════════════════════ */
#toast {
  position: fixed; bottom: 28px; right: 24px;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-left: 3px solid var(--border3);
  border-radius: var(--r);
  padding: 13px 16px;
  font-size: 13px; font-weight: 500; color: var(--text);
  z-index: 9998;
  box-shadow: 0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.10);
  max-width: 340px; line-height: 1.5;
  opacity: 0; pointer-events: none;
}
#toast.show   { animation: toastIn  .3s cubic-bezier(.34,1.56,.64,1) forwards; pointer-events: all; }
#toast.t-out  { animation: toastOut .22s ease forwards; }
.t-ico  { font-size: 13px; flex-shrink: 0; line-height: 1.5; font-weight: 700; }
.t-body { flex: 1; min-width: 0; word-break: break-word; }
#toast.t-success { border-left-color: var(--green); }
#toast.t-success .t-ico { color: var(--green); }
#toast.t-error   { border-left-color: var(--red); }
#toast.t-error   .t-ico { color: var(--red); }
@keyframes toastIn  { from { opacity:0; transform:translateY(14px) scale(.96) } to { opacity:1; transform:translateY(0) scale(1) } }
@keyframes toastOut { from { opacity:1; transform:translateY(0) scale(1) }       to { opacity:0; transform:translateY(6px) scale(.97) } }

/* ═══════════════════════════════════════
   BUTTONS
═══════════════════════════════════════ */
.btn {
  padding: 9px 18px;
  border-radius: var(--rs);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all 200ms cubic-bezier(.4,0,.2,1);
  border: none;
  font-family: var(--font);
  display: inline-flex; align-items: center; gap: 7px;
  text-decoration: none; line-height: 1;
  white-space: nowrap; min-height: 36px;
  letter-spacing: -.01em;
}
.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover {
  background: var(--bg3);
  color: var(--text);
  border-color: var(--border3);
  transform: translateY(-1px);
}
.btn-ghost:active { transform: scale(.97) translateY(0) !important; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(99,102,241,.25), inset 0 1px 0 rgba(255,255,255,.1);
}
.btn-primary:hover {
  background: var(--accent2);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99,102,241,.35), inset 0 1px 0 rgba(255,255,255,.1);
}
.btn-primary:active:not(:disabled) {
  transform: scale(.97) translateY(0) !important;
  box-shadow: 0 1px 2px rgba(99,102,241,.25) !important;
}

.btn-danger {
  background: var(--rbg);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.18);
}
.btn-danger:hover {
  background: rgba(239,68,68,.16);
  transform: translateY(-1px);
}
.btn-danger:active { transform: scale(.97) translateY(0) !important; }

.btn-sm { padding: 6px 13px; font-size: 12px; min-height: 30px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ═══════════════════════════════════════
   FORMS
═══════════════════════════════════════ */
.form-group { margin-bottom: 14px; }
label {
  display: block;
  font-size: 12px; font-weight: 600;
  color: var(--text2);
  margin-bottom: 5px;
  letter-spacing: .01em;
}
input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--rs);
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text);
  font-size: 13.5px; font-family: var(--font);
  outline: none;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: var(--bg2);
  box-shadow: 0 0 0 3px var(--abg);
}
input[type=date]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator {
  filter: invert(.5); cursor: pointer;
}
.msg { padding: 9px 13px; border-radius: var(--rs); font-size: 12px; margin-bottom: 12px; display: none; }
.msg.error   { background: var(--rbg); color: var(--red);   border: 1px solid rgba(239,68,68,.2); display: block; }
.msg.success { background: var(--gbg); color: var(--green); border: 1px solid rgba(34,197,94,.2);  display: block; }
.auth-link { color: var(--accent2); cursor: pointer; text-decoration: underline; }

/* ═══════════════════════════════════════
   SPINNER + SKELETON
═══════════════════════════════════════ */
.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .55s linear infinite;
  flex-shrink: 0;
}
.light .spinner { border-color: rgba(0,0,0,.15); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg) } }

.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg4) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: var(--r);
}
@keyframes shimmer { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* ═══════════════════════════════════════
   ANIMATIONS — shared
═══════════════════════════════════════ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ═══════════════════════════════════════
   PWA ENHANCEMENTS
═══════════════════════════════════════ */
button, .btn, .nav-item, .svc-card, .stat-card, .tslot, .agenda-dia-row {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.app-content, .sb-nav, .agenda-scroll, .table-wrap {
  -webkit-overflow-scrolling: touch;
}

/* PWA standalone — status bar compensation */
@media all and (display-mode: standalone) {
  #loading-overlay { padding-top: var(--sat); }
  .land-nav        { padding-top: calc(12px + var(--sat)); }
  .app-topbar      { padding-top: var(--sat); height: calc(var(--header-h) + var(--sat)); }
  .app-content     { padding-bottom: calc(24px + var(--sab)); }
  #toast           { bottom: calc(28px + var(--sab)); }
  #pwa-update-banner { bottom: calc(80px + var(--sab)); }
}

/* ═══════════════════════════════════════
   SCROLLBARS — global, 6px, sem setas
═══════════════════════════════════════ */
* {
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: #cbd5e1;
  border-radius: 9999px;
}
*::-webkit-scrollbar-button {
  width: 0;
  height: 0;
  display: none;
}
*::-webkit-scrollbar-corner {
  background: transparent;
}

/* ═══════════════════════════════════════
   PWA INSTALL BANNER
═══════════════════════════════════════ */
#pwa-install-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 8900;
  padding: 14px 16px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--bg2);
  border-top: 1px solid var(--border2);
  box-shadow: 0 -4px 28px rgba(0,0,0,.18), 0 -1px 0 rgba(0,0,0,.06);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transform: translateY(102%);
  transition: transform .4s cubic-bezier(.22,1,.36,1);
  will-change: transform;
}
#pwa-install-banner.pwa-ban-show { transform: translateY(0); }
.pwa-ban-content {
  display: flex; align-items: center; gap: 12px;
  max-width: 520px; margin: 0 auto;
}
.pwa-ban-icon-wrap { flex-shrink: 0; }
.pwa-ban-logo {
  width: 42px; height: 42px; border-radius: 10px;
  display: block; object-fit: cover;
}
.pwa-ban-logo-fb {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #7c3aed);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 900; color: #fff;
}
.pwa-ban-text { flex: 1; min-width: 0; }
.pwa-ban-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 2px; line-height: 1.3; }
.pwa-ban-desc  { font-size: 11.5px; color: var(--text2); line-height: 1.45; }
.pwa-share-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; background: var(--bg3);
  border: 1px solid var(--border2); border-radius: 4px;
  padding: 1px 5px; margin: 0 1px; vertical-align: middle;
}
.pwa-ban-btns    { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.pwa-ban-install {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--rs); padding: 8px 18px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  font-family: var(--font); white-space: nowrap;
  transition: background .18s, transform .18s;
  -webkit-tap-highlight-color: transparent;
}
.pwa-ban-install:hover  { background: var(--accent2); transform: translateY(-1px); }
.pwa-ban-install:active { transform: scale(.97); }
.pwa-ban-later {
  background: transparent; color: var(--text3); border: none;
  border-radius: var(--rs); padding: 4px 18px;
  font-size: 11.5px; cursor: pointer; font-family: var(--font);
  text-align: center; transition: color .18s;
  -webkit-tap-highlight-color: transparent;
}
.pwa-ban-later:hover { color: var(--text2); }
.pwa-ban-close {
  background: transparent; border: none; color: var(--text3);
  cursor: pointer; font-size: 24px; line-height: 1; padding: 0 2px;
  flex-shrink: 0; display: flex; align-items: center;
  transition: color .15s; -webkit-tap-highlight-color: transparent;
}
.pwa-ban-close:hover { color: var(--text); }

@media (max-width: 480px) {
  .pwa-ban-install { padding: 8px 14px; }
  .pwa-ban-later   { padding: 4px 14px; }
}
