/* Единая система дизайн-токенов Apple Human Interface Guidelines (macOS / iOS System Settings) */
:root {
  /* Холст и поверхности */
  --bg-canvas: #F5F5F7;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F2F2F7;
  --bg-chrome: rgba(245, 245, 247, 0.86);
  --bg-browser: #111214;

  /* Текст и контраст (WCAG AA+) */
  --ink-primary: #1D1D1F;
  --ink-secondary: #6E6E73;
  --ink-tertiary: #86868B;
  --ink-inverse: #FFFFFF;

  /* Разделители */
  --border-hairline: rgba(60, 60, 67, 0.14);
  --border-strong: rgba(60, 60, 67, 0.24);
  --separator-inset: rgba(60, 60, 67, 0.11);

  /* Семантические цвета Apple System */
  --accent: #007AFF;
  --accent-hover: #0066D6;
  --accent-soft: rgba(0, 122, 255, 0.10);
  --success: #248A3D;
  --success-bg: rgba(52, 199, 89, 0.13);
  --warning: #B25000;
  --warning-bg: rgba(255, 149, 0, 0.14);
  --danger: #D70015;
  --danger-bg: rgba(255, 59, 48, 0.12);

  /* Типографика */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Скругления и тени */
  --radius-card: 14px;
  --radius-control: 10px;
  --radius-pill: 999px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-popover: 0 12px 32px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);

  /* Физика анимаций (Emil/Apple easing) */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-snap: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast: 140ms;
  --dur-base: 220ms;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  color: inherit;
}

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

a:hover {
  text-decoration: underline;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.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;
}

/* Общие кнопки Apple HIG */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--ink-inverse);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--ink-primary);
  border-color: var(--border-hairline);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

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

.btn-danger:hover:not(:disabled) {
  background: #B80012;
}

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

.btn-danger-soft:hover:not(:disabled) {
  background: rgba(255, 59, 48, 0.20);
}

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

.btn-ghost:hover:not(:disabled) {
  background: rgba(60, 60, 67, 0.07);
  color: var(--ink-primary);
}

.btn-lg {
  height: 44px;
  padding: 0 20px;
  font-size: 15px;
  font-weight: 600;
}

.btn-sm {
  height: 30px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: 8px;
}

/* Поля ввода Apple HIG */
.input,
.select,
.textarea {
  width: 100%;
  background: var(--bg-surface);
  color: var(--ink-primary);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-control);
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.input,
.select {
  height: 38px;
}

.textarea {
  min-height: 74px;
  resize: vertical;
}

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

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--border-strong);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.16);
}

/* Переключатель в стиле Apple Switch */
.apple-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
  cursor: pointer;
}

.apple-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.apple-switch-track {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: rgba(120, 120, 128, 0.28);
  transition: background-color var(--dur-base) var(--ease-snap);
}

.apple-switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition: transform var(--dur-base) var(--ease-snap);
}

.apple-switch input:checked + .apple-switch-track {
  background: #34C759;
}

.apple-switch input:checked + .apple-switch-track::after {
  transform: translateX(18px);
}

.apple-switch input:focus-visible + .apple-switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.apple-switch input:disabled + .apple-switch-track {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Статус-бейджи (цвет + текст + форма) */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-idle {
  background: rgba(120, 120, 128, 0.12);
  color: var(--ink-secondary);
}
.status-idle .status-dot {
  background: var(--ink-tertiary);
}

.status-ok {
  background: var(--success-bg);
  color: var(--success);
}
.status-ok .status-dot {
  background: #34C759;
}

.status-warn {
  background: var(--warning-bg);
  color: var(--warning);
}
.status-warn .status-dot {
  background: #FF9500;
}

.status-err {
  background: var(--danger-bg);
  color: var(--danger);
}
.status-err .status-dot {
  background: #FF3B30;
}

.status-info {
  background: var(--accent-soft);
  color: var(--accent);
}
.status-info .status-dot {
  background: var(--accent);
}

/* Карточка сгруппированных настроек Apple HIG */
.hig-card {
  background: var(--bg-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.hig-section-title {
  margin: 0 0 8px 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-secondary);
}

/* Уведомления (inline-баннер) */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-control);
  font-size: 13px;
  line-height: 1.45;
}

.callout-error {
  background: var(--danger-bg);
  color: var(--danger);
}

.callout-warn {
  background: var(--warning-bg);
  color: var(--warning);
}

.callout-ok {
  background: var(--success-bg);
  color: var(--success);
}

.callout-info {
  background: var(--accent-soft);
  color: #0051A8;
}

/* Спиннер загрузки внутри кнопок */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 680ms linear infinite;
  display: inline-block;
  flex-shrink: 0;
}

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

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