/* ==========================================================================
   ausbeds · light design system · components
   Depends on tokens.css. Internal-tools vocabulary: buttons, inputs,
   selects, cards, tables, badges, status, modals, tabs, toolbars, lists.
   ========================================================================== */

/* ============================= BUTTONS ================================== */
/* Rectangular (radius-md), not pill. Primary is marker-cyan, secondary is
   white with a line, ghost is transparent, danger is red fill. An "ink"
   variant remains for the rare brand-true CTA moment. */

.btn {
  --btn-bg:        var(--accent);
  --btn-fg:        var(--accent-fg);
  --btn-border:    transparent;
  --btn-bg-hover:  var(--accent-hover);
  --btn-bg-active: var(--accent-active);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: 7px 14px;
  min-height: 32px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard);
  user-select: none;
}
.btn:hover  { background: var(--btn-bg-hover); }
.btn:active { background: var(--btn-bg-active); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn[disabled], .btn:disabled {
  opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

.btn--secondary {
  --btn-bg:        var(--bg-panel);
  --btn-fg:        var(--fg-1);
  --btn-border:    var(--line-2);
  --btn-bg-hover:  var(--bg-hover);
  --btn-bg-active: var(--bg-active);
}
.btn--ghost {
  --btn-bg:        transparent;
  --btn-fg:        var(--fg-2);
  --btn-border:    transparent;
  --btn-bg-hover:  var(--bg-hover);
  --btn-bg-active: var(--bg-active);
}
.btn--ghost:hover { color: var(--fg-1); }

.btn--danger {
  --btn-bg:        var(--danger);
  --btn-fg:        #fff;
  --btn-border:    transparent;
  --btn-bg-hover:  #951F19;
  --btn-bg-active: #7A1914;
}
.btn--ink {
  --btn-bg:        var(--ink);
  --btn-fg:        #fff;
  --btn-border:    transparent;
  --btn-bg-hover:  #000;
  --btn-bg-active: #000;
}

.btn--sm { padding: 4px 10px; min-height: 26px; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn--lg { padding: 10px 18px; min-height: 40px; font-size: var(--fs-md); }
.btn--icon { padding: 0; width: 32px; min-height: 32px; }
.btn--icon.btn--sm { width: 26px; min-height: 26px; }
.btn--block { display: flex; width: 100%; }

/* Icon slot inside buttons — svg at currentColor */
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn--lg svg { width: 16px; height: 16px; }


/* ============================= INPUTS =================================== */
.input, .textarea, .select {
  display: block;
  width: 100%;
  padding: 6px 10px;
  min-height: 32px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  line-height: 1.4;
  color: var(--fg-1);
  background: var(--bg-panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--fg-4); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--gray-400); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
.input[disabled], .textarea[disabled], .select[disabled] {
  background: var(--bg-sunken); color: var(--fg-3); cursor: not-allowed;
}
.textarea { min-height: 72px; resize: vertical; line-height: 1.5; }
.input--sm { min-height: 26px; padding: 3px 8px; font-size: var(--fs-xs); }
.input--lg { min-height: 40px; font-size: var(--fs-md); padding: 8px 12px; }

.input--invalid, .input.is-invalid {
  border-color: var(--danger);
}
.input--invalid:focus, .input.is-invalid:focus {
  box-shadow: 0 0 0 3px rgba(179,38,30,0.25);
}

/* Select native chevron */
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='none' stroke='%2371717A' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' d='M3 4.5l3 3 3-3'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-1);
}
.label--req::after {
  content: '*';
  color: var(--danger);
  margin-left: 3px;
}
.help {
  margin-top: 4px;
  font-size: var(--fs-xs);
  color: var(--fg-3);
}
.help--error { color: var(--danger); }

.field { display: flex; flex-direction: column; }
.field + .field { margin-top: var(--space-5); }

/* Input-with-icon wrapper */
.input-wrap {
  position: relative;
  display: block;
}
.input-wrap > svg {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 9px;
  width: 14px; height: 14px;
  color: var(--fg-3);
  pointer-events: none;
}
.input-wrap .input { padding-left: 30px; }

/* Checkbox + radio — minimal, accent-coloured */
.checkbox, .radio {
  appearance: none;
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border: 1.5px solid var(--line-2);
  background: var(--bg-panel);
  cursor: pointer;
  display: inline-block;
  vertical-align: -2px;
  flex-shrink: 0;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.checkbox { border-radius: 3px; }
.radio { border-radius: 999px; }
.checkbox:hover, .radio:hover { border-color: var(--gray-400); }
.checkbox:focus-visible, .radio:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2.5 6.5l2.5 2.5 4.5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px 10px;
}
.radio:checked {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 3px #fff;
}


/* ============================= CARDS / PANELS =========================== */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--line-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}
.card--flat     { box-shadow: none; }
.card--raised   { box-shadow: var(--shadow-sm); }
.card--elevated { box-shadow: var(--shadow-md); border-color: transparent; }

.card-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line-3);
}
.card-title {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--fg-1);
  flex: 1;
}
.card-sub {
  font-size: var(--fs-xs);
  color: var(--fg-3);
}
.card-body { padding: var(--space-5); }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--line-3);
  background: var(--bg-sunken);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}


/* ============================= BADGES / STATUS ========================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: var(--fs-2xs);
  font-weight: 600;
  line-height: 1.5;
  color: var(--fg-2);
  background: var(--neutral-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}
.badge--pill    { border-radius: var(--radius-pill); padding: 2px 10px; }
.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--accent  { background: var(--accent-soft); color: var(--accent-active); }
.badge--ink     { background: var(--ink); color: #fff; }
.badge--outline { background: transparent; border-color: var(--line-2); color: var(--fg-2); }

/* Dot-prefixed badge for live status */
.badge--dot::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 999px;
  background: currentColor;
  margin-right: 2px;
}


/* ============================= TABS ===================================== */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--line-1);
  padding: 0 var(--space-5);
}
.tab {
  position: relative;
  padding: 10px 12px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--fg-3);
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  transition: color var(--dur-fast);
}
.tab:hover { color: var(--fg-1); }
.tab[aria-selected="true"], .tab.is-active {
  color: var(--fg-1);
}
.tab[aria-selected="true"]::after, .tab.is-active::after {
  content: '';
  position: absolute;
  left: 8px; right: 8px; bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

/* Segmented control — tighter, for inline switches */
.segmented {
  display: inline-flex;
  padding: 2px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-1);
  border-radius: var(--radius-sm);
}
.segmented > button {
  padding: 4px 10px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--fg-3);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.segmented > button:hover { color: var(--fg-1); }
.segmented > button[aria-selected="true"],
.segmented > button.is-active {
  background: var(--bg-panel);
  color: var(--fg-1);
  box-shadow: var(--shadow-xs);
}


/* ============================= TABLES =================================== */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-sm);
}
.table th, .table td {
  padding: 8px 12px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line-3);
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-sunken);
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--fg-3);
  border-bottom: 1px solid var(--line-1);
  white-space: nowrap;
}
.table thead th.is-sortable { cursor: pointer; user-select: none; }
.table thead th.is-sortable:hover { color: var(--fg-1); }
.table tbody tr { transition: background var(--dur-fast); }
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr.is-selected {
  background: var(--accent-softer);
  box-shadow: inset 2px 0 0 var(--accent);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table--zebra tbody tr:nth-child(even) { background: var(--bg-sunken); }
.table--zebra tbody tr:nth-child(even):hover { background: var(--bg-hover); }
.table--compact th, .table--compact td { padding: 5px 10px; }
.table--bordered {
  border: 1px solid var(--line-1);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.table--bordered th, .table--bordered td { border-right: 1px solid var(--line-3); }
.table--bordered th:last-child, .table--bordered td:last-child { border-right: 0; }


/* ============================= LIST ROWS ================================
   Generic row pattern for inbox / queue / dense lists. */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-3);
  cursor: pointer;
  transition: background var(--dur-fast);
}
.list-item:hover { background: var(--bg-hover); }
.list-item.is-selected {
  background: var(--accent-softer);
  box-shadow: inset 3px 0 0 var(--accent);
}
.list-item.is-unread { background: var(--bg-panel); }
.list-item.is-read   { background: var(--bg-sunken); }
.list-item-main { flex: 1; min-width: 0; }
.list-item-top {
  display: flex; align-items: baseline; gap: var(--space-3);
  margin-bottom: 2px;
}
.list-item-name {
  font-weight: 600; font-size: var(--fs-sm); color: var(--fg-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-item-time {
  margin-left: auto;
  font-size: var(--fs-2xs);
  color: var(--fg-3);
  flex-shrink: 0;
}
.list-item-title {
  font-size: var(--fs-sm); color: var(--fg-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-item-preview {
  font-size: var(--fs-xs); color: var(--fg-3);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}


/* ============================= TOOLBAR / FILTER BAR ===================== */
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line-1);
  min-height: 44px;
}
.toolbar > .spacer { flex: 1; }
.toolbar-group {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
}

/* Chip-style filter token */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 10px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--fg-1);
  background: var(--bg-sunken);
  border: 1px solid var(--line-1);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.chip:hover { border-color: var(--line-2); }
.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-active);
}
.chip > .chip-x {
  font-size: 14px; line-height: 1;
  color: var(--fg-4);
  margin-left: 2px;
}
.chip:hover > .chip-x { color: var(--fg-2); }


/* ============================= MODAL / DRAWER ===========================
   Minimal, JS-toggleable. Set .is-open on the backdrop to show. */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(14,14,16,0.32);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-med) var(--ease-standard);
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }

.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: var(--bg-panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(6px) scale(0.99);
  transition: transform var(--dur-med) var(--ease-standard);
}
.modal-backdrop.is-open .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-5);
  border-bottom: 1px solid var(--line-3);
}
.modal-title { font-size: var(--fs-lg); font-weight: 700; flex: 1; }
.modal-body { padding: var(--space-5); overflow: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-3);
  padding: var(--space-5);
  border-top: 1px solid var(--line-3);
  background: var(--bg-sunken);
}

.drawer {
  position: fixed; top: 0; bottom: 0; right: 0;
  width: min(480px, 100vw);
  background: var(--bg-panel);
  border-left: 1px solid var(--line-1);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-standard);
  z-index: 90;
  display: flex;
  flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }


/* ============================= BANNER / CALLOUT ========================= */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 10px 14px;
  font-size: var(--fs-sm);
  color: var(--fg-1);
  background: var(--info-bg);
  border: 1px solid var(--info-line);
  border-radius: var(--radius-sm);
}
.banner--success { background: var(--success-bg); border-color: var(--success-line); }
.banner--warning { background: var(--warning-bg); border-color: var(--warning-line); }
.banner--danger  { background: var(--danger-bg);  border-color: var(--danger-line); }
.banner-title { font-weight: 700; }
.banner-body  { color: var(--fg-2); }


/* ============================= AVATAR =================================== */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-active);
  font-size: var(--fs-xs);
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--sm { width: 22px; height: 22px; font-size: 10px; }
.avatar--lg { width: 40px; height: 40px; font-size: var(--fs-md); }


/* ============================= APP SHELL PRIMITIVES ===================== */
.app-topbar {
  display: flex; align-items: center; gap: var(--space-4);
  height: var(--chrome-topbar-h);
  padding: 0 var(--space-5);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line-1);
  flex-shrink: 0;
}
.app-sidebar {
  width: var(--chrome-sidebar-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--line-1);
  display: flex;
  flex-direction: column;
  padding: var(--space-4) var(--space-3);
  flex-shrink: 0;
  gap: 2px;
}
.navlink {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 6px 10px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--fg-2);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.navlink:hover { background: var(--bg-hover); color: var(--fg-1); text-decoration: none; }
.navlink.is-active {
  background: var(--accent-soft);
  color: var(--accent-active);
  font-weight: 600;
}
.navlink svg { width: 15px; height: 15px; flex-shrink: 0; opacity: 0.85; }
.navlink-count {
  margin-left: auto;
  font-size: var(--fs-2xs);
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}

.nav-section {
  padding: var(--space-4) var(--space-3) var(--space-2);
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--fg-3);
}
.nav-section:first-child { padding-top: 0; }


/* ============================= DIVIDERS / HR ============================ */
.hr {
  border: 0;
  border-top: 1px solid var(--line-1);
  margin: var(--space-6) 0;
}
.hr--dashed { border-top-style: dashed; }


/* ============================= UTILITIES ================================ */
.stack { display: flex; flex-direction: column; }
.row   { display: flex; align-items: center; }
.grow  { flex: 1; }
.muted { color: var(--fg-3); }
.mono  { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }
