/*
 * Base layer. Tokens come from tokens.css; nothing here hardcodes a color.
 * Component styles live next to their components as .razor.css.
 */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Removes the 300ms tap delay without disabling pinch zoom. */
  touch-action: manipulation;
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: var(--leading-tight);
  font-weight: var(--weight-semibold);
  text-wrap: balance;
}

h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p {
  margin: 0;
  text-wrap: pretty;
}

/* Numbers that change in place must not shift the layout around them. */
.tabular,
time,
.duration,
.counter {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ---------------------------------------------------------------- focus */

/* Focus is never removed, only replaced with something better. */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/*
 * Blazor's FocusOnNavigate moves focus to the page heading after a route change so
 * screen readers announce the new page. Chromium treats that programmatic focus as
 * focus-visible and draws a ring around the heading, which reads as a rendering
 * bug. Suppress it only for these roving targets; real interactive elements keep
 * their ring.
 */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}

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

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

button:disabled,
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.45;
}

/* Height comes from the density token, not from the touch minimum. --control-h
   is 32px for a cursor and 44px for a thumb, which is the whole point of having
   it; hard-coding the touch size made every button on the desktop finger-sized. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-3);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--ink);
}

.btn-danger {
  background: var(--danger);
  color: var(--on-danger);
}

/* ---------------------------------------------------------------- forms */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Labels sit above their input. A placeholder is never a label. */
.field > label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--ink-muted);
}

.field input,
.field textarea,
.field select {
  min-height: var(--control-h);
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--ink-faint);
}

.field input:hover,
.field textarea:hover {
  border-color: var(--border-strong);
}

.field-hint {
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

/* Errors sit below the field they belong to, never only at the top of a form. */
.field-error {
  font-size: var(--text-xs);
  color: var(--danger);
}

.field[data-invalid="true"] input,
.field[data-invalid="true"] textarea {
  border-color: var(--danger);
}

/* ---------------------------------------------------------------- utility */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.muted {
  color: var(--ink-muted);
}

.prose {
  max-width: var(--measure);
}

.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;
}

/* Anything wide scrolls inside itself. The page body never scrolls sideways. */
.scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

/* ---------------------------------------------------------------- loading */

/* Skeletons match the shape of the content they stand in for. */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-3) 25%,
    var(--surface-hover) 37%,
    var(--surface-3) 63%
  );
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
  from { background-position: 100% 50%; }
  to   { background-position: 0 50%; }
}

/* Named shapes rather than inline width/height. A strict CSP refuses style
   attributes, and the ragged widths were only ever meant to look like text. */
.skeleton-title { height: 12px; width: 38%; }
.skeleton-line  { height: 10px; width: 72%; }
.skeleton-line-short { height: 10px; width: 48%; }
.skeleton-line-long  { height: 10px; width: 88%; }
.skeleton-heading { height: 28px; width: 45%; }
.skeleton-block { height: 56px; }

/* Varied per row, so a column of skeletons reads as several lines of text
   rather than a stack of identical bars. Keyed off the row, not the bar. */
.row-skeleton:nth-child(3n) .skeleton-title { width: 52%; }
.row-skeleton:nth-child(3n) .skeleton-line  { width: 61%; }
.row-skeleton:nth-child(3n + 2) .skeleton-title { width: 30%; }
.row-skeleton:nth-child(3n + 2) .skeleton-line  { width: 84%; }

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
    background: var(--surface-3);
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------- safe areas */

.safe-top    { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

/* ---------------------------------------------------------------- auth */

.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--space-4);
}

.auth-card {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-8);
}

.auth-callback {
  align-items: center;
  text-align: center;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}

.auth-mark {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
}

.auth-title {
  font-size: var(--text-2xl);
  margin-top: var(--space-2);
}

.auth-sub {
  color: var(--ink-muted);
  font-size: var(--text-sm);
  margin-top: calc(var(--space-2) * -1);
}

.auth-status {
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

.auth-error {
  padding: var(--space-3);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  font-size: var(--text-sm);
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.auth-submit,
.auth-google {
  width: 100%;
}

.field-optional {
  font-weight: var(--weight-regular);
  color: var(--ink-faint);
}

/* A hairline with the word "or" sitting in a gap, rather than a boxed label. */
.auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--ink-faint);
  font-size: var(--text-2xs);
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-switch {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

/* A button that has to read as a link, because it changes mode rather than navigating. */
.linklike {
  color: var(--primary);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.linklike:hover {
  color: var(--primary-hover);
}

/* ---------------------------------------------------------------- editor */

.save-failed {
  color: var(--danger);
}

.danger-text {
  color: var(--danger);
}

.danger-text:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
}

/* The editor is the page. No boxes around the text: a border here would make
   writing feel like filling in a form. */
.editor-title,
.editor-text {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 0;
  resize: none;
}

.editor-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.editor-text {
  font-size: var(--text-base);
  line-height: var(--leading-body);
  min-height: 60vh;
  /* Prose measure, so long lines stay readable on a wide screen. */
  max-width: var(--measure);
}

.editor-title::placeholder,
.editor-text::placeholder {
  color: var(--ink-faint);
}

.editor-title:focus,
.editor-text:focus {
  outline: none;
}

/* The focus ring belongs on the page region, not around each field: a ring drawn
   around a full-height textarea is a box the design deliberately avoids. */
.editor-body:focus-within {
  outline: none;
}

/* ---------------------------------------------------------------- note list */

.note-link {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
  text-decoration: none;
  color: inherit;
}

.note-link:hover .note-title {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.note-snippet {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-row.is-pinned .note-title::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: var(--space-2);
  border-radius: 50%;
  background: var(--primary);
  vertical-align: middle;
}

.callout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}

.callout-danger {
  border-color: var(--danger);
  background: var(--danger-soft);
}

/* ---------------------------------------------------------------- session check */

/* Shown while the stored session is being restored. Brief on the web, longer on a
   cold desktop launch, and never nothing: a blank window reads as a crash. */
.boot-guard {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 100dvh;
}

.boot-guard-mark {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-md);
  background: var(--primary);
  animation: boot-pulse 1.6s var(--ease-out) infinite;
}

.boot-guard-text {
  font-size: var(--text-sm);
  color: var(--ink-muted);
}

@keyframes boot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.92); }
}

@media (prefers-reduced-motion: reduce) {
  .boot-guard-mark {
    animation: none;
  }
}

/* A smaller button for places that sit inside a row of content rather than in a
   page header: the transcribe action on a recording, for instance. */
.btn-sm {
  height: 26px;
  padding: 0 var(--space-2);
  font-size: var(--text-2xs);
}

/* Links that behave like buttons inside a sentence. */
.linklike {
  border: none;
  background: none;
  padding: 0;
  color: var(--primary);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* A transcript is prose, so it gets prose treatment: a readable measure and
   room to breathe, rather than the dense chrome the rest of the row uses. */
.transcript {
  margin-top: var(--space-1);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-2);
}

.transcript summary {
  font-size: var(--text-2xs);
  color: var(--ink-muted);
  cursor: pointer;
}

.transcript-text {
  margin-top: var(--space-2);
  max-width: 68ch;
  font-size: var(--text-xs);
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
}

.audio-note {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-2xs);
  color: var(--ink-muted);
}
