/* =========================================================================
   Atheer · SaaS-Polish Layer (J.3)
   -------------------------------------------------------------------------
   Modern, compact, professional form + settings layout. Loaded LAST so it
   refines without touching existing components. Fixes:
     • Settings forms taking full page width with massive inputs
     • Single-column field cards that look "1990s admin panel"
     • Inconsistent spacing across pages
     • Heavy borders / oversized typography
   ========================================================================= */


/* ──────────────────────────────────────────────────────────────────────────
   §1 · Page rhythm — constrain readable width on dense settings pages
   ──────────────────────────────────────────────────────────────────────────
   Yeastar P-Series uses a max-width for dense forms; we mirror that. Pure
   list/table pages stay full-width for data density.
   ────────────────────────────────────────────────────────────────────────── */
.page,
.page-wrap,
.page-content {
  max-width: 1240px;
  margin-inline: auto;
}

/* Settings/Form pages → narrower & centered for readability */
.page--settings,
.page[data-template="settings"],
.page-content--settings,
section.page:has(.settings-group),
section.page:has(.form-section) {
  max-width: 900px;
}


/* ──────────────────────────────────────────────────────────────────────────
   §2 · Cards — refined elevation + spacing
   ────────────────────────────────────────────────────────────────────────── */
.card,
.settings-card,
.settings-group,
.form-section {
  background: var(--surface-1, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.card + .card,
.settings-card + .settings-card,
.settings-group + .settings-group,
.form-section + .form-section {
  margin-top: 16px;
}

/* Section title within a card */
.card-title,
.section-title,
.form-section__title,
.settings-group__title,
.settings-card__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}


/* ──────────────────────────────────────────────────────────────────────────
   §3 · Settings rows — TWO-COLUMN layout (label | control)
   ──────────────────────────────────────────────────────────────────────────
   This is THE key fix for the "auto-defense" screenshot: rows now display
   as label on one side, compact control on the other — instead of a single
   full-width "label + input stacked" pattern.
   ────────────────────────────────────────────────────────────────────────── */
.settings-row,
.settings-card .field,
.settings-group .field,
.form-section .field,
.settings-group__row,
.kvrow,
.form-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 320px);
  gap: 14px 20px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border, #f1f5f9);
}

.settings-row:last-child,
.settings-card .field:last-child,
.settings-group .field:last-child,
.form-section .field:last-child,
.kvrow:last-child,
.form-row:last-child {
  border-bottom: none;
}

/* The label side */
.settings-row > label,
.settings-row__label,
.settings-card .field > span:first-child,
.settings-group .field > span:first-child,
.form-section .field > span:first-child,
.kvrow > label,
.form-row > label,
.form-row > .field__label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.5;
}

/* Field labels marked with required */
.field > span:first-child[data-required]::after,
.required::after {
  content: " *";
  color: var(--status-error, #dc2626);
}

/* Helper/hint text under a label */
.settings-row__hint,
.field__hint,
.field-hint,
.field > .text-muted {
  grid-column: 1;
  font-size: 12px;
  color: var(--text-secondary, #64748b);
  margin-top: 2px;
  line-height: 1.5;
}


/* ──────────────────────────────────────────────────────────────────────────
   §4 · Inputs — compact, modern, properly sized
   ──────────────────────────────────────────────────────────────────────────
   The screenshot's massive inputs were because .input had no max-width and
   the label/input were stacked, so the container stretched. With the
   grid-row above, the input now naturally fills only the control column
   (max 320px). We also tighten height/padding.
   ────────────────────────────────────────────────────────────────────────── */
.input,
.field input[type="text"],
.field input[type="number"],
.field input[type="email"],
.field input[type="tel"],
.field input[type="password"],
.field input[type="url"],
.field input[type="search"],
.field textarea,
.field select,
input.input,
select.input,
textarea.input {
  width: 100%;
  max-width: 320px;
  padding: 8px 12px;
  font-size: 13.5px;
  line-height: 1.5;
  border: 1.5px solid var(--border, #e2e8f0);
  border-radius: 8px;
  background: var(--surface-1, #fff);
  color: var(--text-primary);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.input:focus,
.input:focus-visible,
input.input:focus,
select.input:focus,
textarea.input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent, #0f62fe);
  box-shadow: 0 0 0 3px rgba(15, 98, 254, 0.12);
}

/* Number inputs — tighter */
input.input[type="number"],
.field input[type="number"] {
  max-width: 160px;
  text-align: end;
  font-variant-numeric: tabular-nums;
}

/* Textareas — different rhythm */
textarea.input,
.field textarea {
  max-width: 100%;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
}

/* When a row uses a wide input (textarea, JSON override etc.) let it span */
.settings-row--wide,
.form-row--wide,
.field--wide {
  grid-template-columns: 1fr;
}

.settings-row--wide > * + *,
.form-row--wide > * + *,
.field--wide > * + * {
  max-width: 100%;
  width: 100%;
}


/* ──────────────────────────────────────────────────────────────────────────
   §5 · Checkbox / toggle rows — compact single-line
   ────────────────────────────────────────────────────────────────────────── */
.settings-row:has(input[type="checkbox"]),
.field:has(input[type="checkbox"]) {
  grid-template-columns: 1fr auto;
}

.settings-row input[type="checkbox"],
.field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent, #0f62fe);
  cursor: pointer;
}


/* ──────────────────────────────────────────────────────────────────────────
   §6 · Page header — consistent rhythm
   ────────────────────────────────────────────────────────────────────────── */
.page-header,
.page__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-header__title,
.page__title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text-primary);
}

.page-header__subtitle,
.page__subtitle {
  font-size: 13.5px;
  color: var(--text-secondary, #64748b);
  margin: 0;
  line-height: 1.55;
}

.page-header__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}


/* ──────────────────────────────────────────────────────────────────────────
   §7 · Buttons — slimmer + consistent
   ────────────────────────────────────────────────────────────────────────── */
.btn,
button.btn {
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--surface-1, #fff);
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.5;
}

.btn:hover,
button.btn:hover {
  background: var(--surface-2, #f8fafc);
  border-color: var(--border-hover, #cbd5e1);
}

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

.btn--primary,
.btn.btn--primary,
button.btn.btn--primary {
  background: var(--accent, #0f62fe);
  color: #fff;
  border-color: var(--accent, #0f62fe);
}

.btn--primary:hover,
button.btn--primary:hover {
  background: var(--accent-hover, #0a52d5);
  border-color: var(--accent-hover, #0a52d5);
}

.btn--sm {
  padding: 5px 10px;
  font-size: 12px;
}


/* ──────────────────────────────────────────────────────────────────────────
   §8 · Tables — denser, professional
   ────────────────────────────────────────────────────────────────────────── */
.data-table table,
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  padding: 10px 14px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary, #64748b);
  background: var(--surface-2, #f8fafc);
  border-bottom: 1.5px solid var(--border, #e2e8f0);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #f1f5f9);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--surface-2, #f8fafc);
}


/* ──────────────────────────────────────────────────────────────────────────
   §9 · Empty-state polish
   ────────────────────────────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state__icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.55;
}

.empty-state h3 {
  font-size: 16px;
  margin: 0 0 4px;
  color: var(--text-primary);
  font-weight: 700;
}

.empty-state p {
  font-size: 13.5px;
  margin: 0;
}


/* ──────────────────────────────────────────────────────────────────────────
   §10 · Responsive breakpoint — mobile / tablet
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .settings-row,
  .settings-card .field,
  .settings-group .field,
  .form-section .field,
  .kvrow,
  .form-row {
    grid-template-columns: 1fr;
    gap: 6px 0;
    align-items: stretch;
  }

  .input,
  .field input,
  .field select,
  .field textarea {
    max-width: 100%;
  }

  .page,
  .page-wrap,
  .page-content {
    padding-inline: 12px;
  }
}


/* ──────────────────────────────────────────────────────────────────────────
   §11 · Tab refinement (when present)
   ────────────────────────────────────────────────────────────────────────── */
.tabs__nav {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid var(--border, #e2e8f0);
  margin-bottom: 18px;
  padding-bottom: 0;
  overflow-x: auto;
}

.tabs__tab,
.tab {
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.tabs__tab:hover,
.tab:hover {
  color: var(--text-primary);
}

.tabs__tab--active,
.tab--active,
.tabs__tab[aria-selected="true"] {
  color: var(--accent, #0f62fe);
  border-bottom-color: var(--accent, #0f62fe);
}
