/* ==========================================================================
   DexterOS — base design system (tokens, reset, controls, overlays)
   Inspired by Fluent 2 / Windows 11 25H2 materials.
   ========================================================================== */

:root {
  --accent: #2563eb;
  --accent-hover: color-mix(in srgb, var(--accent) 88%, #ffffff);
  --accent-press: color-mix(in srgb, var(--accent) 80%, #000000);
  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --accent-text: #ffffff;

  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 18px;

  --bg: #f3f3f3;
  --bg-elevated: #ffffff;
  --bg-subtle: #fafafa;
  --layer: rgba(255, 255, 255, 0.72);
  --layer-strong: rgba(252, 252, 252, 0.92);
  --text: #1b1b1b;
  --text-secondary: #5c5c5c;
  --text-tertiary: #767676;
  --stroke: rgba(0, 0, 0, 0.08);
  --stroke-strong: rgba(0, 0, 0, 0.16);
  --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.05), 0 12px 32px rgba(0, 0, 0, 0.07);
  --flyout-shadow: 0 8px 16px rgba(0, 0, 0, 0.10), 0 24px 60px rgba(0, 0, 0, 0.24);
  --success: #0f7b3f;
  --warning: #9d5d00;
  --danger: #c42b1c;
  --info: #005fb8;
}

[data-theme="dark"] {
  --bg: #141414;
  --bg-elevated: #1f1f1f;
  --bg-subtle: #191919;
  --layer: rgba(44, 44, 44, 0.72);
  --layer-strong: rgba(32, 32, 32, 0.9);
  --text: #ffffff;
  --text-secondary: #c8c8c8;
  --text-tertiary: #9a9a9a;
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.18);
  --card-shadow: 0 2px 4px rgba(0, 0, 0, 0.25), 0 14px 36px rgba(0, 0, 0, 0.4);
  --flyout-shadow: 0 10px 22px rgba(0, 0, 0, 0.4), 0 30px 70px rgba(0, 0, 0, 0.55);
  --success: #6ccb7d;
  --warning: #f0b354;
  --danger: #ff8d84;
  --info: #6cb8ff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--text) 22%, transparent); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--text) 38%, transparent); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ layout */
.wrap { width: min(1200px, 100% - 48px); margin-inline: auto; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.muted { color: var(--text-secondary); }
.tiny { font-size: 12px; }
.small { font-size: 13px; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hiddenish { display: none !important; }
.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;
}


/* ------------------------------------------------------------------ brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none !important; letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  --brand-1: var(--accent); --brand-2: color-mix(in srgb, var(--accent) 60%, #7c3aed);
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: 0 0 auto;
  background: linear-gradient(145deg, var(--brand-1), var(--brand-2));
  color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--brand-1) 35%, transparent);
}
.brand small { display: block; font-size: 10px; font-weight: 600; letter-spacing: .16em; color: var(--text-tertiary); text-transform: uppercase; line-height: 1; }

/* ------------------------------------------------------------------ surfaces */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
}
.mica {
  background: var(--layer);
  backdrop-filter: blur(30px) saturate(140%);
  -webkit-backdrop-filter: blur(30px) saturate(140%);
  border: 1px solid var(--stroke);
}

/* ------------------------------------------------------------------ buttons */
.btn {
  --btn-bg: var(--bg-elevated);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 34px; padding: 6px 16px;
  background: var(--btn-bg);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius);
  font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, transform .08s ease, box-shadow .12s ease;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .04);
  user-select: none;
}
.btn:hover { background: color-mix(in srgb, var(--btn-bg) 92%, var(--text) 8%); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  --btn-bg: var(--accent);
  color: var(--accent-text);
  border-color: color-mix(in srgb, var(--accent) 70%, #000);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .18);
}
.btn-primary:hover { --btn-bg: var(--accent-hover); }
.btn-primary:active { --btn-bg: var(--accent-press); }
.btn-subtle { background: transparent; border-color: transparent; box-shadow: none; }
.btn-subtle:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.btn-danger { --btn-bg: var(--danger); color: #fff; border-color: color-mix(in srgb, var(--danger) 70%, #000); }
.btn-danger:hover { --btn-bg: color-mix(in srgb, var(--danger) 88%, #fff); }
.btn-sm { min-height: 28px; padding: 3px 10px; font-size: 13px; }
.btn-lg { min-height: 42px; padding: 10px 22px; font-size: 15px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }

/* ------------------------------------------------------------------ forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field .hint { font-size: 12px; color: var(--text-tertiary); }
.input, .select, .textarea {
  width: 100%; min-height: 34px; padding: 6px 11px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, var(--bg));
  border: 1px solid var(--stroke-strong);
  border-bottom: 1px solid color-mix(in srgb, var(--text) 40%, transparent);
  border-radius: var(--radius); transition: border-color .12s ease, background .12s ease;
}
[data-theme="dark"] .input, [data-theme="dark"] .select, [data-theme="dark"] .textarea {
  background: rgba(255, 255, 255, .06);
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 -1px 0 var(--accent); }
.textarea { min-height: 76px; resize: vertical; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 18px) 15px, calc(100% - 13px) 15px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0 0 12px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 16px; height: 16px; }
input[type="color"] { width: 42px; height: 34px; padding: 2px; border-radius: var(--radius); border: 1px solid var(--stroke-strong); background: transparent; cursor: pointer; }

/* Fluent-style switch */
.switch { position: relative; display: inline-flex; align-items: center; width: 40px; height: 20px; flex: 0 0 auto; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0; border-radius: 10px; border: 1px solid var(--stroke-strong);
  background: color-mix(in srgb, var(--text) 12%, transparent); transition: background .15s ease, border-color .15s ease;
}
.switch .thumb {
  position: absolute; top: 50%; left: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-secondary); transform: translateY(-50%); transition: left .15s ease, background .15s ease, width .15s ease, height .15s ease;
}
.switch input:checked ~ .track { background: var(--accent); border-color: color-mix(in srgb, var(--accent) 70%, #000); }
.switch input:checked ~ .thumb { left: 22px; background: #fff; }
.switch input:disabled ~ .track { opacity: .5; }


/* ------------------------------------------------------------------ shared console components */
/* (used by the desktop Settings app and by the admin console modals) */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.wp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.wp-card { border: 1px solid var(--stroke-strong); border-radius: var(--radius-lg); overflow: hidden; cursor: pointer; background: var(--bg-elevated); transition: transform .14s ease, border-color .14s ease; }
.wp-card:hover { transform: translateY(-2px); }
.wp-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.wp-thumb { height: 108px; background-size: cover; background-position: center; }
.wp-meta { padding: 10px 12px; }
.wp-meta b { display: block; font-size: 13px; }
.wp-meta span { font-size: 11.5px; color: var(--text-tertiary); }
.wp-card.current .wp-meta b::after { content: " ✓"; color: var(--accent); }


.swatch-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 2px solid transparent; cursor: pointer; }
.swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-elevated) inset; }


.danger-zone { border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); }


/* ------------------------------------------------------------------ badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--stroke-strong); background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--text-secondary); white-space: nowrap;
}
.badge-good { color: var(--success); border-color: color-mix(in srgb, var(--success) 45%, transparent); background: color-mix(in srgb, var(--success) 14%, transparent); }
.badge-bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.badge-warn { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 45%, transparent); background: color-mix(in srgb, var(--warning) 16%, transparent); }
.badge-accent { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }

/* ------------------------------------------------------------------ tables */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-tertiary); padding: 10px 12px; border-bottom: 1px solid var(--stroke);
}
.table td { padding: 12px; border-bottom: 1px solid var(--stroke); vertical-align: middle; }
.table tbody tr:hover { background: color-mix(in srgb, var(--text) 4%, transparent); }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ------------------------------------------------------------------ avatars & icon tiles */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; overflow: hidden;
  background-size: cover; background-position: center; user-select: none;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }
.avatar.xl { width: 104px; height: 104px; font-size: 40px; }

.appicon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 9px; flex: 0 0 auto; overflow: hidden;
  background: #2b3242; color: #fff; font-size: 21px; line-height: 1;
}
.appicon img { width: 100%; height: 100%; object-fit: cover; }
.appicon.letter { font-weight: 700; font-size: 17px; }

/* ------------------------------------------------------------------ toast */
#toast-host {
  position: fixed; right: 18px; bottom: 18px; z-index: 9000;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast {
  min-width: 260px; max-width: 380px; padding: 12px 14px;
  background: var(--layer-strong); backdrop-filter: blur(24px) saturate(140%);
  border: 1px solid var(--stroke); border-left: 3px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--flyout-shadow); color: var(--text);
  animation: toast-in .18s ease both; pointer-events: auto;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast strong { display: block; font-size: 13px; margin-bottom: 2px; }
.toast span { font-size: 13px; color: var(--text-secondary); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 8000; display: grid; place-items: center;
  background: rgba(0, 0, 0, .45); backdrop-filter: blur(4px); padding: 20px;
  animation: fade-in .14s ease both; overflow: auto;
}
/* Flex column: header and footer stay put while the body scrolls, so the primary
   action is always reachable even on short screens. */
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--bg-elevated); border: 1px solid var(--stroke);
  border-radius: var(--radius-lg); box-shadow: var(--flyout-shadow);
  animation: modal-in .18s cubic-bezier(.2, .9, .3, 1) both;
}
.modal.wide { width: min(880px, 100%); }
.modal > header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 8px; }
.modal > header h3 { margin: 0; font-size: 18px; }
.modal .modal-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px 22px 4px; }
.modal > footer {
  flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 18px;
  border-top: 1px solid var(--stroke); background: color-mix(in srgb, var(--bg-elevated) 92%, var(--text) 3%);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent); border-top-color: currentColor;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, color-mix(in srgb, var(--text) 6%, transparent), color-mix(in srgb, var(--text) 12%, transparent), color-mix(in srgb, var(--text) 6%, transparent));
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border-radius: var(--radius);
}
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state {
  padding: 44px 24px; text-align: center; color: var(--text-secondary);
  border: 1px dashed var(--stroke-strong); border-radius: var(--radius-lg);
}
.empty-state .big { font-size: 34px; display: block; margin-bottom: 10px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
