/* Reset, typography, and the shared primitives (buttons, inputs, overlays)
   that more than one feature uses. Feature-specific styling belongs in
   components.css or css/modules/. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* A flex row that overflows (header, on a narrow phone, is the one that has
 * actually done this) doesn't just look bad — position:fixed elements with
 * right:0/inset:0 (the drawer, the modal/drawer backdrops) can resolve
 * against the resulting wider LAYOUT viewport instead of the true visual
 * one, and end up rendered partly or fully off-screen. This is real mobile
 * browser behaviour, not just a testing artefact. One overflowing row
 * anywhere on the page can make the drawer's own close button unreachable.
 * Hard stop, so a future addition can't silently reintroduce this. */
html, body { overflow-x: hidden; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px; border-radius: 10px;
  font-family: inherit; font-size: .82rem; font-weight: 600;
  border: 1.5px solid var(--border2); background: var(--bg2); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
/* A plain .btn sits on a white toolbar/modal (var(--surface)) — giving it
   var(--surface) too, as it had before, left it defined only by a 1.5px
   border barely darker than the page background, easy to miss at a glance.
   Tinting the resting state and darkening hover further gives every
   secondary button (Tools, Close, Cancel…) a visible edge without touching
   --border/--border2 themselves, so cards, inputs and dividers are unaffected. */
.btn:hover { background: var(--border2); border-color: var(--text3); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text2); }
.btn-ghost:hover { background: var(--bg2); color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ── Form controls ───────────────────────────────────────────────────────── */
.inp, .sel, .txt {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-family: inherit; font-size: .875rem; color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.txt { min-height: 84px; resize: vertical; line-height: 1.55; }
.inp:focus, .sel:focus, .txt:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
}
.inp[aria-invalid="true"], .sel[aria-invalid="true"], .txt[aria-invalid="true"] {
  border-color: var(--red);
}
.inp::placeholder, .txt::placeholder { color: var(--text3); }

.ck { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.ck input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.ck span { font-size: .855rem; font-weight: 500; color: var(--text); }

/* ── Loading overlay ─────────────────────────────────────────────────────── */
#loading-ov {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--dark-grad);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .4s, visibility .4s;
}
#loading-ov.hidden { display: flex !important; opacity: 0; visibility: hidden; pointer-events: none; }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.loading-logo { width: 56px; height: 56px; border-radius: 12px; overflow: hidden; }
.loading-logo img { width: 100%; height: 100%; object-fit: contain; }
.loading-title { color: #f1f5f9; font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; }
.loading-sub { color: #64748b; font-size: .82rem; }
.loading-spinner {
  width: 28px; height: 28px; margin-top: 4px;
  border: 3px solid rgba(255, 255, 255, .1); border-top-color: #6366f1;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sign-in screen ──────────────────────────────────────────────────────── */
#auth-ov {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--dark-grad);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .35s, visibility .35s;
}
#auth-ov.hidden { display: flex !important; opacity: 0; visibility: hidden; pointer-events: none; }
.auth-box {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  width: 100%; max-width: 340px; padding: 0 24px;
}
.auth-logo {
  width: 60px; height: 60px; border-radius: 14px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08);
}
.auth-logo img { width: 100%; height: 100%; object-fit: contain; }
.auth-title { color: #f1f5f9; font-size: 1.1rem; font-weight: 700; letter-spacing: -.02em; text-align: center; }
.auth-sub { color: #64748b; font-size: .8rem; text-align: center; margin-top: -12px; }
.auth-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.auth-inp {
  width: 100%; padding: 11px 16px;
  background: rgba(255, 255, 255, .06);
  border: 1.5px solid rgba(255, 255, 255, .1);
  border-radius: 12px; font-family: inherit; font-size: .95rem; color: #f1f5f9;
  transition: border-color .15s, box-shadow .15s;
}
.auth-inp:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99, 102, 241, .2); }
.auth-inp::placeholder { color: #475569; font-size: .85rem; }
.auth-btn {
  padding: 11px; border-radius: 12px; border: none; cursor: pointer;
  font-family: inherit; font-size: .9rem; font-weight: 600;
  background: var(--accent); color: #fff;
  transition: background .15s, transform .1s;
}
.auth-btn:hover { background: var(--accent-hover); }
.auth-btn:active { transform: scale(.98); }
.auth-btn-link {
  background: transparent; color: #94a3b8; font-weight: 500; padding: 4px;
  border: none; cursor: pointer; font-family: inherit; font-size: .82rem;
}
.auth-btn-link:hover { color: #cbd5e1; }
.auth-msg { font-size: .78rem; text-align: center; min-height: 1.2em; color: #f87171; }
.auth-msg.ok { color: #34d399; }
@keyframes auth-shake {
  0%, 100% { transform: none; }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(120%);
  z-index: 12000; display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-radius: 12px;
  background: #0d1117; color: #f1f5f9;
  font-size: .855rem; font-weight: 500; box-shadow: var(--sh-lg);
  transition: transform .28s cubic-bezier(.2, .8, .2, 1), opacity .28s;
  opacity: 0; pointer-events: none; max-width: min(560px, calc(100vw - 32px));
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }
#toast.err { background: #7f1d1d; }
.toast-act {
  background: rgba(255, 255, 255, .14); border: none; color: #fff;
  font-family: inherit; font-size: .8rem; font-weight: 600;
  padding: 5px 12px; border-radius: 8px; cursor: pointer; flex-shrink: 0;
}
.toast-act:hover { background: rgba(255, 255, 255, .24); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 80px 20px; color: var(--text3); }
.empty-i { font-size: 2.6rem; margin-bottom: 12px; opacity: .55; }
.empty p { font-size: .95rem; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }
