:root {
  --sidebar: #1a1d2e;
  --sidebar-hover: #252a40;
  --sidebar-text: #a8b3cf;
  --sidebar-active: #fff;
  --accent: #4c6fff;
  --accent-2: #7c3aed;
  --danger: #dc2626;
  --ok: #16a34a;
  --bg: #f0f2f5;
  --card: #fff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  min-height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
}

.brand {
  padding: 0 1.25rem 1.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--sidebar-active);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 0.75rem;
}

.nav-section {
  padding: 0.5rem 0;
}
.nav-label {
  padding: 0.35rem 1.25rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
}
.nav-item {
  display: block;
  padding: 0.55rem 1.25rem;
  color: inherit;
  text-decoration: none;
  font-size: 0.9rem;
  border-left: 3px solid transparent;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
}
.nav-item.active {
  background: var(--sidebar-hover);
  color: var(--sidebar-active);
  border-left-color: var(--accent);
}

.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge.ok {
  background: #dcfce7;
  color: #166534;
}
.badge.info {
  background: #dbeafe;
  color: #1d4ed8;
}
.badge.warn-top {
  background: #fef3c7;
  color: #92400e;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
}

.content {
  padding: 1.5rem 1.75rem 2.5rem;
  flex: 1;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 1.25rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  justify-content: flex-end;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: #0ea5e9;
  color: #fff;
}
.btn-secondary {
  background: #2563eb;
  color: #fff;
}
.btn-purple {
  background: var(--accent-2);
  color: #fff;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-ghost {
  background: #e2e8f0;
  color: var(--text);
}
.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
}

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
}
.card h3 {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.card .val {
  font-size: 1.65rem;
  font-weight: 800;
  margin-top: 0.35rem;
  line-height: 1.2;
}
.card .icon {
  float: right;
  opacity: 0.35;
  font-size: 1.5rem;
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.chart-card h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.table-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.table-tools input[type='search'],
.table-tools select {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
table.data th,
table.data td {
  padding: 0.65rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  background: #f8fafc;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
table.data tr:hover td {
  background: #fafafa;
}

.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.72rem;
}
.pill.on {
  background: #dcfce7;
  color: #166534;
}
.pill.off {
  background: #fee2e2;
  color: #991b1b;
}

.td-provider {
  max-width: 160px;
  vertical-align: top;
}
.provider-edit {
  display: inline-block;
  min-width: 3.5rem;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
  border: 1px dashed transparent;
  cursor: text;
  outline: none;
  font-weight: 500;
}
.provider-edit:hover,
.provider-edit:focus {
  border-color: var(--border);
  background: #f8fafc;
}
.provider-edit-hint {
  display: block;
  font-size: 0.62rem;
  margin-top: 0.2rem;
  line-height: 1.25;
}

.signal-bars {
  display: inline-flex;
  gap: 2px;
  align-items: flex-end;
  height: 14px;
}
.signal-bars span {
  width: 4px;
  background: #cbd5e1;
  border-radius: 1px;
}
.signal-bars span.on {
  background: var(--ok);
}
.signal-bars span:nth-child(1) {
  height: 4px;
}
.signal-bars span:nth-child(2) {
  height: 7px;
}
.signal-bars span:nth-child(3) {
  height: 10px;
}
.signal-bars span:nth-child(4) {
  height: 14px;
}

.mono {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.72rem;
  word-break: break-all;
  max-width: 220px;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 110px;
}

/* Pastikan tombol aksi tidak tertutup elemen lain (scroll/stacking) */
table.data td.td-actions {
  position: relative;
  z-index: 2;
  vertical-align: top;
}
table.data td.td-actions .btn {
  pointer-events: auto;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.88rem;
}
.alert.warn {
  background: #ffedd5;
  border: 1px solid #fdba74;
  color: #9a3412;
}
.alert.err {
  background: #fee2e2;
  color: #991b1b;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  padding: 1.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}
.modal h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}
.modal label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.modal select,
.modal textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-family: inherit;
}
.modal textarea {
  min-height: 80px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.api-table code {
  font-size: 0.78rem;
  background: #f1f5f9;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.diag-panel {
  margin-bottom: 1rem;
}
.diag-row {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.diag-row:last-of-type {
  border-bottom: none;
}
.diag-steps {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
}
.diag-step {
  font-size: 0.82rem;
}
.diag-step.ok {
  color: var(--ok);
}
.diag-step.fail {
  color: var(--danger);
}
.diag-forward {
  margin-top: 0.35rem;
  font-size: 0.78rem;
  word-break: break-all;
  color: var(--muted);
}
.diag-hint {
  font-size: 0.72rem;
  margin-top: 0.25rem;
  max-width: 320px;
  line-height: 1.35;
}

@media (max-width: 900px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.75rem;
  }
  .brand {
    width: 100%;
    border: none;
    margin: 0;
    padding-bottom: 0.5rem;
  }
  .nav-section {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }
  .nav-label {
    width: 100%;
  }
}
