/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius-pill);
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: var(--text-sm); line-height: 1; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), opacity var(--dur-fast);
  touch-action: manipulation; text-decoration: none;
}
.btn:hover { background: var(--accent-strong); text-decoration: none; }
.btn:active { opacity: 0.88; }
.btn[disabled], .btn.is-disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--bad-text); color: var(--surface); }
:root[data-theme="dark"] .btn.danger { background: #f07a8b; color: #1a0b0f; }
.btn.danger-ghost { background: transparent; color: var(--bad-text); border-color: transparent; }
.btn.danger-ghost:hover { background: var(--bad-bg); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: var(--text-xs); }
.btn.lg { min-height: 48px; padding: 0 24px; font-size: var(--text-md); }
.btn.icon-only { width: 40px; padding: 0; }
.btn.sm.icon-only { width: 34px; }
.btn .spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--text-sm); font-weight: 600; color: var(--text); }
.hint { font-size: var(--text-xs); color: var(--text-muted); }
.error-text { font-size: var(--text-xs); color: var(--bad-text); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23778' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad-text); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-faint); cursor: not-allowed; }
.input-wrap { position: relative; }
.input-wrap .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.input-wrap .input { padding-left: 38px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.check { display: flex; align-items: center; gap: 10px; font-size: var(--text-sm); cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { width: 42px; height: 24px; border-radius: var(--radius-pill); background: var(--surface-3); border: 1px solid var(--border-strong); position: relative; transition: background var(--dur-fast); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); border: 1px solid var(--border-strong); transition: transform var(--dur-fast) var(--ease); }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); border-color: var(--accent); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.5; }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: var(--radius-pill); border: 1px solid var(--border); }
.segmented button { border: 0; background: transparent; padding: 7px 14px; border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Cards and panels */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.card.pad { padding: var(--space-5); }
.card-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: var(--text-lg); }
.card-body { padding: var(--space-5); }
.card-body.flush { padding: 0; }

/* Badges: always an icon or label, never colour alone */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 600; background: var(--info-bg); color: var(--info-text); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.bad { background: var(--bad-bg); color: var(--bad-text); }
.badge.accent { background: var(--accent-weak); color: var(--on-accent-weak); }
.badge .icon { width: 13px; height: 13px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { font-size: var(--text-sm); }
.table th { text-align: left; font-weight: 600; color: var(--text-muted); padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); }
.table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .cell-title { font-weight: 600; color: var(--text); }
.table .cell-sub { font-size: var(--text-xs); color: var(--text-muted); }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.table tr.is-blocked td { opacity: 0.65; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a, .tabs button { padding: 12px 16px; border: 0; background: transparent; color: var(--text-muted); font-weight: 600; font-size: var(--text-sm); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; display: inline-flex; gap: 8px; align-items: center; }
.tabs a:hover, .tabs button:hover { color: var(--text); text-decoration: none; }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* Progress */
.progress { height: 8px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--accent); transition: width var(--dur) var(--ease); }
.progress.warn > span { background: var(--brand-gold); }
.progress.bad > span { background: var(--bad-text); }

/* Avatar */
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-weak); color: var(--on-accent-weak); display: inline-grid; place-items: center; font-weight: 700; font-size: var(--text-xs); flex: none; font-family: var(--font-display); }
.avatar.lg { width: 56px; height: 56px; font-size: var(--text-lg); }

/* Modal */
.modal-root { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: var(--space-4); }
.modal-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade var(--dur) var(--ease); }
.modal { position: relative; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); animation: pop var(--dur) var(--ease); }
.modal.wide { width: min(860px, 100%); }
.modal.xwide { width: min(1080px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: var(--text-lg); flex: 1; }
.modal-body { padding: var(--space-5); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); background: var(--surface); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.985); } }

/* Toasts */
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 40px)); }
.toast { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border-strong); border-left-width: 4px; border-radius: var(--radius-md); box-shadow: var(--shadow-md); font-size: var(--text-sm); animation: pop var(--dur) var(--ease); }
.toast.success { border-left-color: var(--accent); }
.toast.warn { border-left-color: var(--brand-gold); }
.toast.error { border-left-color: var(--bad-text); }
.toast strong { display: block; font-weight: 650; }
.toast .toast-close { margin-left: auto; border: 0; background: transparent; color: var(--text-muted); padding: 2px; border-radius: 6px; }

/* Popover menu */
.menu-wrap { position: relative; }
.menu { position: absolute; z-index: 60; top: calc(100% + 8px); right: 0; min-width: 220px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 6px; animation: pop var(--dur-fast) var(--ease); }
.menu.left { right: auto; left: 0; }
.menu button, .menu a { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; background: transparent; border-radius: var(--radius-sm); text-align: left; font-size: var(--text-sm); color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--surface-2); text-decoration: none; }
.menu hr { margin: 6px 0; }
.menu .menu-head { padding: 10px 12px 8px; }

/* Empty state */
.empty { text-align: center; padding: var(--space-7) var(--space-5); display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.empty .empty-icon { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-weak); color: var(--on-accent-weak); }
.empty h4 { font-size: var(--text-lg); }
.empty p { max-width: 42ch; color: var(--text-muted); }

/* Callouts */
.callout { display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--radius-md); background: var(--info-bg); color: var(--info-text); font-size: var(--text-sm); }
.callout.warn { background: var(--warn-bg); color: var(--warn-text); }
.callout.bad { background: var(--bad-bg); color: var(--bad-text); }
.callout.accent { background: var(--accent-weak); color: var(--on-accent-weak); }
.callout strong { font-weight: 650; }

/* Dropzone */
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-md); padding: var(--space-5); text-align: center; background: var(--surface-2); transition: border-color var(--dur-fast), background var(--dur-fast); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-weak); }
.dropzone .file-name { font-weight: 650; word-break: break-all; }

/* Key value list */
.kv { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; gap: 10px 20px; font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 10px; } }

/* Stat */
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .stat-value { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 650; letter-spacing: -0.03em; line-height: 1; }
.stat .stat-label { font-size: var(--text-sm); color: var(--text-muted); }

/* List rows */
.list-row { display: flex; align-items: center; gap: var(--space-3); padding: 14px var(--space-5); border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow > .title { font-weight: 600; font-size: var(--text-sm); }
.list-row .grow > .sub { font-size: var(--text-xs); color: var(--text-muted); }
a.list-row { color: inherit; text-decoration: none; }
a.list-row:hover { background: var(--surface-2); }

/* Filter bar */
.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.filters .input-wrap { flex: 1 1 240px; max-width: 360px; }
.filters .select { width: auto; min-width: 160px; }

/* Status dot used with text */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); display: inline-block; }
.dot.ok { background: var(--accent); }
.dot.warn { background: var(--brand-gold); }
.dot.bad { background: var(--bad-text); }
