/* settings.css — Route Tracker v3 */

/* ─── Settings layout ────────────────────────────────────────────────────── */

.settings-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 24px 60px;
}

.btn-link {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  transition: color .15s;
}
.btn-link:hover { color: var(--text); }

/* ─── Section ────────────────────────────────────────────────────────────── */

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title-row .section-title {
  margin-bottom: 0;
}

/* ─── Field groups ───────────────────────────────────────────────────────── */

.field-group {
  margin-bottom: 14px;
}

.field-group:last-child { margin-bottom: 0; }

.field-group label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.field-group input[type=text],
.field-group input[type=password],
.field-group input[type=number],
.field-group input[type=email],
.field-group select,
input[type=text].sched-time {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color .15s;
}

.field-group input:focus,
.field-group select:focus { border-color: var(--accent); }

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

.field-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

/* ─── Tablet / small desktop (≤ 600px) ──────────────────────────────────── */
@media (max-width: 600px) {
  .field-row-2,
  .field-row-3 { grid-template-columns: 1fr; }
}

/* ─── Phone portrait (≤ 480px — iPhone 15 and similar) ──────────────────── */
@media (max-width: 480px) {
  /* ── Layout: reduce all padding ─────────────────────────────────── */
  .settings-content { padding: 12px 12px 48px; }
  .settings-section { padding: 14px; }

  /* ── Field rows: stack vertically, buttons full-width ────────────── */
  .field-row {
    flex-wrap: wrap;
    align-items: stretch;
  }
  .field-row > input,
  .field-row > select { flex: 1 1 100%; }
  .field-row > button,
  .field-row > .btn-primary,
  .field-row > .btn-secondary { width: 100%; }

  /* ── Form actions (Save Route / Cancel): stack ───────────────────── */
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions > button,
  .form-actions > .btn-primary,
  .form-actions > .btn-secondary { width: 100%; }

  /* ── Settings footer (Save General / Save Alerts): stack ─────────── */
  .settings-footer {
    flex-direction: column;
    align-items: stretch;
  }
  .settings-footer > button,
  .settings-footer > .btn-primary { width: 100%; }

  /* ── Section title row: wrap "+ Add Route" below title if needed ─── */
  .section-title-row { flex-wrap: wrap; gap: 8px; }
  .section-title-row > .btn-primary { align-self: flex-start; }

  /* ── Log section: title + tab buttons wrap to two lines ──────────── */
  .section-title-row.log-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .log-tabs { flex-wrap: wrap; }

  /* ── Routes table: horizontal scroll ────────────────────────────── */
  .routes-table        { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .routes-table table  { min-width: 480px; }

  /* ── Schedule rows: wrap to two lines (days+mode / time+delete) ──── */
  .sched-row { flex-wrap: wrap; row-gap: 6px; }
  .sched-row > select          { flex: 1 1 calc(50% - 4px); min-width: 120px; }
  .sched-row > input.sched-time { flex: 1 1 80px; }
  .sched-row > .btn-tiny       { align-self: flex-end; }

  /* ── Channel fields: keep toggle inline with icon+name ───────────── */
  .channel-header { flex-wrap: nowrap; }

  /* ── Stats grid: 2-per-row ───────────────────────────────────────── */
  .stat-chip { flex: 1 1 calc(50% - 5px); min-width: 130px; }

  /* ── Advisor details: full width ─────────────────────────────────── */
  .advisor-details { width: 100%; }

  /* ── Address picker: dropdown stays within section ───────────────── */
  .addr-dropdown { max-height: 180px; }

  /* ── Touch targets: ensure minimum 44px tap height ──────────────── */
  .btn-tiny  { padding: 8px 12px; font-size: 12px; }
  .log-tab-btn { padding: 7px 12px; }
  .tab       { padding: 12px 14px; }
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  transition: background .15s;
}
.btn-primary:hover { background: #4a6ee0; }

.btn-secondary {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  transition: border-color .15s;
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-tiny {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
}
.btn-tiny:hover { border-color: var(--accent); }
.btn-tiny.btn-danger       { color: var(--red); }
.btn-tiny.btn-danger:hover { border-color: var(--red); }
.btn-secondary.btn-danger       { color: var(--red); }
.btn-secondary.btn-danger:hover { border-color: var(--red); }

/* ─── Footer ─────────────────────────────────────────────────────────────── */

.settings-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
}

.save-status {
  font-size: 12px;
  color: var(--muted);
}
.save-status.ok  { color: var(--green); }
.save-status.err { color: var(--red); }

/* ─── Checkbox / Toggle ──────────────────────────────────────────────────── */

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 8px;
}
.checkbox-label input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; }

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}

/* Toggle switch */
.toggle-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  margin-left: auto;
}
.toggle-label input[type=checkbox] { display: none; }
.toggle {
  width: 40px; height: 22px;
  background: var(--border);
  border-radius: 11px;
  position: relative;
  transition: background .2s;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: left .2s;
}
.toggle-label input:checked + .toggle { background: var(--accent); }
.toggle-label input:checked + .toggle::after { left: 21px; }

/* ─── Channel cards ──────────────────────────────────────────────────────── */

.channel-card { }

.channel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.channel-icon { font-size: 18px; }
.channel-name { font-size: 15px; font-weight: 600; }

.channel-fields {
  padding-top: 4px;
}

/* ─── Routes table ───────────────────────────────────────────────────────── */

.routes-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.routes-table th {
  text-align: left;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.routes-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.routes-table tr:last-child td { border-bottom: none; }

.ap-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  background: rgba(91,124,246,.18);
  color: var(--accent);
  white-space: nowrap;
}

/* ─── Route form ─────────────────────────────────────────────────────────── */

.route-form { border: 2px solid var(--accent); }

.sched-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.sched-row select, .sched-row input { flex: 1; margin-bottom: 0; }
.sched-row input.sched-time { flex: 0.5; min-width: 80px; }

.advisor-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding: 10px 0 6px;
  user-select: none;
}
.advisor-fields { padding-top: 10px; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* ─── System tab ─────────────────────────────────────────────────────────── */

.stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.stat-chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  min-width: 100px;
}
.stat-chip label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.stat-chip span {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.log-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.6;
  color: #94a3b8;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 10px;
}

.log-tabs {
  display: flex;
  gap: 4px;
}
.log-tab-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font);
}
.log-tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

#testResult { margin-top: 12px; }

/* ─── Address picker widget ─────────────────────────────────────────────── */

.addr-wrap {
  position: relative;
  display: flex;
  gap: 4px;
  align-items: stretch;
}

.addr-wrap input[type=text] {
  flex: 1;
  min-width: 0;   /* let flexbox shrink below intrinsic width */
  margin-bottom: 0;
}

.addr-pick-btn,
.addr-map-btn {
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  line-height: 1;
  transition: border-color .15s, color .15s;
  white-space: nowrap;
}
.addr-pick-btn:hover,
.addr-map-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Dropdown list */
.addr-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 200;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.addr-dropdown.open { display: block; }

.addr-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.addr-item:last-child { border-bottom: none; }
.addr-item:hover { background: rgba(91,124,246,.12); color: var(--text); }

.addr-empty {
  padding: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ── Alert / Channel Profile system ─────────────────────────────────────── */

.channel-profiles-block {
  margin-bottom: 20px;
}

.cp-type-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.cp-empty {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 2px;
}

.cp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 6px;
}
.cp-table th {
  text-align: left;
  padding: 5px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.cp-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  vertical-align: middle;
}
.cp-table tr:last-child td { border-bottom: none; }
.cp-table td:last-child { white-space: nowrap; }

.cp-form {
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-top: 8px;
}

.binding-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.binding-row select {
  flex: 1;
  padding: 6px 8px;
  font-size: 13px;
}
.binding-row select:first-child {
  flex: 0 0 100px;
}
