/* Base reset, UI tokens and shared components. Design pass follows Unslop by Damir Sokolovsky (CC BY 4.0). */
:root {
  --ui-bg: light-dark(#f6f5f2, #191817);
  --ui-bg-2: light-dark(#eeece8, #151413);
  --ui-panel: light-dark(#fdfcf9, #22201e);
  --ui-panel-2: light-dark(#eeece7, #2c2926);
  --ui-text: light-dark(#292621, #f4efe7);
  --ui-secondary: light-dark(#514b42, #c5bdb2);
  --ui-muted: light-dark(#686056, #a49b90);
  --ui-border: color-mix(in srgb, var(--ui-text) 10%, transparent);
  --ui-primary: light-dark(#834b1d, #edbf78);
  --ui-primary-text: light-dark(#fffaf2, #281c10);
  --ui-danger: light-dark(#a53733, #ee948b);
  --ui-success: light-dark(#276447, #8bc3a1);
  --ui-warning: light-dark(#815318, #e6bb7c);
  --ui-focus: var(--ui-primary);
  --ui-radius: 8px;
  --ui-shadow: 0 8px 24px light-dark(rgb(0 0 0 / .12), rgb(0 0 0 / .24));
  --ui-ease: cubic-bezier(.2, .7, .3, 1);
  --ui-font: 'Segoe UI', system-ui, sans-serif;
  --ui-mono: ui-monospace, 'Cascadia Code', Consolas, monospace;
  color-scheme: light dark;
}
:root[data-ui-theme="light"] { color-scheme: light; }
:root[data-ui-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--ui-font);
  background: var(--ui-bg);
  color: var(--ui-text);
  font-size: 1rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img, video, canvas, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; min-width: 0; max-width: 100%; }
a { color: var(--ui-primary); }
h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.2; font-weight: 500; }
p { margin: 0 0 12px; }
strong, b { font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--ui-muted); }
.small { font-size: .85em; }
.mono { font-family: var(--ui-mono); }
.row, .row-between { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.row-between { justify-content: space-between; }
.row > *, .row-between > *, .col > * { min-width: 0; }
.col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: .75rem; }
.center { display: grid; place-items: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px; border-radius: var(--ui-radius); border: 1px solid var(--ui-border);
  background: var(--ui-panel-2); color: var(--ui-text); cursor: pointer; font-weight: 500;
  text-decoration: none; text-align: center; white-space: normal; max-width: 100%;
  transition: background-color .15s var(--ui-ease), border-color .15s var(--ui-ease), opacity .15s var(--ui-ease);
  min-height: 40px;
}
.btn:hover { background: color-mix(in srgb, var(--ui-panel-2) 80%, var(--ui-text) 8%); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn[aria-busy="true"] { position: relative; color: transparent !important; }
.btn[aria-busy="true"]::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--ui-text); border-top-color: transparent; animation: spin .7s linear infinite;
}
.btn-primary[aria-busy="true"]::after { border-color: var(--ui-primary-text); border-top-color: transparent; }
.btn-primary { background: var(--ui-primary); border-color: var(--ui-primary); color: var(--ui-primary-text); }
.btn-primary:hover { background: color-mix(in srgb, var(--ui-primary) 88%, var(--ui-primary-text)); }
.btn-danger, .btn-success { background: transparent; }
.btn-danger { border-color: var(--ui-danger); color: var(--ui-danger); }
.btn-success { border-color: var(--ui-success); color: var(--ui-success); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: color-mix(in srgb, var(--ui-text) 8%, transparent); }
.btn-sm { padding: 4px 8px; min-height: 32px; font-size: .875rem; }
.btn-lg { padding: 12px 20px; min-height: 48px; font-size: 1rem; }
.btn-icon { padding: 4px; min-width: 36px; min-height: 36px; flex: none; }
.btn-block { width: 100%; }
@media (pointer: coarse) { .btn:not(.btn-lg) { min-height: 44px; } }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > label, .field > .label { font-size: .875rem; color: var(--ui-secondary); font-weight: 500; }
.field .hint { font-size: .875rem; color: var(--ui-muted); }
.error-text { font-size: .875rem; color: var(--ui-danger); }
.error-text:empty { display: none; }
.input, select.input, textarea.input {
  width: 100%; padding: 8px 12px; border-radius: var(--ui-radius);
  border: 1px solid var(--ui-border); background: var(--ui-panel-2); color: var(--ui-text);
  min-height: 44px;
}
textarea.input { resize: vertical; min-height: 80px; }
.input:focus { border-color: var(--ui-focus); outline: 1px solid var(--ui-focus); }
.input.invalid { border-color: var(--ui-danger); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; flex: none; accent-color: var(--ui-primary); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 1rem; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
input[type="color"].input { padding: 2px; min-height: 40px; width: 60px; }
input[type="range"] { accent-color: var(--ui-primary); width: 100%; }

/* Panels & tables */
.panel { background: var(--ui-panel); border: 1px solid var(--ui-border); border-radius: 16px; padding: 20px; min-width: 0; }
.panel + .panel { margin-top: 1rem; }
.panel-title { font-size: 1.125rem; font-weight: 500; margin-bottom: 12px; }
@media (max-width: 480px) { .panel { padding: 12px; } }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--ui-border); vertical-align: middle; }
.table th { font-size: .875rem; color: var(--ui-secondary); font-weight: 500; }
.table tr:hover td { background: color-mix(in srgb, var(--ui-text) 3%, transparent); }
.table-wrap { min-width: 0; max-width: 100%; overflow-x: auto; }
.table .btn { margin-block: 2px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .8125rem; font-weight: 500; background: var(--ui-panel-2); border: 1px solid var(--ui-border); }
.badge-primary { background: color-mix(in srgb, var(--ui-primary) 20%, transparent); border-color: var(--ui-primary); }
.badge-success { background: color-mix(in srgb, var(--ui-success) 20%, transparent); border-color: var(--ui-success); }
.badge-danger { background: color-mix(in srgb, var(--ui-danger) 20%, transparent); border-color: var(--ui-danger); }
.badge-warning { background: color-mix(in srgb, var(--ui-warning) 20%, transparent); border-color: var(--ui-warning); }
.empty { padding: 2rem; text-align: center; color: var(--ui-muted); }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--ui-border); margin-bottom: 16px; }
.tabs button { background: none; border: none; padding: 8px 12px; min-height: 40px; cursor: pointer; color: var(--ui-muted); font-weight: 500; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--ui-text); border-bottom-color: var(--ui-primary); }
/* Phones: one swipeable row of tabs instead of a wrapped stack */
@media (max-width: 720px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; scroll-snap-type: x proximity; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; white-space: nowrap; scroll-snap-align: start; }
}

/* Progress */
.progress { height: 8px; border-radius: 999px; background: var(--ui-panel-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--ui-primary); }

/* Language switch */
.lang-switch { display: inline-flex; border: 1px solid var(--ui-border); border-radius: 8px; padding: 2px; }
.lang-switch button { background: transparent; border: none; border-radius: 4px; padding: 4px 8px; min-height: 32px; cursor: pointer; font-size: .8125rem; font-weight: 500; color: var(--ui-secondary); }
.lang-switch button.active { background: var(--ui-panel-2); color: var(--ui-text); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .55); display: grid; place-items: center; z-index: 1000; padding: 1rem; animation: fade-in .15s; }
.modal-backdrop.closing { animation: fade-out .12s forwards; pointer-events: none; }
.modal { background: var(--ui-panel); border: 1px solid var(--ui-border); border-radius: 16px; width: min(520px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: var(--ui-shadow); overflow-y: auto; animation: modal-in .18s var(--ui-ease); }
.modal-open body { overflow: hidden; }
@media (max-width: 560px) {
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal { width: 100%; border-radius: 16px 16px 0 0; max-height: 92dvh; animation: sheet-in .22s var(--ui-ease); padding-bottom: env(safe-area-inset-bottom); }
  .modal-actions .btn { flex: 1 1 auto; }
}
.modal-wide { width: min(900px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--ui-border); }
.modal-head h3 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 16px; min-height: 80px; overflow: auto; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--ui-border); }

.room-links { display: grid; grid-template-columns: minmax(0, 160px) minmax(0, 1fr); gap: 16px; align-items: start; }
.room-links .qr { background: #fff; border-radius: 8px; padding: 8px; }
.room-links .qr svg { width: 100%; height: auto; }
.room-link-row { display: flex; align-items: center; gap: 8px; }
.room-link-row .input { flex: 1; font-family: var(--ui-mono); font-size: 1rem; }
.room-code { font-family: var(--ui-mono); font-weight: 500; }
@media (max-width: 560px) {
  .room-links { grid-template-columns: minmax(0, 1fr); }
  .room-links .qr { width: min(144px, 100%); }
}

/* Toast */
.toast-host { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 2000; width: min(420px, calc(100% - 2rem)); pointer-events: none; }
.toast-host-alert { bottom: auto; top: 1rem; }
.toast { display: flex; align-items: center; gap: 12px; background: var(--ui-panel); color: var(--ui-text); border: 1px solid var(--ui-border); border-left: 4px solid var(--ui-primary); padding: 12px 16px; border-radius: 8px; box-shadow: var(--ui-shadow); opacity: 0; transform: translateY(4px); transition: opacity .15s var(--ui-ease), transform .15s var(--ui-ease); pointer-events: auto; cursor: pointer; }
.toast.show { opacity: 1; transform: none; }
.toast-msg { flex: 1; min-width: 0; }
.toast-action { flex: none; background: none; border: 1px solid var(--ui-border); border-radius: 6px; padding: 4px 10px; min-height: 32px; font-weight: 600; color: var(--ui-primary); cursor: pointer; }
.toast-action:hover { background: color-mix(in srgb, var(--ui-primary) 12%, transparent); }
.toast-success { border-left-color: var(--ui-success); }
.toast-error { border-left-color: var(--ui-danger); }
.toast-warning { border-left-color: var(--ui-warning); }

/* Misc */
.spinner { width: 28px; height: 28px; border: 3px solid var(--ui-border); border-top-color: var(--ui-primary); border-radius: 50%; animation: spin .8s linear infinite; }
.loading-screen { min-height: 60vh; display: grid; place-items: center; }
.conn-badge { position: fixed; top: 8px; right: 8px; z-index: 900; padding: 4px 8px; border-radius: 6px; font-size: .8125rem; font-weight: 500; color: var(--ui-warning); background: var(--ui-panel); border: 1px solid var(--ui-border); }
.icon { display: inline-block; flex: none; width: 18px; height: 18px; vertical-align: middle; }
kbd { font-family: var(--ui-mono); font-size: .8em; padding: .1em .35em; border: 1px solid var(--ui-border); border-radius: 4px; background: var(--ui-panel-2); }

.conn-badge::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: currentColor; animation: blink 1s infinite; }
.kbd-hint { font-size: .8125rem; color: var(--ui-muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
