/* ============================================
   M.Wolf Dashboard — Calm UI System
   ============================================ */

:root {
  color-scheme: light dark;

  /* Surfaces */
  --bg:           #fbfbfd;
  --surface:      #ffffff;
  --surface-2:    #f4f5f7;
  --surface-3:    #eceef2;
  --border:       #e7e8ec;
  --border-strong:#d8dade;

  /* Text */
  --text:         #16181d;
  --text-muted:   #6a6f78;
  --text-soft:    #9aa0a8;
  --text-invert:  #ffffff;

  /* Accent + states */
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft:  #eff4ff;
  --success:      #16a34a;
  --success-soft: #ecfdf3;
  --danger:       #dc2626;
  --danger-soft:  #fef2f2;
  --warning:      #b45309;
  --warning-soft: #fef6e7;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;

  /* Radius */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Typography */
  --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
          'Tahoma', 'Helvetica Neue', Arial, sans-serif;

  /* Effects */
  --shadow:    0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --t: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #0f1115;
    --surface:       #16181d;
    --surface-2:     #1c1f26;
    --surface-3:     #232730;
    --border:        #262a33;
    --border-strong: #313640;

    --text:          #e8eaed;
    --text-muted:    #9aa0a8;
    --text-soft:     #6a6f78;

    --accent:        #6692ff;
    --accent-hover:  #84a5ff;
    --accent-soft:   #1c2436;
    --success:       #4ade80;
    --success-soft:  #14241a;
    --danger:        #f87171;
    --danger-soft:   #2a1818;
    --warning:       #fbbf24;
    --warning-soft:  #2a2114;

    --shadow:    0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}

/* ============================================
   Reset & Base
   ============================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button,
select {
  cursor: pointer;
}

h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
}

.hidden {
  display: none !important;
}

/* ============================================
   Header
   ============================================ */

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand-shell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  height: 100%;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 0 var(--s-5);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  flex: 0 0 auto;
}

.nav-bar h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.nav-bar .subtitle {
  display: none;
}

/* ============================================
   Layout
   ============================================ */

.container {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: var(--s-6) var(--s-5) var(--s-7);
}

.auth-container {
  max-width: 380px;
  min-height: calc(100vh - 56px);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Auth screens
   ============================================ */

.auth-panel {
  width: 100%;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  box-shadow: var(--shadow);
}

.auth-mark {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  align-self: center;
  margin-bottom: var(--s-2);
}

.auth-heading {
  text-align: center;
  margin-bottom: var(--s-2);
}

.auth-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: var(--s-1);
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
}

.auth-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

/* ============================================
   Sections & Section title
   ============================================ */

.section {
  margin-bottom: var(--s-6);
}

.section-title {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: var(--s-3);
}

/* Backwards-compat alias for any leftover JS class hooks */
.ios-section { margin-bottom: var(--s-6); }
.ios-section-title {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  margin-bottom: var(--s-3);
}

/* ============================================
   Card / Cell
   ============================================ */

.card,
.ios-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.card + .card,
.ios-card + .ios-card {
  margin-top: var(--s-3);
}

.form-card,
.compact-card {
  padding: var(--s-5);
}

.spaced-card {
  margin-top: var(--s-3);
}

.cell,
.ios-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  min-height: 52px;
}

.ios-cell + .ios-cell {
  border-top: 1px solid var(--border);
}

.ios-cell-label {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.ios-cell-value {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text-muted);
  font-size: 14px;
}

.select-cell { width: auto; }

/* ============================================
   Account & Status
   ============================================ */

.account-summary {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-1);
  padding: var(--s-5);
}

.account-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.account-id {
  font-size: 13px;
  color: var(--text-muted);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-soft);
  flex: 0 0 auto;
}

.status-dot.online   { background: var(--success); }
.status-dot.paused   { background: var(--warning); }
.status-dot.offline  { background: var(--text-soft); }
.status-dot.connecting { background: var(--warning); }

/* ============================================
   Tabs
   ============================================ */

.tabs {
  display: flex;
  gap: var(--s-1);
  margin-bottom: var(--s-5);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  position: relative;
  padding: var(--s-3) var(--s-4);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: color var(--t);
}

.tab-btn:hover {
  color: var(--text);
}

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

.tab-btn.active::after {
  content: '';
  position: absolute;
  inset-inline: var(--s-2);
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================
   Buttons
   ============================================ */

.ios-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 40px;
  padding: 0 var(--s-4);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--t), border-color var(--t), color var(--t);
}

.ios-btn:hover { background: var(--surface-3); }

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

.ios-btn-primary {
  background: var(--accent);
  color: var(--text-invert);
}

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

.ios-btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.ios-btn-secondary:hover { background: var(--surface-2); }

.ios-btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
}

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

.ios-btn-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2);
  margin-top: var(--s-4);
}

.standalone-action {
  margin-top: var(--s-3);
  width: auto;
  padding: 0 var(--s-3);
  height: 36px;
}

.icon-text-btn {
  width: auto;
  height: 32px;
  padding: 0 var(--s-3);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: color var(--t), border-color var(--t);
}

.icon-text-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

/* Focus */
.ios-btn:focus-visible,
.tab-btn:focus-visible,
.ios-input:focus-visible,
.ios-select:focus-visible,
.ios-switch:focus-visible,
.icon-text-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================
   Inputs
   ============================================ */

.ios-input,
.ios-select {
  width: 100%;
  height: 40px;
  padding: 0 var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--t), box-shadow var(--t);
}

.ios-input::placeholder { color: var(--text-soft); }

.ios-input:focus,
.ios-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ios-input:disabled,
.ios-select:disabled {
  background: var(--bg);
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

textarea.ios-input {
  height: auto;
  min-height: 80px;
  padding: var(--s-3);
  resize: vertical;
  line-height: 1.55;
}

input[type="time"].ios-input {
  direction: ltr;
  text-align: right;
}

.ios-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236a6f78' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left var(--s-3) center;
  padding-inline-start: var(--s-6);
}

.form-group { margin-bottom: var(--s-4); }
.form-group:last-child { margin-bottom: 0; }
.collapsible-group { margin-bottom: var(--s-4); }

.form-group label {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: var(--s-2);
}

/* Two-column row, collapses on mobile */
.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}

.field-note {
  grid-column: 1 / -1;
  color: var(--text-soft);
  font-size: 12px;
  margin-top: -4px;
}

/* ============================================
   Switch
   ============================================ */

.ios-switch {
  position: relative;
  width: 40px;
  height: 24px;
  appearance: none;
  background: var(--border-strong);
  border: 0;
  border-radius: 999px;
  flex: 0 0 auto;
  cursor: pointer;
  transition: background var(--t);
}

.ios-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 20px;
  height: 20px;
  background: #ffffff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform var(--t);
}

.ios-switch:checked { background: var(--accent); }

[dir="rtl"] .ios-switch:checked::after { transform: translateX(-16px); }
[dir="ltr"] .ios-switch:checked::after { transform: translateX(16px); }

.ios-switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Inline label+switch row */
.rest-toggle-label,
.form-group .rest-toggle-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  margin-bottom: 0; /* Remove the bottom margin from .form-group label */
}

/* ============================================
   Stats
   ============================================ */

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}

.stat-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
}

.stat-item .value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.stat-item .label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: var(--s-2);
}

/* Last-error block */
.last-error {
  padding: var(--s-4);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
  border-radius: var(--r-md);
  color: var(--danger);
  font-size: 13px;
  word-break: break-word;
}

.last-error-text {
  color: var(--danger);
  font-size: 13px;
  word-break: break-word;
  line-height: 1.55;
}

/* ============================================
   Helper text
   ============================================ */

.helper-text {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.helper-stack {
  display: block;
  margin-top: var(--s-2);
}

/* ============================================
   Diagnostics — collapsed by default
   ============================================ */

.diagnostics {
  margin-top: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.diagnostics > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-3) var(--s-5);
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.diagnostics > summary::-webkit-details-marker { display: none; }

.diagnostics > summary::after {
  content: '+';
  font-size: 16px;
  line-height: 1;
  color: var(--text-soft);
  transition: transform var(--t);
}

.diagnostics[open] > summary::after { content: '−'; }

.diagnostics .ios-cell:first-of-type { border-top: 1px solid var(--border); }

.diagnostic-value {
  max-width: 60%;
  text-align: end;
  word-break: break-word;
}

/* ============================================
   Schedule list
   ============================================ */

.schedule-list {
  display: grid;
  gap: var(--s-3);
}

.schedule-card {
  padding: var(--s-5);
}

.schedule-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}

.schedule-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.schedule-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.schedule-badge {
  flex: 0 0 auto;
  padding: 2px var(--s-2);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}

.schedule-badge.enabled {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
}

.schedule-badge.disabled {
  background: var(--surface-2);
  color: var(--text-muted);
}

.schedule-message {
  margin: var(--s-3) 0;
  padding: var(--s-3);
  background: var(--surface-2);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}

.schedule-result {
  display: grid;
  gap: 2px;
  margin-top: var(--s-3);
  padding: var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.schedule-result span {
  color: var(--text-soft);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.schedule-result strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.schedule-result small {
  color: var(--text-soft);
  font-size: 11px;
}

.schedule-result.success strong { color: var(--success); }
.schedule-result.failed strong  { color: var(--danger); }
.schedule-result.skipped strong,
.schedule-result.muted strong   { color: var(--text-muted); }

.schedule-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--s-2);
  margin-top: var(--s-4);
}

/* ============================================
   Toast
   ============================================ */

.toast {
  position: fixed;
  bottom: var(--s-5);
  left: 50%;
  z-index: 1000;
  max-width: min(360px, calc(100vw - 32px));
  padding: var(--s-3) var(--s-4);
  background: #1a1d23;
  color: #ffffff;
  border-radius: var(--r-md);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  transition: opacity var(--t), transform var(--t);
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--accent); }

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 640px) {
  .container {
    padding: var(--s-5) var(--s-4) var(--s-6);
  }

  .form-card,
  .compact-card,
  .schedule-card,
  .stat-item {
    padding: var(--s-4);
  }

  .ios-cell {
    padding: var(--s-3) var(--s-4);
  }

  .inline-fields {
    grid-template-columns: 1fr;
  }

  .schedule-actions {
    grid-template-columns: 1fr 1fr;
  }

  .schedule-actions > :first-child {
    grid-column: 1 / -1;
  }


}

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