:root {
  --bg: #0f1419;
  --surface: #1a222c;
  --surface-2: #232d3a;
  --border: #2e3a4a;
  --text: #e8eef4;
  --muted: #8b9cb0;
  --accent: #3d9cf5;
  --accent-dim: #2563a8;
  --success: #3dd68c;
  --warn: #f5a623;
  --danger: #f25f5c;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: 100vh;
}

.app-single {
  display: block;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}

.autofind-section {
  margin-bottom: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.autofind-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.provision-modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 640px;
  width: calc(100% - 2rem);
  background: var(--surface);
  color: var(--text);
}

.provision-modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-inner {
  padding: 1.25rem;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.sidebar-actions input {
  width: 100%;
  margin-bottom: 0.5rem;
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.device-list li button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  padding: 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
}

.device-list li button:hover {
  background: var(--surface-2);
}

.device-list li button.active {
  border-color: var(--accent-dim);
  background: var(--surface-2);
}

.device-list .serial {
  font-weight: 600;
  font-size: 0.95rem;
}

.device-list .meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.main {
  padding: 1.5rem 2rem 3rem;
  max-width: 1100px;
}

.view-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.tab {
  font-family: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.tab.active {
  color: var(--text);
  border-color: var(--accent-dim);
  background: var(--surface-2);
}

.view-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.signal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.legend-pill {
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.legend-pill.good {
  background: rgba(61, 214, 140, 0.12);
  border-color: rgba(61, 214, 140, 0.35);
}
.legend-pill.medium {
  background: rgba(61, 156, 245, 0.12);
}
.legend-pill.weak {
  background: rgba(245, 166, 35, 0.12);
  border-color: rgba(245, 166, 35, 0.35);
}
.legend-pill.critical {
  background: rgba(242, 95, 92, 0.12);
  border-color: rgba(242, 95, 92, 0.35);
}

.signal-buckets {
  display: grid;
  gap: 1rem;
}

@media (min-width: 900px) {
  .signal-buckets {
    grid-template-columns: 1fr 1fr;
  }
}

.bucket {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.bucket h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bucket h3 .count {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85rem;
}

.bucket ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.bucket li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.bucket li:first-child {
  border-top: none;
}

.bucket li button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: left;
}

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

.sig-dot.good {
  background: var(--success);
}
.sig-dot.medium {
  background: var(--accent);
}
.sig-dot.weak {
  background: var(--warn);
}
.sig-dot.critical {
  background: var(--danger);
}

.device-list .signal-tag {
  font-size: 0.72rem;
  margin-top: 0.25rem;
}

.optical-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .optical-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.metric {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}

.metric span {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.metric strong {
  font-size: 1.05rem;
}

.badge.signal-good {
  color: var(--success);
  background: rgba(61, 214, 140, 0.12);
}
.badge.signal-medium {
  color: var(--accent);
}
.badge.signal-weak {
  color: var(--warn);
  background: rgba(245, 166, 35, 0.12);
}
.badge.signal-critical {
  color: var(--danger);
  background: rgba(242, 95, 92, 0.12);
}

.olt-groups {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.olt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.olt-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.olt-ont-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.olt-ont-table th,
.olt-ont-table td {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-top: 1px solid var(--border);
}

.tag-acs {
  color: var(--success);
  font-size: 0.75rem;
}

.tag-noacs {
  color: var(--warn);
  font-size: 0.75rem;
}

.tag-ok {
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 500;
}

.tag-warn {
  color: var(--warn);
  font-size: 0.75rem;
}

.tag-danger {
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 500;
}

.tag-muted {
  color: var(--muted);
  font-size: 0.75rem;
}

.tiny {
  font-size: 0.7rem;
}

.btn.tiny {
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
}

.olt-actions-cell {
  white-space: nowrap;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.olt-ont-detail {
  margin-top: 1rem;
}

.olt-link-panel {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.pon-editor {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.pon-editor-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.pon-editor-list {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
  font-size: 0.85rem;
}

.pon-editor-form {
  margin-bottom: 0.5rem;
}

.olt-detail-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

.err-banner {
  background: color-mix(in srgb, var(--danger) 18%, var(--surface));
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 1rem;
  color: var(--text);
  font-size: 0.9rem;
}

.tr069-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  margin: 0;
}

.main-header {
  margin-bottom: 1.5rem;
}

.main-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.muted {
  color: var(--muted);
}

.header-meta {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
}

.empty-state {
  margin-top: 2rem;
}

.empty-card {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}

.empty-card h2 {
  margin-top: 0;
}

.forms {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.ok {
  color: var(--success);
  background: rgba(61, 214, 140, 0.12);
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .grid.two {
    grid-template-columns: 1fr;
  }
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

input:focus {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

.check-row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  padding-top: 1.5rem;
}

.wifi-bands {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.wifi-band {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.wifi-band:first-child {
  border-top: none;
  padding-top: 0;
}

.wifi-band h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.hint {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
}

.action-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  font-family: inherit;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 0.9rem;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: #5aadff;
}

.btn.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.ghost:hover {
  background: var(--surface-2);
}

#notice {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

#notice.ok {
  background: rgba(61, 214, 140, 0.12);
  border: 1px solid rgba(61, 214, 140, 0.35);
  color: var(--success);
}

#notice.err {
  background: rgba(242, 95, 92, 0.12);
  border: 1px solid rgba(242, 95, 92, 0.35);
  color: var(--danger);
}

#notice[hidden] {
  display: none;
}