/* ============================================================
   All-In-One — design system
   Tokens, base elements, and the components used app-wide.
   ============================================================ */

:root {
  /* dark is the default; [data-theme="light"] overrides below */
  --bg:            #0b0d12;
  --surface:       #12151d;
  --surface-2:     #171b25;
  --surface-3:     #1d2230;
  --border:        #242a3a;
  --border-strong: #323a4f;
  --text:          #e7eaf2;
  --text-dim:      #9aa3b8;
  --text-faint:    #6b7488;

  --accent:        #6366f1;
  --accent-hover:  #7c7ff3;
  --accent-soft:   #6366f11f;
  --accent-text:   #a5b0ff;

  --green:  #22c55e;  --green-soft:  #22c55e1f;
  --amber:  #f59e0b;  --amber-soft:  #f59e0b1f;
  --red:    #ef4444;  --red-soft:    #ef44441f;
  --blue:   #3b82f6;  --blue-soft:   #3b82f61f;
  --purple: #a855f7;  --purple-soft: #a855f71f;

  --r-sm: 6px;  --r-md: 10px;  --r-lg: 14px;  --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.28);
  --shadow-md: 0 6px 20px -4px rgba(0,0,0,.42);
  --shadow-lg: 0 24px 60px -12px rgba(0,0,0,.6);

  --sidebar-w: 268px;
  --topbar-h: 52px;
  --fast: 120ms cubic-bezier(.3,.7,.4,1);
  --med: 220ms cubic-bezier(.3,.7,.4,1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          "Noto Sans", Ubuntu, Cantarell, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="light"] {
  --bg:            #f6f7fa;
  --surface:       #ffffff;
  --surface-2:     #ffffff;
  --surface-3:     #f1f3f7;
  --border:        #e3e7ef;
  --border-strong: #cdd4e0;
  --text:          #161a23;
  --text-dim:      #5b6478;
  --text-faint:    #8a92a4;
  --accent-text:   #4f46e5;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow-md: 0 6px 20px -4px rgba(16,24,40,.12);
  --shadow-lg: 0 24px 60px -12px rgba(16,24,40,.18);
}

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

/* A class like `.boot { display: grid }` beats the browser's own
   [hidden] rule, leaving invisible elements still catching clicks. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { margin: 0; font-weight: 640; letter-spacing: -.011em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75em; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--mono); font-size: .9em; }

::selection { background: var(--accent); color: #fff; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Thin, unobtrusive scrollbars that still work with a trackpad. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 99px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ---------------- boot screen ---------------- */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--bg);
  z-index: 100;
}
.boot-mark {
  width: 46px; height: 46px;
  border-radius: var(--r-lg);
  background: linear-gradient(135deg, #818cf8, #6366f1);
  animation: bootPulse 1.4s ease-in-out infinite;
}
.boot-text { color: var(--text-faint); font-size: 13px; margin: 0; }
@keyframes bootPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(.88); opacity: .55; }
}

.noscript {
  position: fixed; inset: 0;
  display: grid; place-content: center;
  padding: 24px; text-align: center;
  background: var(--bg); color: var(--text);
}

/* ---------------- buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 520;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--fast), border-color var(--fast), transform var(--fast), opacity var(--fast);
  user-select: none;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); border-color: transparent; }

.btn-danger { background: var(--red-soft); border-color: transparent; color: #f87171; }
.btn-danger:hover:not(:disabled) { background: var(--red); color: #fff; border-color: var(--red); }

.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn-lg { height: 42px; padding: 0 20px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

/* ---------------- form controls ---------------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; font-weight: 560; color: var(--text-dim); }
.field-hint { font-size: 12px; color: var(--text-faint); }
.field-error { font-size: 12px; color: #f87171; }

.input, .textarea, .select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color var(--fast), box-shadow var(--fast);
}
[data-theme="light"] .input,
[data-theme="light"] .textarea,
[data-theme="light"] .select { background: var(--surface); }

.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:disabled, .textarea:disabled { opacity: .6; cursor: not-allowed; }
.textarea { resize: vertical; min-height: 84px; line-height: 1.55; }

.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%239aa3b8' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

/* Font-size 16px stops iOS Safari zooming in when a field is focused. */
@media (max-width: 760px) {
  .input, .textarea, .select { font-size: 16px; }
}

.checkbox { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13.5px; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }

.switch {
  position: relative; width: 38px; height: 22px; flex: none;
  border-radius: 99px; background: var(--border-strong);
  cursor: pointer; transition: background var(--fast); border: none; padding: 0;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform var(--fast);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* ---------------- surfaces ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}

.divider { height: 1px; background: var(--border); border: 0; margin: 16px 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; line-height: 1.7;
  background: var(--surface-3); color: var(--text-dim);
  white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  font-size: 11px; font-weight: 640; color: #fff;
  background: var(--accent);
  user-select: none;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 21px; height: 21px; font-size: 9.5px; }
.avatar-lg { width: 40px; height: 40px; font-size: 15px; }
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar + .avatar { margin-left: -7px; box-shadow: 0 0 0 2px var(--surface); }

kbd {
  display: inline-block;
  min-width: 19px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-3);
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font);
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
}

.empty {
  display: grid; place-items: center; gap: 10px;
  padding: 56px 24px; text-align: center; color: var(--text-faint);
}
.empty h3 { color: var(--text-dim); font-weight: 600; }
.empty p { max-width: 380px; font-size: 13.5px; margin: 0; }

.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- toasts ---------------- */

.toasts {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 90;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 240px; max-width: min(380px, calc(100vw - 32px));
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  pointer-events: auto;
  animation: toastIn var(--med);
}
.toast-error { border-left-color: var(--red); }
.toast-success { border-left-color: var(--green); }
.toast-close {
  margin-left: auto; padding: 0; border: 0; background: none;
  color: var(--text-faint); cursor: pointer; font-size: 15px; line-height: 1;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(.97); }
  to { opacity: 1; transform: none; }
}

/* ---------------- modals ---------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(3, 5, 10, .6);
  backdrop-filter: blur(3px);
  z-index: 80;
  animation: fadeIn var(--fast);
}
.modal {
  width: min(520px, 100%);
  max-height: min(86vh, 760px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  animation: modalIn var(--med);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { flex: 1; font-size: 15.5px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-wide { width: min(760px, 100%); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 560px) {
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  @keyframes modalIn {
    from { opacity: .4; transform: translateY(100%); }
    to { opacity: 1; transform: none; }
  }
}

/* ---------------- menus ---------------- */

.menu {
  position: fixed;
  min-width: 190px;
  max-height: 60vh;
  padding: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  z-index: 85;
  overflow-y: auto;
  animation: menuIn var(--fast);
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.menu-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  padding: 7px 9px;
  border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text);
  font: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.menu-item:hover, .menu-item.active { background: var(--surface-3); }
.menu-item[disabled] { opacity: .45; cursor: default; }
.menu-item .shortcut { margin-left: auto; color: var(--text-faint); font-size: 11px; }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--border); }
.menu-label {
  padding: 7px 9px 3px;
  font-size: 11px; font-weight: 640;
  color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em;
}

/* ---------------- utilities ---------------- */

.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
