/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   Service Modal — Add / Edit Service
   Tabbed modal with panel integration
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

/* ── Modal shell ──
   Height & flex layout are set in style.css (.modal-box.svc-modal)
   to ensure centralized overrides take effect before this file loads.
   Here: the same heights in dvh where supported. With the browser bar showing,
   90vh / 92vh / 95vh is taller than the visible screen and the footer
   (Cancel / Save) ends up below it. */
.modal-box.svc-modal { max-height: min(90vh, calc(100dvh - 32px)) !important; }
@media (max-width: 768px) {
  .modal-box.svc-modal {
    height: min(92vh, calc(100dvh - 32px)) !important;
    max-height: calc(100dvh - 32px) !important;
  }
}
@media (max-width: 640px) {
  .modal-box.svc-modal {
    height: calc(100dvh - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
  }
}

/* ── Tab system ─────────────────────────────────── */

.svc-tab-bar {
  display: flex;
  flex-shrink: 0;
  gap: 0;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
}

/*
 * Tabs must hard-override the global `button` reset
 * (border-radius:8px, padding:10px 20px, font-weight:600, etc.)
 */
button.svc-tab {
  all: unset;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color .2s, border-color .2s;
  position: relative;
}
button.svc-tab:hover {
  color: var(--text);
}
button.svc-tab.svc-tab-active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

/* Tab icons */
button.svc-tab svg {
  opacity: 0.35;
  flex-shrink: 0;
  transition: opacity .2s, color .2s;
}
button.svc-tab:hover svg {
  opacity: 0.65;
}
button.svc-tab.svc-tab-active svg {
  opacity: 1;
  color: var(--accent);
}

/* Active-tab indicator dot (Panel tab when configured) */
.svc-tab-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  box-shadow: 0 0 6px rgba(16,185,129,0.4);
}

/* ── Tab pane ── */
/* Tab body fills all remaining modal height via flex.
   Panes overlay each other absolutely so only the active one
   is rendered — the container height never changes. */
.svc-tabs {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.svc-tab-body {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.svc-tab-pane {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 24px 24px 20px;
}

/* ── Password field — eye toggle inside input ───── */
.svc-pw-wrap {
  position: relative;
}
.svc-pw-wrap input {
  padding-right: 44px !important;
}

button.svc-pw-toggle {
  all: unset;
  box-sizing: border-box;
  position: absolute;
  right: 1px;
  top: 1px;
  bottom: 1px;
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  border-radius: 0 8px 8px 0;
  transition: color .15s, background .15s;
}
button.svc-pw-toggle:hover {
  color: var(--text);
  background: rgba(255,255,255,0.04);
}

/* Eye icon swap via CSS class */
.svc-pw-toggle .svc-eye-open,
.svc-pw-toggle .svc-eye-closed {
  pointer-events: none;
  flex-shrink: 0;
}
.svc-pw-toggle .svc-eye-closed    { display: none  !important; }
.svc-pw-toggle .svc-eye-open      { display: block !important; }
.svc-pw-toggle.svc-pw-visible .svc-eye-open   { display: none  !important; }
.svc-pw-toggle.svc-pw-visible .svc-eye-closed  { display: block !important; }

/* ── Toggle switch rows ─────────────────────────── */
.svc-toggle-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.svc-toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.svc-toggle-label {
  font-size: 13px;
  color: var(--text);
  user-select: none;
  /* a <label for> so the text toggles the switch too (not just the 36x20 switch) */
  display: inline;
  margin: 0;
  font-weight: 400;
  letter-spacing: 0;
  cursor: pointer;
}
@media (pointer: coarse) {
  .svc-toggle-row, .modal-box.svc-modal .form-toggle-row { min-height: 40px; }
  .svc-toggle-label { padding: 10px 0; }
}

/* ── Test connection ────────────────────────────── */
.svc-test-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 4px;
}
.svc-test-btn {
  padding: 9px 18px;
  font-size: 12px;
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: 8px;
  color: var(--text);
}
.svc-test-btn:hover:not(:disabled) {
  background: rgba(99,102,241,0.14);
  border-color: rgba(99,102,241,0.35);
}
.svc-test-icon {
  display: flex;
  align-items: center;
}
@keyframes svc-spin {
  to { transform: rotate(360deg); }
}
.svc-test-spin svg {
  animation: svc-spin .8s linear infinite;
}
.svc-test-result {
  display: inline-flex;
  align-items: flex-start;
  min-width: 0;
  max-width: 100%;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
}
.svc-test-result-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding-top: 2px;
}
.svc-test-result-text {
  /* Wraps instead of cutting off: a panel's reason for refusing is the useful part. */
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.45;
  max-width: 520px;
}
.svc-test-ok {
  color: var(--green);
  background: rgba(34,197,94,0.08);
}
.svc-test-fail {
  color: var(--red);
  background: rgba(239,68,68,0.08);
}

/* ── Empty states ───────────────────────────────── */
.svc-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 44px 20px;
  gap: 10px;
}
.svc-empty-icon {
  color: var(--muted);
  opacity: 0.15;
}
.svc-empty-text {
  font-size: 13px;
  color: var(--muted);
}

/* ── Footer ─────────────────────────────────────── */
.svc-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}
.svc-btn-cancel {
  border-radius: 10px;
}

/* ── Sub-section divider ────────────────────────── */
.svc-sub-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.svc-sub-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
  .svc-tab-pane {
    padding: 20px 18px 16px;
  }
}
@media (max-width: 640px) {
  /* All five tabs stay visible: they share the row and wrap to a second one if needed
     (a hidden-scrollbar strip cut "Panel" off at 360px). */
  .svc-tab-bar {
    padding: 0 6px;
    flex-wrap: wrap;
  }
  button.svc-tab {
    flex: 1 1 auto;
    justify-content: center;
    padding: 0 6px;
    height: 40px;
    font-size: 11.5px;
    white-space: nowrap;
  }
  button.svc-tab svg {
    display: none;
  }
  .svc-tab-pane {
    padding: 16px 14px 12px;
  }
  .svc-modal-footer {
    padding: 12px 16px;
  }
  .svc-test-row {
    flex-wrap: wrap;
  }
}
@media (pointer: coarse) {
  .modal-box.svc-modal .modal-close { width: 40px; height: 40px; }
  button.svc-tab { height: 44px; }
  .svc-test-btn { min-height: 40px; }
  button.svc-pw-toggle { top: 0; bottom: 0; }   /* the whole field height: 40px, not 38 */
}
/* Landscape phones: give the scrolling pane the height the header, tabs and footer took */
@media (max-height: 520px) {
  .modal-box.svc-modal > .modal-header { padding: 8px 16px; }
  button.svc-tab { height: 38px; }
  .svc-tab-pane { padding: 12px 18px; }
  .svc-modal-footer { padding: 8px 16px; }
}
