@import url("./tokens.css");

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--link-hover); }

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-on);
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.skip-link:focus { top: var(--space-4); }

/* ——— App shell ——— */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  padding: var(--space-5) var(--space-4);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  box-shadow: 1px 0 0 rgba(28, 25, 23, 0.04);
}

.sidebar .brand {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-6);
  padding: var(--space-2) var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text);
}

.sidebar .brand i {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--accent-muted);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}

.sidebar nav a,
.sidebar nav button.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  min-height: 44px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  border: none;
  background: none;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background var(--transition), color var(--transition);
}

.sidebar nav a i,
.sidebar nav button.nav-link i {
  width: 20px;
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.85;
}

.sidebar nav a:hover,
.sidebar nav button.nav-link:hover {
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.sidebar nav a.active {
  background: var(--accent-muted);
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar nav a.active i { opacity: 1; }

.main {
  flex: 1;
  padding: var(--space-6) var(--space-8);
  overflow: auto;
  max-width: 1200px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
  line-height: var(--leading-normal);
}

/* ——— Cards ——— */
.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}

.card h2,
.card h3 {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  margin-bottom: var(--space-4);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.card p + p { margin-top: var(--space-2); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: var(--space-5);
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.04);
}

.stat-card:hover {
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(28, 25, 23, 0.05);
}

.stat-card .value {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: 1;
  color: var(--accent);
}

.stat-card .label {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
  font-weight: 500;
}

/* ——— Forms ——— */
label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

input, select, textarea {
  width: 100%;
  padding: 0.75rem var(--space-4);
  min-height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
  line-height: 1.25;
  margin-bottom: var(--space-4);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select {
  height: 44px;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2.5rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' 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 0.75rem center;
  background-size: 1rem;
}

select:hover {
  background-color: var(--surface-hover);
}

select:focus {
  background-color: var(--surface);
}

input::placeholder { color: var(--muted); }

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 var(--accent-muted);
}

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

.input-icon-wrap {
  position: relative;
  margin-bottom: var(--space-4);
}

.input-icon-wrap input {
  padding-left: 2.75rem;
  margin-bottom: 0;
}

.input-icon-wrap i {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 var(--space-5);
}

.form-grid-full {
  grid-column: 1 / -1;
}

.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.checkbox-inline input {
  width: auto;
  min-height: auto;
  height: auto;
  margin: 0;
}

/* ——— Buttons ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.75rem var(--space-5);
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-muted);
}

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

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

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

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.25);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }

.btn-block { width: 100%; }

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

/* ——— Tables ——— */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }

.pagination-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

.pagination-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  min-height: 36px;
}

.pagination-size {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-sm);
  color: var(--muted);
  white-space: nowrap;
}

.pagination-size select {
  width: auto;
  min-width: 4.25rem;
  height: 36px;
  min-height: 36px;
  margin: 0;
  padding: 0.375rem 2rem 0.375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.25;
}

.pagination-summary {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--muted);
  line-height: 36px;
  white-space: nowrap;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
}

.pagination-page {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  min-width: 6.5rem;
  line-height: 36px;
  text-align: center;
  white-space: nowrap;
}

table { width: 100%; border-collapse: collapse; }

thead { position: sticky; top: 0; z-index: 1; }

th, td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

th {
  background: var(--bg-elevated);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-hover); }

td.num { text-align: right; font-variant-numeric: tabular-nums; }

.table-empty td {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-secondary);
  border: none;
}

/* ——— Badges ——— */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-active, .badge-scheduled, .badge-running {
  background: var(--success-bg);
  color: var(--success);
}
.badge-inactive, .badge-draft {
  background: rgba(120, 113, 108, 0.15);
  color: var(--text-secondary);
}
.badge-paused {
  background: rgba(251, 191, 36, 0.15);
  color: #b45309;
}
.badge-completed {
  background: var(--info-bg);
  color: var(--info);
}
.badge-failed, .badge-suspended, .badge-cancelled {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ——— Alerts ——— */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}

.alert-error {
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.alert-info {
  background: var(--accent-muted);
  border-color: rgba(13, 148, 136, 0.2);
  color: var(--accent);
}

.theme-light .alert-error {
  color: var(--semantic-danger-fg);
}

.theme-light .alert-info {
  color: var(--brand-700);
}

.error { color: var(--danger); font-size: 0.875rem; margin-bottom: var(--space-4); }
.hint { color: var(--text-secondary); font-size: 0.875rem; line-height: 1.5; }
.success { color: var(--success); font-size: 0.875rem; }

/* ——— Auth (split layout) ——— */
.auth-body {
  background: var(--bg-elevated);
}

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
}

.auth-hero {
  position: relative;
  overflow: hidden;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-light .auth-hero {
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(13, 148, 136, 0.12) 0%, transparent 55%),
    linear-gradient(165deg, #ecfdf5 0%, #faf9f7 48%, #faf9f7 100%);
  border-right-color: var(--border-subtle);
}

.auth-hero-art {
  position: absolute;
  right: -4%;
  bottom: -6%;
  width: min(540px, 88%);
  pointer-events: none;
  user-select: none;
}

.auth-hero-art img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 24px 48px rgba(28, 25, 23, 0.08));
}

.auth-hero-inner {
  position: relative;
  z-index: 1;
  width: min(480px, 100%);
  padding: var(--space-8) var(--space-6);
}

.auth-hero .logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-6);
  color: var(--text);
}

.auth-hero .logo i {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: var(--accent-muted);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
}

.auth-hero h2 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  margin-bottom: var(--space-4);
  max-width: 14ch;
}

.auth-hero h2 em {
  font-style: normal;
  color: var(--accent);
}

.auth-hero > .auth-hero-inner > p {
  color: var(--text-secondary);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  max-width: 38ch;
  margin-bottom: var(--space-6);
}

.auth-feature-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.auth-feature-list li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(28, 25, 23, 0.04);
}

.auth-feature-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.auth-feature-icon.whatsapp {
  background: rgba(18, 140, 126, 0.12);
  color: #128c7e;
}

.auth-feature-icon.data {
  background: var(--info-bg);
  color: var(--info);
}

.auth-feature-icon.schedule {
  background: var(--warning-bg);
  color: var(--warning);
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: var(--bg-elevated);
}

.auth-panel-wrap {
  width: min(440px, 100%);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow:
    0 1px 2px rgba(28, 25, 23, 0.04),
    0 16px 40px rgba(28, 25, 23, 0.06);
}

.auth-card-top {
  margin-bottom: var(--space-5);
}

.auth-step-track {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: var(--space-5);
}

.auth-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.auth-step-dot.active {
  background: var(--accent);
  transform: scale(1.1);
}

.auth-step-line {
  flex: 1;
  height: 2px;
  background: var(--border-subtle);
  margin: 0 var(--space-2);
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-2);
}

.auth-card .subtitle {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.auth-card .step-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--accent);
  margin-bottom: var(--space-2);
}

.field-hint {
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  margin: calc(var(--space-2) * -1) 0 var(--space-4);
}

.phone-input-group {
  display: flex;
  align-items: stretch;
  min-height: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
  margin-bottom: var(--space-4);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-card .phone-input-group {
  min-height: 52px;
  height: auto;
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  background: var(--bg);
}

.phone-input-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
  background: var(--surface);
}

.phone-prefix {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  background: rgba(18, 140, 126, 0.06);
  border-right: 1px solid var(--border-subtle);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.phone-prefix i {
  color: #128c7e;
  font-size: 1.125rem;
}

.phone-input-group input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  margin-bottom: 0;
  box-shadow: none;
  padding: 0 var(--space-4);
  font-size: 1.0625rem;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.phone-input-group input:focus {
  box-shadow: none;
}

.otp-input-wrap {
  margin-bottom: var(--space-2);
}

.otp-input-wrap input {
  min-height: 52px;
  margin-bottom: 0;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: 0.4em;
  text-align: center;
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}

.btn-lg {
  min-height: 48px;
  padding-top: 0.875rem;
  padding-bottom: 0.875rem;
  font-size: var(--text-base);
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  box-shadow: none;
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-subtle);
  text-decoration: none;
}

.auth-card-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.auth-flow {
  display: flex;
  flex-direction: column;
}

.auth-section + .auth-section {
  margin-top: var(--space-4);
}

.auth-section-expand[hidden] {
  display: none;
}

.auth-phone-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.auth-phone-summary-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted);
}

.auth-phone-summary strong {
  flex: 1;
  font-size: var(--text-base);
  letter-spacing: 0.04em;
}

.btn-sm {
  min-height: 36px;
  padding: 0.375rem 0.75rem;
  font-size: var(--text-sm);
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.csv-cell {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 10rem;
}

.csv-cell-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.csv-cell-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.csv-cell-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.csv-filename {
  font-size: var(--text-xs);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 11rem;
}

.csv-cell-actions {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}

.csv-cell-empty {
  justify-content: flex-start;
  gap: var(--space-2);
}

.btn-icon-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-icon-sm:hover {
  color: var(--text);
  background: var(--surface-muted);
  border-color: var(--border-strong, var(--border));
}

.cell-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: var(--text-xs);
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.id-copy-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 14rem;
}

.copy-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.copy-btn.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(15, 23, 42, 0.45);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-dialog {
  width: min(960px, 100%);
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-dialog-sm {
  width: min(480px, 100%);
  max-height: none;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.modal-header p {
  margin: var(--space-1) 0 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.modal-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.modal-body {
  padding: var(--space-4) var(--space-5);
  overflow: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
}

/* ——— App dialogs (confirm / alert / success / loading) ——— */
body.app-dialog-open {
  overflow: hidden;
}

.app-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
}

.app-dialog-overlay[hidden] {
  display: none !important;
}

.app-dialog-loading {
  z-index: 1300;
}

.app-dialog-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
  text-align: center;
  animation: app-dialog-in 0.18s ease-out;
}

.app-dialog-panel-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-5);
}

.app-dialog-icon-wrap {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
}

.app-dialog-icon-neutral {
  background: var(--surface-muted);
  color: var(--text-secondary);
}

.app-dialog-icon-danger {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
}

.app-dialog-icon-warning {
  background: rgba(217, 119, 6, 0.12);
  color: #d97706;
}

.app-dialog-icon-success {
  background: rgba(22, 163, 74, 0.12);
  color: #16a34a;
}

.app-dialog-content h2 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

.app-dialog-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

.app-dialog-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-5);
  flex-wrap: wrap;
}

.app-dialog-actions .btn {
  min-width: 108px;
}

.app-dialog-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: app-dialog-spin 0.75s linear infinite;
}

.app-dialog-loading-text {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
}

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

@keyframes app-dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.auth-mode-badge {
  display: inline-block;
  margin-top: var(--space-3);
  padding: 0.25rem 0.625rem;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: 999px;
  background: var(--accent-muted);
  color: var(--accent);
}

.auth-mode-badge[data-mode="returning"] {
  background: rgba(18, 140, 126, 0.08);
  color: var(--accent);
}

.auth-mode-badge[data-mode="new"] {
  background: rgba(59, 130, 246, 0.1);
  color: #2563eb;
}

/* Legacy single-column auth fallback */
.auth-page.auth-simple {
  grid-template-columns: 1fr;
  place-items: center;
  padding: var(--space-6);
}

.auth-page.auth-simple .auth-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

/* ——— Stepper ——— */
.steps {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.step {
  padding: var(--space-2) var(--space-4);
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  transition: all var(--transition);
}

.step.active {
  background: var(--accent-muted);
  border-color: rgba(13, 148, 136, 0.35);
  color: var(--accent);
}

.step.done {
  background: var(--success-bg);
  border-color: rgba(74, 222, 128, 0.25);
  color: var(--success);
}

/* ——— Mapping & preview ——— */
.mapping-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: var(--space-4);
  align-items: center;
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.mapping-row label { margin-bottom: 0; }
.mapping-row select { margin-bottom: 0; }
.mapping-row span { color: var(--muted); font-size: 0.875rem; }

.preview-table {
  font-size: 0.875rem;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
}

.preview-table h2 {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--muted);
  margin-bottom: var(--space-2);
}

.spreadsheet-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid #c8c8c8;
  border-radius: 2px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.spreadsheet-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.spreadsheet-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.spreadsheet-table th,
.spreadsheet-table td {
  border: 1px solid #d4d4d4;
  padding: 0.375rem 0.625rem;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.spreadsheet-table th {
  background: linear-gradient(180deg, #f3f3f3 0%, #e8e8e8 100%);
  color: #1f2937;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  box-shadow: inset 0 -1px 0 #c8c8c8;
}

.spreadsheet-table tbody tr:nth-child(even) td:not(.spreadsheet-row-num) {
  background: #fafafa;
}

.spreadsheet-table tbody tr:hover td:not(.spreadsheet-row-num) {
  background: #eef6ff;
}

.spreadsheet-row-num {
  width: 42px;
  min-width: 42px;
  text-align: center;
  background: #f3f3f3 !important;
  color: #6b7280;
  font-weight: 600;
  font-size: 0.6875rem;
  position: sticky;
  left: 0;
  z-index: 1;
  box-shadow: inset -1px 0 0 #c8c8c8;
}

.spreadsheet-table thead .spreadsheet-row-num {
  z-index: 3;
  background: linear-gradient(180deg, #f3f3f3 0%, #e8e8e8 100%) !important;
}

.spreadsheet-empty {
  background: #fff;
}

.time-range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}

.time-range-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.time-range-row select {
  margin-bottom: 0;
}

.day-chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.day-chip {
  position: relative;
  cursor: pointer;
  margin: 0;
}

.day-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.day-chip span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 600;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.day-chip input:checked + span {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
}

.day-chip input:focus-visible + span {
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.form-actions .btn {
  min-height: 44px;
  padding-left: var(--space-5);
  padding-right: var(--space-5);
}

.form-actions .btn-primary {
  margin-left: auto;
}

@media (max-width: 520px) {
  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .form-actions .btn-primary {
    margin-left: 0;
  }
}

/* ——— Empty state ——— */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
}

.empty-state i {
  font-size: 2rem;
  color: var(--muted);
  margin-bottom: var(--space-4);
  opacity: 0.6;
}

.empty-state h3 {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: var(--space-5);
  max-width: 32ch;
  margin-left: auto;
  margin-right: auto;
}

/* ——— Agent info card ——— */
.agent-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

.agent-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--accent-muted);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.agent-card strong {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
}

/* ——— Responsive ——— */
@media (max-width: 900px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-hero {
    display: flex;
    flex-direction: column;
    min-height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .auth-hero-art {
    position: relative;
    right: auto;
    bottom: auto;
    width: min(320px, 85%);
    margin: var(--space-4) auto 0;
    order: 2;
  }
  .auth-hero-inner {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    order: 1;
  }
  .auth-hero .logo,
  .auth-hero h2,
  .auth-hero > .auth-hero-inner > p {
    margin-left: auto;
    margin-right: auto;
  }
  .auth-hero h2 { max-width: none; }
  .auth-feature-list { text-align: left; max-width: 360px; margin: 0 auto; }
  .auth-panel { padding: var(--space-5); }
}

@media (max-width: 520px) {
  .auth-hero-art { display: none; }
}

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-3) var(--space-4);
  }
  .sidebar .brand { margin-bottom: var(--space-3); }
  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .sidebar nav a,
  .sidebar nav button.nav-link {
    width: auto;
    padding: var(--space-2) var(--space-3);
    min-height: 40px;
    font-size: 0.875rem;
  }
  .sidebar nav a.active { box-shadow: inset 0 -3px 0 var(--accent); }
  .main { padding: var(--space-5) var(--space-4); }
  .form-grid { grid-template-columns: 1fr; }
  .mapping-row { grid-template-columns: 1fr; }
  .mapping-row span { display: none; }
}
