/* Fibr design tokens + shared components.
 * Served at /shared/tokens.css for the admin panel, the web cabinet and the
 * Telegram Mini App. Geometry and accents follow docs/DESIGN.md (green
 * primary, blue secondary, Inter); the dark surface ladder is stepped so
 * that every layer — canvas → card → field → hairline — is actually
 * distinguishable (cards and borders used to be the same grey). */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --primary: #00b24b;
  --primary-strong: #19c964;
  --on-primary: #ffffff;
  --secondary: #0075ff;
  --secondary-strong: #4b9dff;
  --canvas: #0e0f11;          /* page */
  --surface: #191b1f;         /* cards */
  --surface-2: #22252a;       /* nested blocks, tertiary buttons, pills */
  --surface-3: #2b2f35;       /* hover */
  --field: #121417;           /* inputs sit *into* the card */
  --hairline: #2a2d33;        /* dividers inside cards */
  --border: #33373e;          /* field / button outlines */
  --ink: #f0f2f5;
  --muted: #9aa1b1;
  --faint: #626873;
  --danger: #ff5a5f;
  --warn: #f5a623;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-float: 0 16px 48px rgba(0, 0, 0, 0.55);
  --focus: 0 0 0 3px color-mix(in srgb, var(--secondary) 40%, transparent);
}

:root[data-theme="light"] {
  color-scheme: light;
  --primary: #00a044;
  --primary-strong: #008c3b;
  --on-primary: #ffffff;
  --secondary: #0070f3;
  --secondary-strong: #0062d6;
  --canvas: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f1f2f4;
  --surface-3: #e7e9ec;
  --field: #ffffff;
  --hairline: #eceef1;
  --border: #dadde3;
  --ink: #16181c;
  --muted: #5d6470;
  --faint: #9aa1b1;
  --danger: #dc2f35;
  --warn: #b26b00;
  --shadow-card: 0 1px 2px rgba(16, 18, 22, 0.06), 0 1px 1px rgba(16, 18, 22, 0.03);
  --shadow-float: 0 16px 48px rgba(16, 18, 22, 0.18);
  --focus: 0 0 0 3px color-mix(in srgb, var(--secondary) 28%, transparent);
}

:root {
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-full: 999px;
  --h-ctl: 40px;      /* inputs, buttons */
  --h-ctl-sm: 32px;   /* small buttons */
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ---------- base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01", "tnum";
}

h1,
h2,
h3 {
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
}

p {
  margin: 0;
}

b,
strong {
  font-weight: 700;
}

a {
  color: var(--secondary-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img,
svg {
  display: inline-block;
  vertical-align: middle;
}

/* ---------- card ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.card > h3:first-child,
.card-title {
  margin-bottom: 12px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--h-ctl);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--primary);
  color: var(--on-primary);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, filter 0.15s ease, transform 0.05s ease;
}

.btn:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn--secondary {
  background: var(--secondary);
}

.btn--tertiary {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--border);
}

.btn--tertiary:hover {
  background: var(--surface-3);
  filter: none;
}

.btn--ghost {
  background: transparent;
  color: var(--secondary-strong);
}

.btn--ghost:hover {
  background: color-mix(in srgb, var(--secondary) 12%, transparent);
  filter: none;
}

.btn--danger {
  background: var(--danger);
}

/* Destructive but secondary: red text on a quiet surface. */
.btn--danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn--danger-ghost:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  filter: none;
}

.btn--small {
  min-height: var(--h-ctl-sm);
  padding: 0 12px;
  font-size: 13px;
  border-radius: var(--r-sm);
}

.btn--icon {
  width: var(--h-ctl-sm);
  min-height: var(--h-ctl-sm);
  padding: 0;
}

.btn--block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

/* ---------- inputs ---------- */

.input {
  width: 100%;
  min-height: var(--h-ctl);
  padding: 0 12px;
  background: var(--field);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font: inherit;
  font-weight: 500;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea.input {
  padding: 10px 12px;
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

.input::placeholder {
  color: var(--faint);
}

.input:hover {
  border-color: color-mix(in srgb, var(--border) 60%, var(--muted));
}

.input:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: var(--focus);
}

select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  cursor: pointer;
  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='%239aa1b1' stroke-width='2.5' 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[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  margin: 0;
  flex: none;
}

/* Field label (above an input). */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field + .field {
  margin-top: 12px;
}

.field > span,
.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- pills ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
  background: var(--surface-2);
  color: var(--muted);
}

.pill--ok {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  color: var(--primary-strong);
}

.pill--live {
  background: color-mix(in srgb, var(--secondary) 16%, transparent);
  color: var(--secondary-strong);
}

.pill--off {
  background: var(--surface-2);
  color: var(--muted);
}

.pill--danger {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.pill--warn {
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  color: var(--warn);
}

button.pill {
  border: 0;
  font-family: inherit;
  cursor: pointer;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  display: inline-block;
  flex: none;
}

.dot--on {
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}

.dot--off {
  background: var(--faint);
}

/* ---------- table ---------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}

.table tbody tr {
  transition: background-color 0.12s ease;
}

.table tbody tr:hover {
  background: color-mix(in srgb, var(--surface-2) 55%, transparent);
}

.table tr:last-child td {
  border-bottom: 0;
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fibr-fade 0.15s ease;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  padding: 22px;
  width: min(100%, 460px);
  max-height: calc(100vh - 32px);
  overflow: auto;
  box-shadow: var(--shadow-float);
  animation: fibr-pop 0.18s ease;
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal .modal-sub {
  margin: 0 0 14px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* Phones: modals become bottom sheets with full-width actions. */
@media (max-width: 560px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-height: 92vh;
    border-radius: 22px 22px 0 0;
    padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
    animation: fibr-sheet 0.22s ease;
  }

  .modal::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: var(--border);
    margin: -8px auto 14px;
  }

  .modal-actions .btn {
    flex: 1 1 0;
    min-height: var(--h-ctl);
  }
}

@keyframes fibr-fade { from { opacity: 0; } }
@keyframes fibr-pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes fibr-sheet { from { transform: translateY(40px); opacity: 0.4; } }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 16px;
  box-shadow: var(--shadow-float);
  z-index: 200;
  max-width: min(90vw, 420px);
  font-weight: 600;
  height: auto;
  white-space: normal;
  animation: fibr-fade 0.15s ease;
}

.toast.pill--danger {
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

/* ---------- code blocks ---------- */

.config-pre {
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin: 12px 0;
  max-height: 40vh;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 14px;
  background: #fff;
  border-radius: var(--r-lg);
  margin: 4px auto 0;
  width: fit-content;
}

.qr-wrap img {
  width: min(260px, 66vw);
  height: min(260px, 66vw);
  display: block;
  image-rendering: pixelated;
}

/* ---------- theme toggle icon ---------- */

.theme-ico {
  width: 16px;
  height: 16px;
}

:root[data-theme="dark"] .theme-ico .sun,
:root[data-theme="light"] .theme-ico .moon {
  display: none;
}

/* ---------- utilities ---------- */

.muted {
  color: var(--muted);
}

.faint {
  color: var(--faint);
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
}

.grow {
  flex: 1;
  min-width: 0;
}

.hidden {
  display: none !important;
}

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