/* ==========================================================================
   CodeGate design system
   Tokens, base elements and components shared by the customer page, login,
   installer and admin panel. No external fonts or CDNs are used.
   ========================================================================== */

:root {
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --sunken: #eceff3;
  --line: #e1e6eb;
  --line-strong: #c9d1d9;
  --text: #17202a;
  --text-2: #4a5867;
  --text-3: #6f7d8b;

  --accent: #0d6f66;
  --accent-hover: #0a5b53;
  --accent-soft: #dff1ee;
  --accent-text: #0a5b53;
  --on-accent: #ffffff;

  --ok: #157a3d;
  --ok-soft: #e0f3e7;
  --warn: #a45306;
  --warn-soft: #fcefd6;
  --danger: #bf352b;
  --danger-soft: #fbe5e2;
  --info: #2a5db0;
  --info-soft: #e3ecfa;

  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 14px;
  --r-xl: 20px;

  --shadow-sm: 0 1px 2px rgb(23 32 42 / 0.06);
  --shadow-md: 0 1px 2px rgb(23 32 42 / 0.05), 0 10px 28px -10px rgb(23 32 42 / 0.14);
  --shadow-lg: 0 30px 70px -24px rgb(23 32 42 / 0.4);
  --focus: 0 0 0 3px rgb(13 111 102 / 0.28);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1418;
  --surface: #141c22;
  --surface-2: #182229;
  --sunken: #0f171c;
  --line: #233039;
  --line-strong: #34444f;
  --text: #e7edf2;
  --text-2: #aab7c2;
  --text-3: #7f8d99;

  --accent: #3cc4ad;
  --accent-hover: #62d7c3;
  --accent-soft: #123330;
  --accent-text: #83e2d2;
  --on-accent: #052620;

  --ok: #56cf83;
  --ok-soft: #12301f;
  --warn: #f0b04f;
  --warn-soft: #3a2a10;
  --danger: #f27b6f;
  --danger-soft: #3d1a17;
  --info: #7fadf2;
  --info-soft: #14284a;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 1px 2px rgb(0 0 0 / 0.35), 0 12px 30px -12px rgb(0 0 0 / 0.6);
  --shadow-lg: 0 30px 70px -24px rgb(0 0 0 / 0.8);
  --focus: 0 0 0 3px rgb(60 196 173 / 0.35);

  color-scheme: dark;
}

/* --- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
/* Reserve the scrollbar's space on every page, so content does not shift sideways when a page is long enough to need one. */
html { scrollbar-gutter: stable; }
html.no-transition *, html.no-transition *::before, html.no-transition *::after { transition: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14.5px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.012em; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent-text); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
code, kbd, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
code { font-size: 0.9em; background: var(--sunken); padding: 1px 6px; border-radius: var(--r-sm); }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

.icon { flex: none; vertical-align: -0.2em; }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 200; background: var(--accent); color: var(--on-accent); padding: 8px 14px; border-radius: var(--r-md); text-decoration: none; }
.skip-link:focus { top: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

/* --- Brand ----------------------------------------------------------------- */

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 650; letter-spacing: -0.01em; }
.brand:hover { color: var(--text); }
.brand-logo { border-radius: 8px; object-fit: cover; }
.bm-bg { fill: var(--accent); }
.bm-ring { stroke: rgb(255 255 255 / 0.35); }
.bm-arc { stroke: #fff; }
.bm-dot { fill: #fff; }
:root[data-theme="dark"] .bm-bg { fill: var(--accent); }
:root[data-theme="dark"] .bm-ring { stroke: rgb(5 38 32 / 0.35); }
:root[data-theme="dark"] .bm-arc, :root[data-theme="dark"] .bm-dot { stroke: #052620; }
:root[data-theme="dark"] .bm-dot { fill: #052620; }

/* --- Buttons ---------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--r-md);
  font-weight: 560; font-size: 14px; line-height: 1; white-space: nowrap;
  text-decoration: none; cursor: pointer; user-select: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--focus); }
.btn[disabled], .btn.is-disabled { opacity: 0.55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--sunken); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); color: #fff; }
.btn-danger-quiet { background: transparent; color: var(--danger); }
.btn-danger-quiet:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; border-radius: 11px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); }
.btn-icon:hover { background: var(--sunken); color: var(--text); }
.btn-icon.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
form.inline { display: inline; margin: 0; }

/* --- Forms -------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .optional { font-weight: 400; color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { height: auto; padding: 10px 12px; min-height: 90px; resize: vertical; }
.select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236f7d8b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input.is-invalid, .select.is-invalid { border-color: var(--danger); }
.input-sm { height: 34px; font-size: 13.5px; }
.hint { font-size: 12.5px; color: var(--text-3); }
.error-text { font-size: 12.5px; color: var(--danger); font-weight: 500; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid .span-2 { grid-column: 1 / -1; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check small { display: block; color: var(--text-3); font-size: 12.5px; }
.input-with-action { position: relative; }
.input-with-action .input { padding-right: 44px; }
.input-with-action .btn-icon { position: absolute; right: 3px; top: 3px; }
input[type="file"].input { padding: 7px 10px; height: auto; }

/* --- Cards, badges, alerts ------------------------------------------------------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-title { font-size: 15px; }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-muted { background: var(--sunken); color: var(--text-2); }
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.alert { display: flex; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); border: 1px solid transparent; font-size: 13.5px; }
.alert .icon { margin-top: 2px; }
.alert strong { font-weight: 650; }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert a { color: inherit; font-weight: 600; }

.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); font-weight: 700; font-size: 14px; flex: none; }
.avatar-sm { width: 28px; height: 28px; border-radius: 8px; font-size: 12.5px; }

.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 6px; }

.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.7s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Tables -------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--text-3); padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.table .cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.table .cell-main strong { display: block; font-weight: 600; }
.table .cell-main span.sub { display: block; font-size: 12.5px; color: var(--text-3); }
.table .actions { display: flex; gap: 2px; justify-content: flex-end; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.is-highlight td { background: var(--accent-soft); }

/* --- Modals ------------------------------------------------------------------------------ */

dialog.modal {
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
}
dialog.modal::backdrop { background: rgb(9 16 22 / 0.55); backdrop-filter: blur(3px); }
dialog.modal[open] { animation: modal-in 0.18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 0; }
.modal-head h2 { font-size: 17px; }
.modal-head p { color: var(--text-3); font-size: 13.5px; margin-top: 4px; }
.modal-body { padding: 18px 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; flex-wrap: wrap; }
.modal-lg { width: min(640px, calc(100vw - 32px)); }

/* --- Toasts ---------------------------------------------------------------------------------- */

.toasts { position: fixed; z-index: 300; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-left-width: 4px;
  box-shadow: var(--shadow-md); font-size: 13.5px; animation: toast-in 0.22s ease-out;
}
.toast.is-leaving { opacity: 0; transform: translateX(12px); transition: opacity 0.2s, transform 0.2s; }
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warn); }
.toast-info { border-left-color: var(--info); }
.toast .icon { margin-top: 2px; }
.toast-success .icon { color: var(--ok); }
.toast-error .icon { color: var(--danger); }
.toast-warning .icon { color: var(--warn); }
.toast-info .icon { color: var(--info); }
.toast button { margin-left: auto; background: none; border: 0; color: var(--text-3); padding: 0 2px; line-height: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* --- Pagination, tabs, menus -------------------------------------------------------------------- */

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); font-size: 13px; color: var(--text-3); }
.pagination-links { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.page-link { min-width: 34px; height: 34px; padding: 0 10px; display: inline-grid; place-items: center; border-radius: var(--r-sm); border: 1px solid transparent; color: var(--text-2); text-decoration: none; font-weight: 550; }
a.page-link:hover { background: var(--sunken); color: var(--text); }
.page-link.is-current { background: var(--accent); color: var(--on-accent); }
.page-link.is-disabled { opacity: 0.4; }
.page-gap { color: var(--text-3); padding: 0 4px; }

.tabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--sunken); border-radius: var(--r-md); flex-wrap: wrap; }
.tab { padding: 6px 13px; border-radius: 7px; color: var(--text-2); text-decoration: none; font-weight: 560; font-size: 13.5px; }
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 8px); z-index: 60; min-width: 220px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-md); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; text-align: left; color: var(--text); text-decoration: none; border-radius: var(--r-sm); font-size: 13.5px; }
.menu-item:hover { background: var(--sunken); color: var(--text); }
.menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-head strong { display: block; }
.menu-head span { font-size: 12.5px; color: var(--text-3); }

/* Theme switch: a pill track with a sliding thumb. The thumb position follows data-theme-choice (set by theme.js). */
.theme-switch {
  --step: 34px; --i: 2;
  position: relative; display: inline-flex; gap: 2px; padding: 3px;
  background: var(--sunken); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 0.08);
}
:root[data-theme-choice="light"] .theme-switch { --i: 0; }
:root[data-theme-choice="dark"] .theme-switch { --i: 1; }
:root[data-theme-choice="system"] .theme-switch { --i: 2; }
.theme-switch::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow-sm);
  transform: translateX(calc(var(--i) * var(--step)));
  transition: transform 0.3s cubic-bezier(0.3, 1.25, 0.5, 1);
}
.theme-switch button { position: relative; z-index: 1; width: 32px; height: 32px; display: grid; place-items: center; border: 0; background: transparent; color: var(--text-3); border-radius: 50%; transition: color 0.2s; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button .icon { transition: transform 0.3s ease; }
.theme-switch button[aria-pressed="true"] .icon { transform: scale(1.1) rotate(-12deg); }
.theme-switch button[data-theme-set="light"][aria-pressed="true"] { color: var(--warn); }
.theme-switch button[data-theme-set="dark"][aria-pressed="true"] { color: var(--accent-text); }
.theme-switch button[data-theme-set="system"][aria-pressed="true"] { color: var(--text); }
@media (prefers-reduced-motion: reduce) { .theme-switch::before, .theme-switch button .icon { transition: none; } }

/* --- Error page ---------------------------------------------------------------------------------- */

.error-body { display: grid; place-items: center; padding: 24px; }
.error-page { max-width: 440px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.error-code { font: 700 56px/1 var(--font-mono); color: var(--accent); letter-spacing: -0.04em; }
.error-page h1 { font-size: 22px; }
.error-page p { color: var(--text-2); }

@media (max-width: 640px) {
  .field-grid, .field-grid.cols-3 { grid-template-columns: 1fr; }
  .modal-head, .modal-body { padding-left: 18px; padding-right: 18px; }
  .modal-foot { padding: 0 18px 18px; }
  .modal-foot .btn { flex: 1 1 auto; }
  .toasts { right: 12px; left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
