/* Shared components used across every screen. Depends on tokens.css being
   loaded first. Plain CSS, no preprocessor, per CLAUDE.md. */

* { box-sizing: border-box; }

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.45;
  overflow-x: hidden; /* a very long unbroken URL must never widen the page */
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--space-3); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); margin-top: var(--space-6); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.icon-svg { display: inline-block; vertical-align: -0.2em; flex-shrink: 0; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }

/* Wherever a URL (or any single unbroken piece of text -- a title, a
   domain) needs to fit in a card's width instead of forcing the page to
   scroll sideways: one line, ellipsis, never wider than its container. */
.url-line {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wrap-anywhere { overflow-wrap: anywhere; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--fs-md);
  font-family: inherit;
  cursor: pointer;
  background: none;
  color: var(--text);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); text-decoration: none; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); text-decoration: none; }
.btn-ghost { background: none; color: var(--text-muted); padding-inline: 0.5rem; }
.btn-ghost:hover:not(:disabled) { color: var(--text); text-decoration: none; }
.btn-danger { color: var(--danger); }
.btn-danger.btn-primary { background: var(--danger); color: #fff; }
.btn-sm { min-height: 36px; padding: 0.35rem 0.75rem; font-size: var(--fs-sm); }
.btn-icon { min-width: var(--tap-min); padding: 0.5rem; }
.btn-block { width: 100%; }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  padding: 0;
  min-height: auto;
}
.link-btn.danger { color: var(--danger); }

/* ---------- Form controls ---------- */
.field { margin-bottom: var(--space-4); }
.field label { display: block; margin-bottom: 0.3rem; font-size: var(--fs-sm); color: var(--text-muted); }
.field-hint { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 0.25rem; }
.input, .select, .textarea, .field input, .field select, .field textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  font-size: var(--fs-md);
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.textarea, .field textarea { min-height: 5rem; resize: vertical; }
.input:focus, .select:focus, .textarea:focus,
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.checkbox-row, .radio-row { display: flex; align-items: center; gap: var(--space-2); min-height: var(--tap-min); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }

.search-input-wrap { position: relative; }
.search-input-wrap .search-icon {
  position: absolute; inset-inline-start: 0.75rem; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); pointer-events: none; font-size: 0.95rem;
}
.search-input-wrap input[type="search"] {
  width: 100%;
  padding: 0.6rem 0.9rem 0.6rem 2.25rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  font-size: var(--fs-md);
  min-height: var(--tap-min);
  background: var(--surface);
  color: var(--text);
}
[dir="rtl"] .search-input-wrap .search-icon { inset-inline-start: auto; inset-inline-end: 0.75rem; }
[dir="rtl"] .search-input-wrap input[type="search"] { padding: 0.6rem 2.25rem 0.6rem 0.9rem; }

form.inline { display: inline; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}

/* ---------- Badge / Chip ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: var(--fs-xs);
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-soon { background: var(--surface-2); color: var(--text-faint); font-style: italic; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: var(--fs-sm);
  padding: 0.3rem 0.4rem 0.3rem 0.75rem;
  border-radius: var(--radius-pill);
  background: var(--accent-tint);
  color: var(--accent);
  border: 1px solid transparent;
  min-height: 32px;
}
[dir="rtl"] .chip { padding: 0.3rem 0.75rem 0.3rem 0.4rem; }
.chip button {
  background: none; border: none; color: inherit; cursor: pointer; font-size: 1rem;
  line-height: 1; padding: 0.15rem; min-width: 24px; min-height: 24px; border-radius: 50%;
}
.chip button:hover { background: rgba(47, 111, 237, 0.15); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-bottom: var(--space-4); }

/* ---------- Table ---------- */
.table-wrap,
/* `.table-scroll` is the same thing under the name the newer screens use.
   Aliasing rather than renaming keeps every existing template working. A wide
   table MUST scroll inside its own box: the page itself never scrolls
   sideways, which is what `overflow-x: hidden` on the body relies on. */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table.simple, table.data-table { width: 100%; border-collapse: collapse; min-width: 560px; }
table.simple th, table.simple td,
table.data-table th, table.data-table td {
  text-align: start;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
table.data-table th { background: var(--surface-2); font-weight: 600; color: var(--text-muted); position: sticky; top: 0; }
table.data-table td.col-title { white-space: normal; max-width: 360px; }
table.simple tbody tr:last-child td, table.data-table tbody tr:last-child td { border-bottom: none; }

/* ---------- Toast ---------- */
.toast-stack {
  position: fixed;
  inset-inline: 0;
  bottom: calc(var(--space-4) + var(--bottom-nav-safe, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
  padding: 0 var(--space-4);
}
.toast {
  pointer-events: auto;
  background: var(--text);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.toast-success { background: var(--success); }
.toast-danger { background: var(--danger); }
.toast .toast-action { color: #fff; text-decoration: underline; font-weight: 600; white-space: nowrap; }

/* ---------- Modal / Sheet ---------- */
.modal-backdrop, .sheet-backdrop {
  position: fixed; inset: 0; background: rgba(15, 17, 22, 0.45);
  z-index: var(--z-modal); display: flex; align-items: center; justify-content: center;
}
.modal-backdrop[hidden], .sheet-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: min(480px, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
  overflow-y: auto;
  padding: var(--space-5);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.modal-header h2 { margin: 0; }

.sheet-backdrop { align-items: flex-end; z-index: var(--z-drawer); }
.sheet {
  background: var(--surface);
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-md);
  padding: var(--space-4) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
}
.sheet-grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--border-strong); margin: 0 auto var(--space-4); }
.sheet-title { font-size: var(--fs-lg); font-weight: 600; margin-bottom: var(--space-3); }
.sheet-option {
  display: flex; align-items: center; gap: var(--space-3);
  width: 100%; text-align: start; background: none; border: none;
  padding: var(--space-3) var(--space-2); min-height: calc(var(--tap-min) + 8px);
  font-size: var(--fs-md); color: var(--text); border-radius: var(--radius-sm); cursor: pointer;
}
.sheet-option:hover:not(:disabled) { background: var(--surface-2); }
.sheet-option:disabled { color: var(--text-faint); cursor: not-allowed; }
.sheet-option .icon { width: 24px; text-align: center; flex-shrink: 0; }

/* On desktop a "sheet" reads better as a centered panel, same markup. */
@media (min-width: 768px) {
  .sheet-backdrop { align-items: center; }
  .sheet {
    width: min(420px, calc(100vw - 2rem));
    max-height: calc(100vh - 4rem);
    border-radius: var(--radius-lg);
  }
}

/* ---------- Empty state / Skeleton ---------- */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-7) var(--space-4);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: var(--space-3); }
.empty-state .btn { margin-top: var(--space-3); }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sf-shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes sf-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-card { height: 96px; margin-bottom: var(--space-3); border-radius: var(--radius-md); }

/* ---------- Misc carried over ---------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); margin: var(--space-4) 0; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); background: var(--surface); }
.plan-card.active { border-color: var(--accent); }

.action-list-group { margin-bottom: var(--space-5); }
.action-item { display: flex; align-items: center; gap: var(--space-3); padding: 0.6rem 0.2rem; border-bottom: 1px solid var(--border); min-height: var(--tap-min); }
.action-item.completed .title { text-decoration: line-through; color: var(--text-muted); }
.action-item .due { margin-inline-start: auto; font-size: var(--fs-xs); color: var(--text-muted); }

.error-msg { color: var(--danger); font-size: var(--fs-sm); margin-bottom: var(--space-4); background: var(--danger-bg); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); }
.success-msg { color: var(--success); font-size: var(--fs-sm); margin-bottom: var(--space-4); background: var(--success-bg); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); }

.auth-shell { max-width: 380px; margin: 4rem auto; padding: var(--space-6); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.auth-shell h1 { font-size: var(--fs-xl); margin-top: 0; }

/* --- Shared links and export tables -------------------------------------- */

/* Each row carries three small forms (change expiry, new link, revoke). Laid
   out inline they force the table far wider than a phone, which is what the
   screenshot run's overflow check caught. They wrap instead, and the table
   still scrolls inside its own box if the content needs it. */
.data-table td.row-actions { white-space: normal; }
.data-table td.row-actions .inline-form {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin: 0 var(--space-1) var(--space-1) 0;
}
.data-table td.row-actions .input-sm { width: auto; min-width: 8rem; }
.data-table td.share-settings { white-space: normal; }
.data-table td.share-settings .badge { margin: 0 var(--space-1) var(--space-1) 0; }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.85em; }
.input-sm { padding: 0.25rem 0.5rem; font-size: 0.9em; }

.is-inactive { opacity: 0.6; }
.plan-price { margin: 0 0 var(--space-2); }
.plan-card.is-soldout { opacity: 0.75; }
/* Radio, then its name, then its explanation -- the control lines up with the
   text rather than sitting on a line of its own above it. */
.choice {
  display: grid;
  /* minmax(0, 1fr) so a long label wraps instead of widening the row. */
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 var(--space-2);
  align-items: baseline;
  margin-bottom: var(--space-3);
  cursor: pointer;
}
.choice input { grid-row: 1; }
.choice > span { grid-column: 2; font-weight: 600; }
.choice > small { grid-column: 2; }
.choice-locked { opacity: 0.65; }
.choice small { display: block; }
.summary-list dt { font-weight: 600; margin-top: var(--space-2); }
.summary-list dd { margin: 0 0 var(--space-1); }
.warn-text { color: var(--warn, #a15c00); }
.bulk-secondary { margin-top: var(--space-2); display: flex; gap: var(--space-2); flex-wrap: wrap; }
.callout { border-inline-start: 3px solid var(--border); padding-inline-start: var(--space-3); }
.callout-success { border-inline-start-color: var(--ok, #1f7a44); }
.callout-soon { border-inline-start-color: var(--border); }

/* --- Public share page ---------------------------------------------------- */

.share-public .share-content { max-width: 46rem; margin: 0 auto; padding: var(--space-4) var(--space-3); }
.share-list { list-style: none; padding: 0; margin: 0; }
.share-card { margin-bottom: var(--space-3); }
.share-card-title { font-size: 1.05rem; margin: 0 0 var(--space-1); }
.share-card-title.is-done { text-decoration: line-through; }
.share-note { white-space: pre-wrap; overflow-wrap: anywhere; }
.share-meta span + span::before { content: ' · '; }
.share-footer { margin-top: var(--space-5); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.share-gate { max-width: 26rem; }

/* --- Tables that become cards on a phone ---------------------------------- */

/*
 * A six-column table is fine on a laptop and useless on a phone: even inside a
 * scrolling box, reading it means dragging sideways and losing the header.
 * Below 640px these tables become one card per row, with each cell labelled by
 * the column it came from (the label is carried in `data-label`, filled from
 * the same translation the header uses, so the two cannot drift apart).
 *
 * `.stacks-on-mobile` is opt-in: tables where every column is short keep the
 * normal layout.
 */
@media (max-width: 639px) {
  .table-scroll:has(.stacks-on-mobile),
  .table-wrap:has(.stacks-on-mobile) {
    overflow-x: visible;
    border: none;
  }

  table.stacks-on-mobile,
  table.stacks-on-mobile tbody,
  table.stacks-on-mobile tr,
  table.stacks-on-mobile td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  /* The header row is not lost, it moves onto each cell as a label. */
  table.stacks-on-mobile thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  table.stacks-on-mobile tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    background: var(--surface);
  }

  table.stacks-on-mobile td {
    border: none;
    padding: var(--space-1) 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  table.stacks-on-mobile td::before {
    content: attr(data-label);
    display: block;
    font-size: var(--fs-xs);
    color: var(--text-muted);
    margin-bottom: 2px;
  }

  /* A cell with nothing in it would otherwise show a lonely label. */
  table.stacks-on-mobile td:empty { display: none; }

  /* The row's controls each get a full line, so nothing wraps into a shape
     that is hard to hit with a thumb. */
  table.stacks-on-mobile td.row-actions .inline-form {
    display: flex;
    width: 100%;
    margin: 0 0 var(--space-2);
  }
  table.stacks-on-mobile td.row-actions .input-sm { flex: 1; min-width: 0; }
  table.stacks-on-mobile td.row-actions .btn { white-space: nowrap; }
}
