/* OlConnect Manager — strict black & white design system.
 *
 * One theme, no toggle. The panel had a lavender accent plus a light/dark
 * switch, which meant every visual decision had to work twice and the accent
 * competed with the status colours. Monochrome removes both problems: the
 * accent is gone, and meaning is carried by luminance (how bright a thing is)
 * and by shape, never by hue alone. Status stays readable for colour-blind
 * users because success/error also differ in weight and border, not just tone.
 */

/* ── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  /* Monochrome accent: the single "this is interactive" tone. */
  --color-primary: #ffffff;
  --color-primary-hover: #e6e6e6;
  --color-primary-focus: #cccccc;

  /* Accent fills are inversions, not tints. */
  --color-accent: #ffffff;
  --color-accent-ink: #0a0a0a;
  --color-accent-subtle: rgba(255, 255, 255, 0.07);
  --color-accent-border: rgba(255, 255, 255, 0.22);

  /* Legacy names kept so markup that still references them keeps rendering. */
  --color-lavender-subtle: var(--color-accent-subtle);
  --color-lavender-border: var(--color-accent-border);

  /* Text ramp. The previous values were calibrated for a purple-tinted canvas
   * and read as "smudged into the background" on pure black: #8e8e8e is only
   * 3.6:1 against #050505, well under the 4.5:1 body-text floor.
   *
   * These are set by contrast ratio against --color-canvas, not by taste:
   *   ink       21:1  headings and primary values
   *   ink-muted 12:1  body text and secondary values
   *   ink-subtle 8:1  captions, ids, metadata
   *   ink-tertiary 5:1  only for disabled or decorative text
   * Anything that carries meaning stays at 8:1 or better. */
  --color-ink: #ffffff;
  --color-ink-muted: #dcdcdc;
  --color-ink-subtle: #a8a8a8;
  --color-ink-tertiary: #808080;

  --color-canvas: #050505;
  --color-surface-1: #0e0e0e;
  --color-surface-2: #151515;
  --color-surface-3: #1d1d1d;

  --color-hairline: #232323;
  --color-hairline-strong: #383838;
  --color-hairline-tertiary: #4d4d4d;

  /* Status: brightness carries the signal, hue is not used at all. Success is
   * the brightest ink, failure a mid grey — a difference that survives both a
   * monochrome palette and colour blindness. */
  --color-success: #ffffff;
  --color-success-strong: #ffffff;
  --color-error: #7a7a7a;
  --color-error-strong: #ffffff;

  /* Group colours: eight steps of grey, ordered light to dark. Groups are told
   * apart by position in the scale, so the palette stays monochrome. */
  --group-1: #f5f5f5;
  --group-2: #d4d4d4;
  --group-3: #b3b3b3;
  --group-4: #929292;
  --group-5: #717171;
  --group-6: #555555;
  --group-7: #3d3d3d;
  --group-8: #292929;

  --rounded-xs: 4px;
  --rounded-sm: 6px;
  --rounded-md: 8px;
  --rounded-lg: 12px;
  --rounded-xl: 16px;
  --rounded-pill: 9999px;

  --spacing-xs: 8px;
  --spacing-sm: 12px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
}

/* Tailwind's greys are tuned for a mid-dark background. On near-black they
 * drop to ~3.5:1 and the labels they carry become guesswork. Route them onto
 * the contrast-checked ramp instead of editing forty call sites. */
.text-gray-300,
.text-gray-400 {
  color: var(--color-ink-muted) !important;
}

.text-gray-500 {
  color: var(--color-ink-subtle) !important;
}

body {
  color-scheme: dark;
  font-family: 'Plus Jakarta Sans', -apple-system, system-ui, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-canvas);
  color: var(--color-ink);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.01em;
  transition: background 0.2s ease, color 0.2s ease;
}

/* ── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.fade-in {
  animation: fadeIn 0.25s ease-out;
}

.slide-in {
  animation: slideIn 0.25s ease-out;
}

/* ── Cards & Layout ─────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface-1);
  border: 1px solid var(--color-hairline);
  border-radius: var(--rounded-lg);
  animation: fadeIn 0.25s ease-out;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.card-hover {
  transition: border-color .2s ease, transform .2s ease, box-shadow .2s ease;
}

.card-hover:hover {
  border-color: var(--color-hairline-strong);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.25), 0 0 0 1px var(--color-lavender-border);
}

.metric-card {
  background: var(--color-surface-1);
  border: 1px solid var(--color-hairline);
  border-radius: var(--rounded-md);
  padding: 14px;
  transition: border-color .15s ease, background .15s ease;
}

.metric-card:hover {
  border-color: var(--color-lavender-border);
}

/* Groups without a subscription (the "Без подписки" bucket) get a numbered
 * marker too, so the list reads as a continuous 01..N sequence rather than
 * "some groups have numbers and one does not". */
.instance-group-marker.is-plain {
  background: transparent;
  color: var(--color-ink-muted);
  border: 1px solid var(--color-hairline-strong);
}

.instance-group {
  border: 1px solid var(--color-hairline);
  border-radius: var(--rounded-lg);
  padding: var(--spacing-md);
  background: var(--color-surface-1);
}

/* A grouped block is identified by hue first: the rail and the wash share the
 * group colour, and the numbered badge in the header carries the same number
 * as the cards inside it. Hue answers "which group", the number answers
 * "which one is this" — the pair survives both a busy screen and a glance. */

.instance-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}


.instance-group-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  flex: 0 0 auto;
  border-radius: var(--rounded-sm);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #050505;
  background: var(--instance-group-accent, var(--color-ink));
  /* The numeral sits on a saturated plate, so it is always dark-on-light —
   * legible on every group hue without per-hue tuning. */
}

.instance-group-subscription {
  /* A 4px colour rail is the thing the eye finds first when scanning a list;
   * the wash underneath only confirms it. */
  background: var(--instance-group-bg, var(--color-surface-1));
  border-left: 4px solid var(--instance-group-accent, var(--color-hairline-tertiary));
  padding-left: calc(var(--spacing-md) - 4px);
}

/* The subscription badge in the header picks up the group hue so the header
 * and the rail agree. */
.instance-group-subscription .instance-group-header .badge {
  color: var(--instance-group-accent, var(--color-ink-muted));
  border-color: var(--instance-group-border, var(--color-hairline-strong));
}

.instance-group-subscription .instance-card {
  border-left: 1px solid var(--color-hairline);
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-ink-subtle);
  margin-bottom: 12px;
}

.section {
  border: 1px solid var(--color-hairline);
  border-radius: var(--rounded-lg);
  padding: var(--spacing-md);
  background: var(--color-surface-1);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--rounded-md);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: all .15s ease-in-out;
  min-height: 38px;
  border: 1px solid transparent;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  min-height: 32px;
  border-radius: var(--rounded-sm);
}

/* Primary is an inversion: white plate, black label. In monochrome that is
 * the strongest "act here" signal available, and it needs no accent hue. */
.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
  box-shadow: 0 2px 8px -1px rgba(255, 255, 255, 0.12);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: 0 4px 14px -1px rgba(255, 255, 255, 0.18);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-primary-focus);
}

.btn-success {
  background: #ffffff;
  color: #050505;
}

.btn-success:hover:not(:disabled) {
  background: #e6e6e6;
}

/* Destructive stays distinguishable by outline weight, not by red. */
.btn-danger {
  background: transparent;
  color: var(--color-ink);
  border: 1px solid var(--color-hairline-tertiary);
}

.btn-danger:hover:not(:disabled) {
  background: var(--color-surface-3);
  border-color: var(--color-ink-muted);
}

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-ink);
  border: 1px solid var(--color-hairline);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-surface-3);
  border-color: var(--color-hairline-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--color-ink-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-lavender-subtle);
  color: var(--color-primary);
}

.btn-icon {
  padding: 8px;
  min-height: 34px;
  min-width: 34px;
}

/* ── Status Indicators ──────────────────────────────────────────────────── */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--rounded-pill);
  display: inline-block;
}

/* Running is a bright filled dot; failed is a hollow one with a wide ring.
 * The shapes differ, so the two states are told apart without relying on
 * hue — which is exactly what a monochrome panel needs. */
.status-running {
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.22);
}

.status-failed {
  background: transparent;
  border: 1.5px solid var(--color-ink-muted);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.status-inactive {
  background: var(--color-ink-tertiary);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: var(--rounded-pill);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Running reads as a bright filled pill; failed as a dim outlined one. */
.status-pill-running {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-ink);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.status-pill-failed {
  background: transparent;
  color: var(--color-ink-subtle);
  border: 1px solid var(--color-hairline-tertiary);
}

.status-pill-inactive {
  background: var(--color-surface-2);
  color: var(--color-ink-subtle);
  border: 1px solid var(--color-hairline);
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--rounded-pill);
  font-size: 11px;
  font-weight: 500;
  background: var(--color-surface-2);
  color: var(--color-ink-muted);
  border: 1px solid var(--color-hairline);
}

/* Badges differ by fill weight and border strength, not by hue. A "strong"
 * badge is filled, a "quiet" one is an outline — that ordering survives both
 * colour blindness and a monochrome palette. */
.badge-lavender {
  background: var(--color-accent-subtle);
  color: var(--color-ink);
  border-color: var(--color-accent-border);
}

.badge-emerald {
  background: var(--color-surface-3);
  color: var(--color-ink);
  border-color: var(--color-hairline-tertiary);
}

.badge-amber {
  background: transparent;
  color: var(--color-ink-muted);
  border-color: var(--color-hairline-strong);
}

.badge-blue {
  background: var(--color-accent-subtle);
  color: var(--color-ink);
  border-color: var(--color-accent-border);
}

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 13, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  backdrop-filter: blur(8px);
}

.modal {
  background: var(--color-surface-1);
  border: 1px solid var(--color-hairline-strong);
  border-radius: var(--rounded-xl);
  max-width: 44rem;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--spacing-lg);
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-sm {
  max-width: 28rem;
}

/* ── Logs ───────────────────────────────────────────────────────────────── */
pre.logs {
  background: var(--color-canvas);
  padding: var(--spacing-md);
  border-radius: var(--rounded-md);
  border: 1px solid var(--color-hairline);
  overflow-x: auto;
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  letter-spacing: 0;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--color-ink-muted);
}

.qr-wrap {
  background: #ffffff;
  padding: 16px;
  border-radius: var(--rounded-md);
  display: inline-block;
  box-shadow: 0 0 0 4px #ffffff, 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ── Form Controls ──────────────────────────────────────────────────────── */
input, select, textarea {
  background: var(--color-surface-2);
  border: 1px solid var(--color-hairline-strong);
  color: var(--color-ink);
  padding: 9px 13px;
  border-radius: var(--rounded-md);
  width: 100%;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  transition: border-color .15s, box-shadow .15s, background .15s;
  min-height: 40px;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23948fa8' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  appearance: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input::placeholder, textarea::placeholder {
  color: var(--color-ink-tertiary);
}

input:hover, textarea:hover {
  border-color: var(--color-hairline-tertiary);
  background: var(--color-surface-3);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-surface-2);
  box-shadow: 0 0 0 3px var(--color-lavender-border);
}

input:disabled, input[readonly] {
  color: var(--color-ink-subtle);
  background: var(--color-surface-1);
  border-color: var(--color-hairline);
  opacity: 0.6;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-ink-muted);
}

.field-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.field-row > input, .field-row > select {
  flex: 1;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--rounded-sm);
  transition: background .15s;
}

.radio-row:hover {
  background: var(--color-surface-2);
}

.radio-row input[type="radio"],
.radio-row input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--color-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.slug-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.slug-row input {
  flex: 1;
  margin-bottom: 0;
}

/* ── Spinner ────────────────────────────────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--rounded-pill);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  pointer-events: none;
}

.toast {
  background: var(--color-surface-1);
  border: 1px solid var(--color-hairline);
  color: var(--color-ink);
  padding: 10px 16px;
  border-radius: var(--rounded-md);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 14rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  transition: opacity .25s, transform .25s;
}

.toast-success {
  border-color: var(--color-lavender-border);
}

.toast-success .toast-icon {
  color: var(--color-primary);
}

.toast-error {
  border-color: var(--color-hairline-tertiary);
}

.toast-error .toast-icon {
  color: var(--color-error);
}

.toast-info .toast-icon {
  color: var(--color-primary);
}

/* ── App Shell & Sidebar ────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--color-surface-1);
  border-right: 1px solid var(--color-hairline);
  padding: var(--spacing-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  box-sizing: border-box;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  padding: 4px 6px 20px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--rounded-md);
  color: var(--color-ink-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: all .15s ease-in-out;
}

.sidebar-link:hover {
  background: var(--color-surface-2);
  color: var(--color-ink);
}

.sidebar-link-active {
  background: var(--color-lavender-subtle);
  color: var(--color-primary);
  font-weight: 600;
  border-color: var(--color-lavender-border);
}

.sidebar-link-active svg {
  color: var(--color-primary);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--color-hairline);
}

.sidebar-main {
  flex: 1;
  padding: var(--spacing-lg);
  min-width: 0;
}

/* ── Login Page ─────────────────────────────────────────────────────────── */
.login-page {
  background: radial-gradient(circle at 50% 25%, var(--color-lavender-subtle) 0%, transparent 60%), var(--color-canvas);
}

.login-card {
  border-color: var(--color-hairline-strong);
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--color-lavender-border);
}

/* ── Mobile Adjustments ─────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .modal {
    padding: var(--spacing-md);
    border-radius: var(--rounded-lg);
  }

  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--color-hairline);
    padding: var(--spacing-sm);
    gap: 4px;
  }

  .sidebar-brand {
    display: none;
  }

  .sidebar-link {
    width: auto;
    flex: 1 1 auto;
    justify-content: center;
    padding: 8px 12px;
    font-size: 13px;
  }

  .sidebar-footer {
    flex-direction: row;
    margin-top: 0;
    border-top: none;
    padding-top: 0;
  }

  .sidebar-footer .sidebar-link {
    flex: 1 1 auto;
  }

  .sidebar-main {
    padding: var(--spacing-md);
  }
}

/* ── Tabs & Sub-navigation ─────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--rounded-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-ink-muted);
  background: var(--color-surface-1);
  border: 1px solid var(--color-hairline);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease-in-out;
}

.tab-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-ink);
  border-color: var(--color-hairline-strong);
}

.tab-btn-active {
  background: var(--color-lavender-subtle);
  color: var(--color-primary);
  border-color: var(--color-lavender-border);
  font-weight: 600;
}

.tab-btn-active svg {
  color: var(--color-primary);
}

/* ── Utility ────────────────────────────────────────────────────────────── */
.copyable {
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0;
  word-break: break-all;
}

.divider {
  border-top: 1px solid var(--color-hairline);
  margin: var(--spacing-md) 0;
}
