/* Halcyon base: reset, typography and shared components.
   Colours come only from the theme tokens (themes/*.css). */

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

:root {
  --font-scale: 1;
  --font-sans: "Inter var", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 18px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --speed: 180ms;
}

html { font-size: calc(15px * var(--font-scale)); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

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

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0 0 .8em; }
a { color: var(--accent-strong); text-decoration-thickness: 1px; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-s); }

/* scrollbars: thin and quiet */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* icons */
.i { width: 1.15em; height: 1.15em; stroke: currentColor; stroke-width: 1.8; fill: none;
     stroke-linecap: round; stroke-linejoin: round; flex: none; vertical-align: -0.2em; }
.i-fill { fill: currentColor; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  height: 2.4rem; padding: 0 1rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500;
  transition: background var(--speed) var(--ease), border-color var(--speed), transform var(--speed), box-shadow var(--speed);
  white-space: nowrap; text-decoration: none; font-size: .93rem;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-contrast); box-shadow: 0 6px 16px -8px var(--accent); }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 2rem; padding: 0 .8rem; font-size: .85rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: 10px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed);
  position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active, .icon-btn[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); }
.icon-btn:disabled { opacity: .4; cursor: default; }
/* Destructive actions read as red everywhere (toolbar, bulk bar, quick actions, menus). */
.icon-btn.danger, .bulk .icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.menu button.danger { color: var(--danger); }
.menu button.danger:hover { background: var(--danger-soft); }
.icon-btn .i { width: 1.2rem; height: 1.2rem; }

/* tooltips for [data-tip]: one floating element, see util.installTooltips */
.tooltip {
  position: fixed; z-index: 1000; pointer-events: none; max-width: min(22rem, 90vw);
  background: var(--text); color: var(--bg); font-size: .75rem; line-height: 1.35; padding: .3rem .6rem;
  border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, .18); opacity: 0; transition: opacity 120ms;
}
.tooltip.show { opacity: 1; }

/* forms */
.field { display: grid; gap: .35rem; margin-bottom: 1rem; }
.field > label, .label { font-size: .82rem; font-weight: 500; color: var(--text-2); }
.hint { font-size: .8rem; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 2.6rem; padding: 0 .85rem; border-radius: var(--radius-s);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: border-color var(--speed), box-shadow var(--speed);
}
.textarea { height: auto; min-height: 6rem; padding: .7rem .85rem; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.row { display: flex; gap: .75rem; align-items: center; }
.row > .grow { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: .75rem; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: .7rem; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 2.4rem; height: 1.4rem; border-radius: 999px; background: var(--border-strong); position: relative;
  transition: background var(--speed) var(--ease); flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: .2rem; left: .2rem; width: 1rem; height: 1rem; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow-1); transition: transform var(--speed) var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(1rem); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* segmented control */
.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  border: 0; background: transparent; padding: .35rem .9rem; border-radius: 999px; cursor: pointer; color: var(--text-2);
  font-size: .85rem; font-weight: 500; display: inline-flex; gap: .4rem; align-items: center;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* chips, tags, pills */
.chip {
  display: inline-flex; align-items: center; gap: .35rem; height: 1.45rem; padding: 0 .55rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  background: var(--p0-bg); color: var(--p0-fg);
}
.chip .x { border: 0; background: none; color: inherit; cursor: pointer; padding: 0; opacity: .6; display: inline-grid; }
.chip .x:hover { opacity: 1; }
.c0 { --c-bg: var(--p0-bg); --c-fg: var(--p0-fg); }
.c1 { --c-bg: var(--p1-bg); --c-fg: var(--p1-fg); }
.c2 { --c-bg: var(--p2-bg); --c-fg: var(--p2-fg); }
.c3 { --c-bg: var(--p3-bg); --c-fg: var(--p3-fg); }
.c4 { --c-bg: var(--p4-bg); --c-fg: var(--p4-fg); }
.c5 { --c-bg: var(--p5-bg); --c-fg: var(--p5-fg); }
.c6 { --c-bg: var(--p6-bg); --c-fg: var(--p6-fg); }
.c7 { --c-bg: var(--p7-bg); --c-fg: var(--p7-fg); }
.chip[class*=" c"], .chip[class^="c"] { background: var(--c-bg); color: var(--c-fg); }
.dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--c-fg, var(--accent)); flex: none; }

.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .6rem; border-radius: 999px;
        font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* avatars */
.avatar {
  width: 2.4rem; height: 2.4rem; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--c-bg, var(--p0-bg)); color: var(--c-fg, var(--p0-fg)); font-weight: 600; font-size: .85rem;
  letter-spacing: .02em; user-select: none;
}

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); padding: 1.4rem; box-shadow: var(--shadow-1); }

/* toasts */
.toasts { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 200; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: .9rem; padding: .7rem .8rem .7rem 1.1rem;
  background: var(--text); color: var(--bg); border-radius: 14px; box-shadow: var(--shadow-2); font-size: .9rem;
  animation: toast-in 240ms var(--ease) both; max-width: min(92vw, 520px);
}
.toast.error { background: var(--danger); color: #fff; }
.toast button { background: transparent; border: 0; color: inherit; font-weight: 600; cursor: pointer; padding: .2rem .5rem; border-radius: 8px; opacity: .9; }
.toast button:hover { background: rgba(255,255,255,.12); }
.toast.leaving { animation: toast-out 200ms var(--ease) both; }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes spin { to { transform: rotate(360deg); } }

.spinner { width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }

/* dialogs */
dialog {
  border: 0; padding: 0; border-radius: var(--radius-l); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2); max-width: calc(100vw - 2rem); max-height: calc(100dvh - 2rem);
}
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
dialog[open] { animation: rise 220ms var(--ease) both; }

.menu {
  position: fixed; z-index: 150; min-width: 13rem; max-height: 60vh; overflow: auto; padding: .35rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-2);
  animation: rise 140ms var(--ease) both;
}
.menu button, .menu a {
  display: flex; align-items: center; gap: .65rem; width: 100%; padding: .5rem .7rem; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); text-align: left; cursor: pointer; font-size: .9rem; text-decoration: none;
}
.menu button:hover, .menu button.active, .menu a:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: .3rem 0; }
.menu .menu-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: .45rem .7rem .2rem; }
.menu .menu-input { margin: .2rem .2rem .35rem; width: calc(100% - .4rem); height: 2.1rem; }

.kbd, kbd {
  font-family: var(--font-mono); font-size: .75rem; padding: .1rem .4rem; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; color: var(--text-2);
}

.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* soft pastel backdrop used by sign-in and empty states */
.blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blobs span { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .9; }
.blobs span:nth-child(1) { width: 46vmax; height: 46vmax; background: var(--blob-1); top: -18vmax; left: -12vmax; }
.blobs span:nth-child(2) { width: 38vmax; height: 38vmax; background: var(--blob-2); bottom: -16vmax; right: -10vmax; }
.blobs span:nth-child(3) { width: 26vmax; height: 26vmax; background: var(--blob-3); bottom: 8vmax; left: 18vmax; }
