/* ==========================================
   SLM Gateway — Enterprise Dashboard Theme
   Override PicoCSS for compact, dense UI
   ========================================== */

/* --- Global overrides --- */
:root {
  --pico-font-size: 16px;
  --pico-line-height: 1.5;
  --pico-spacing: 1rem;
  --pico-form-element-spacing-vertical: 0.55rem;
  --pico-form-element-spacing-horizontal: 0.8rem;
  --pico-border-radius: 6px;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --muted: #64748b;
  --surface: rgba(255,255,255,0.03);
  --surface-hover: rgba(255,255,255,0.06);
  --border-subtle: rgba(255,255,255,0.08);
}

body {
  font-size: 16px;
  background: #0f172a;
}

/* --- Layout --- */
#app-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Top navbar --- */
.app-navbar {
  background: #1e293b;
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  height: 56px;
  display: flex;
  align-items: center;
}

.app-navbar .nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: #f1f5f9;
  margin-right: 2rem;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-navbar .nav-brand svg {
  width: 20px;
  height: 20px;
  opacity: 0.8;
}

.app-navbar .nav-tabs {
  display: flex;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.app-navbar .nav-tabs::-webkit-scrollbar {
  display: none;
}

.app-navbar .nav-tabs li {
  margin: 0;
  padding: 0;
}

.tab-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1.1rem;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  opacity: 1;
  height: 56px;
  box-sizing: border-box;
}

.tab-link:hover {
  color: #e2e8f0;
  background: rgba(255,255,255,0.04);
}

.tab-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
  opacity: 1;
}

.tab-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
}

.logout-link {
  color: #64748b;
  font-size: 0.95rem;
  text-decoration: none;
  padding: 0.5rem 0.9rem;
  border-radius: 4px;
  transition: all 0.15s;
  opacity: 1;
}

.logout-link:hover {
  color: #ef4444;
  background: rgba(239,68,68,0.1);
}

/* --- Main content --- */
.app-main {
  padding: 1.25rem 1.5rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

/* --- Tab content --- */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* --- Section header --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}

.section-header h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin: 0;
  color: #f1f5f9;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-header .count {
  font-size: 0.8rem;
  background: rgba(59,130,246,0.15);
  color: var(--accent);
  padding: 0.15rem 0.55rem;
  border-radius: 10px;
  font-weight: 600;
}

.section-header .subtitle {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 400;
  margin-left: 0.5rem;
}

/* --- Buttons --- */
button, [role="button"] {
  font-size: 0.95rem;
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

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

.btn-cancel {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: #94a3b8;
}

.btn-cancel:hover {
  background: rgba(255,255,255,0.06);
  color: #e2e8f0;
}

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

.btn-danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
}

.btn-refresh {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: #94a3b8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-refresh:hover {
  background: rgba(255,255,255,0.06);
  color: #e2e8f0;
  border-color: rgba(255,255,255,0.25);
}

.btn-refresh svg {
  width: 18px;
  height: 18px;
}

.btn-refresh.spinning svg {
  animation: spin 0.6s linear;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.btn-add {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: white;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.95rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  --pico-background-color: var(--accent);
}

.btn-add:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  --pico-background-color: var(--accent-hover);
}

.btn-add svg {
  width: 16px;
  height: 16px;
}

/* --- Tables --- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--surface);
}

.table-wrap table {
  margin: 0;
  border-collapse: collapse;
  width: 100%;
  min-width: 600px;
}

table th {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255,255,255,0.02);
  white-space: nowrap;
}

table td {
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: #cbd5e1;
  vertical-align: middle;
}

table tbody tr:last-child td {
  border-bottom: none;
}

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

.td-actions {
  white-space: nowrap;
}

.td-actions a, .td-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  color: #94a3b8;
  text-decoration: none;
  transition: all 0.15s;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.td-actions a:hover, .td-actions button:hover {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
}

.td-actions .act-delete:hover {
  background: rgba(239,68,68,0.1);
  color: #ef4444;
}

.td-actions svg {
  width: 16px;
  height: 16px;
}

.td-mono {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
  font-size: 0.9rem;
  color: #94a3b8;
}

.td-truncate {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-row td {
  text-align: center;
  color: #475569;
  padding: 2.5rem;
  font-size: 0.95rem;
}

/* --- Badges / Pills --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.65rem;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-registration  { background: rgba(59,130,246,0.12); color: #60a5fa; }
.badge-peer          { background: rgba(249,115,22,0.12); color: #fb923c; }
.badge-internal      { background: rgba(59,130,246,0.12); color: #60a5fa; }
.badge-pstn          { background: rgba(249,115,22,0.12); color: #fb923c; }
.badge-sip           { background: rgba(168,85,247,0.12); color: #c084fc; }
.badge-Registered    { background: rgba(34,197,94,0.12); color: #4ade80; }
.badge-Unregistered  { background: rgba(239,68,68,0.12); color: #f87171; }
.badge-active        { background: rgba(34,197,94,0.12); color: #4ade80; }
.badge-ended         { background: rgba(100,116,139,0.12); color: #94a3b8; }
.badge-bridge        { background: rgba(59,130,246,0.12); color: #60a5fa; }
.badge-protected     { background: rgba(249,115,22,0.12); color: #fb923c; }
.badge-custom        { background: rgba(34,197,94,0.12); color: #4ade80; }
.badge-loading       { background: rgba(100,116,139,0.08); color: #64748b; }
.badge-error         { background: rgba(239,68,68,0.12); color: #f87171; }
.badge-default       { background: rgba(34,197,94,0.12); color: #4ade80; font-size: 0.72rem; }
.badge-external      { background: rgba(168,85,247,0.12); color: #c084fc; font-size: 0.72rem; }
.badge-disabled      { background: rgba(100,116,139,0.12); color: #64748b; }

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.badge-Registered .badge-dot { background: #4ade80; }
.badge-Unregistered .badge-dot { background: #f87171; }
.badge-active .badge-dot { background: #4ade80; }
.badge-loading .badge-dot { background: #64748b; animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* --- Dialogs / Modals --- */
dialog {
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

dialog article {
  max-width: 820px;
  width: 92vw;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 12px;
  background: #1e293b;
}

dialog article header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

dialog article header h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

dialog article header .close-dialog {
  background: transparent;
  border: none;
  color: #64748b;
  padding: 0.25rem;
  margin: 0;
  cursor: pointer;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  position: static;
  float: none;
  opacity: 1;
}

dialog article header .close-dialog:hover {
  background: rgba(255,255,255,0.08);
  color: #e2e8f0;
}

.dialog-body {
  padding: 1.25rem;
}

.dialog-footer {
  margin: 0.75rem -1.25rem -1.25rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  border-radius: 0 0 12px 12px;
}

.dialog-footer button {
  min-width: 80px;
}

/* --- Forms --- */
label {
  font-size: 0.95rem;
  font-weight: 500;
  color: #94a3b8;
  margin-bottom: 0.7rem;
}

input, select, textarea {
  font-size: 0.95rem;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.1);
  color: #e2e8f0;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

input::placeholder, textarea::placeholder {
  color: #475569;
}

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

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem 1.25rem;
}

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

/* Compact switches */
input[role="switch"] {
  width: 36px;
  height: 20px;
}

/* Codec checkboxes */
.codec-checks {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.35rem 0;
}

.codec-checks label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0;
  font-size: 0.95rem;
  color: #cbd5e1;
  cursor: pointer;
}

.codec-checks input[type="checkbox"] {
  margin: 0;
  width: 16px;
  height: 16px;
}

/* Section divider in forms */
.form-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.35rem;
  margin-top: 0.75rem;
  margin-bottom: 0.35rem;
  grid-column: 1 / -1;
}

.config-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.35rem;
  margin-bottom: 0.35rem;
}

.config-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.25rem 1.25rem;
}

.config-fields-grid .cfg-full {
  grid-column: 1 / -1;
}

.config-fields-grid .cfg-section-title {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--pico-muted-color);
  border-bottom: 1px solid var(--pico-muted-border-color);
  padding-bottom: 0.25rem;
  margin-top: 0.5rem;
  margin-bottom: 0;
}

.config-fields-grid label {
  font-size: 0.95rem;
}

/* --- Login --- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #0f172a;
}

.login-card {
  width: 100%;
  max-width: 440px;
  padding: 3rem 2.5rem;
  background: #1e293b;
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.4);
}

.login-card h3 {
  text-align: center;
  margin-bottom: 2rem;
  font-size: 1.5rem;
  color: #f1f5f9;
}

.login-card .login-brand {
  text-align: center;
  margin-bottom: 0.75rem;
  opacity: 0.5;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.login-card label {
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
}

.login-card input {
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
}

.login-card button[type="submit"] {
  font-size: 1rem;
  padding: 0.75rem 1.25rem;
  margin-top: 0.5rem;
}

.login-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  color: #f87171;
  padding: 0.6rem 0.85rem;
  border-radius: 6px;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

/* --- Toast notifications --- */
.toast-container {
  position: fixed;
  top: 62px;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.75rem 1.1rem;
  font-size: 0.95rem;
  color: #e2e8f0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: auto;
  animation: toastIn 0.2s ease-out;
  max-width: 380px;
}

.toast.toast-out {
  animation: toastOut 0.2s ease-in forwards;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

/* --- Confirm dialog --- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.confirm-box {
  background: #1e293b;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 380px;
  width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

.confirm-box p {
  font-size: 0.95rem;
  color: #e2e8f0;
  margin-bottom: 1.25rem;
}

.confirm-box .confirm-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.confirm-box .btn-cancel {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: #94a3b8;
}

.confirm-box .btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

/* --- Info banner --- */
.info-banner {
  background: rgba(59,130,246,0.06);
  border: 1px solid rgba(59,130,246,0.15);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  color: #94a3b8;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.info-banner svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}

.warn-banner {
  background: rgba(245,158,11,0.08);
  border-color: rgba(245,158,11,0.2);
  color: #fbbf24;
}

.warn-banner svg {
  color: #f59e0b;
}

/* --- Field hints --- */
.field-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* --- Trunk type toggle --- */
.trunk-reg-field {
  /* shown/hidden dynamically */
}

/* --- Password eye toggle --- */
.input-eye-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-eye-wrap input {
  width: 100%;
  padding-right: 2.5rem;
}

.btn-eye {
  position: absolute;
  right: 0.5rem;
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 0.25rem;
  margin: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  min-width: unset;
}

.btn-eye:hover {
  color: #94a3b8;
  background: rgba(255,255,255,0.06);
}

.btn-eye svg {
  width: 16px;
  height: 16px;
}

/* --- Calls: sub-section header --- */
.sub-header {
  font-size: 1rem;
  font-weight: 600;
  color: #94a3b8;
  margin: 1.5rem 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sub-header:first-child {
  margin-top: 0;
}

.sub-header svg {
  width: 18px;
  height: 18px;
  opacity: 0.5;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .app-navbar {
    padding: 0 0.75rem;
  }

  .app-navbar .nav-brand {
    margin-right: 0.75rem;
    font-size: 0.9rem;
  }

  .tab-link {
    padding: 0.6rem 0.75rem;
    font-size: 0.8rem;
  }

  .tab-link span { display: none; }

  .app-main {
    padding: 1rem 0.75rem;
  }

  .section-header {
    flex-wrap: wrap;
  }

  .section-header h2 {
    font-size: 1.15rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

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

  dialog article {
    width: 96vw;
  }

  .table-wrap {
    border-radius: 6px;
  }
}

@media (max-width: 480px) {
  .app-navbar .nav-brand .brand-text { display: none; }

  .section-header .subtitle { display: none; }
}
