/* Lyrcloud dashboard. Builds on the tokens defined in styles.css. */

.dash-body {
  background: var(--bg);
}

.dash-body::before {
  display: none;
}

.dash-loading {
  padding: 40px;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.mono,
.dash-app code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.88em;
}

.dash-app code {
  color: var(--link);
}

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

.wrap {
  word-break: break-all;
}

/* ---------------------------------------------------------------- sidebar */

.dash-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 20px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface-sidebar);
}

.dash-sidebar .brand {
  padding: 0 8px;
}

.dash-sidebar nav {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  font-size: 0.92rem;
}

.dash-sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--ink-soft);
}

.dash-sidebar nav a:hover {
  color: var(--text);
  background: var(--hover);
}

.dash-sidebar nav a[aria-current="page"] {
  color: var(--text);
  background: rgba(50, 211, 255, 0.12);
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  color: var(--brand);
  font-size: 0.85rem;
}

.nav-label {
  margin: 18px 10px 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  text-transform: uppercase;
}

.sidebar-docs {
  margin-top: auto;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------------------------------------------------------------- topbar */

.dash-topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(16px);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-pill,
.plan-pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: capitalize;
}

.preview-pill {
  border: 1px dashed var(--warn-line);
  color: var(--warn-ink);
}

.plan-pill {
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: #03131d;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  font-weight: 800;
}

.icon-button {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}

/* ---------------------------------------------------------------- form controls */

.dash-app select,
.dash-app input:not([type="checkbox"]):not([type="radio"]),
.dash-app textarea {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-input);
  font: inherit;
  font-size: 0.92rem;
}

.dash-app select:focus,
.dash-app input:focus,
.dash-app textarea:focus {
  outline: 2px solid rgba(50, 211, 255, 0.45);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--hover);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  border-color: rgba(148, 163, 184, 0.45);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn.primary {
  border-color: transparent;
  color: #04101a;
  background: linear-gradient(135deg, #58e1ff, #32d3ff);
}

.btn.danger {
  border-color: rgba(255, 107, 107, 0.4);
  color: var(--danger-ink);
  background: rgba(255, 107, 107, 0.08);
}

.btn.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.row.center {
  justify-content: center;
}

.grow {
  flex: 1 1 260px;
}

.field {
  display: grid;
  gap: 8px;
  max-width: 420px;
  margin-bottom: 16px;
  font-weight: 650;
}

.form-error {
  margin: 10px 0 0;
  color: var(--danger-ink);
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--track);
  transition: background 150ms ease;
  pointer-events: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  transition: transform 150ms ease;
}

.switch input:checked + .switch-track {
  background: var(--brand-strong);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------- content */

.dash-content {
  display: grid;
  gap: 20px;
  width: min(1120px, 100%);
  padding: 28px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-head h1 {
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  letter-spacing: -0.03em;
  word-break: break-word;
}

.page-head p {
  margin: 6px 0 0;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.panel h2 {
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel.empty {
  padding: 48px 22px;
  text-align: center;
}

.panel.empty h2 {
  font-size: 1.4rem;
}

.empty-icon {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 16px;
  border-radius: 16px;
  color: #03131d;
  background: linear-gradient(135deg, var(--brand), var(--success));
  font-size: 1.4rem;
  font-weight: 800;
}

.panel.callout {
  border-color: var(--warn-line);
  background: var(--warn-bg);
}

.grid-2,
.grid-3,
.stat-grid {
  display: grid;
  gap: 20px;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
}

.sample-note {
  margin: -8px 0 0;
  color: var(--warn-ink);
  font-size: 0.8rem;
}

.sample-note.inline {
  margin: 0;
}

.quick span {
  color: var(--brand);
  font-weight: 800;
}

.quick h3 {
  margin-top: 10px;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.quick p {
  margin: 4px 0 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.quick:hover {
  border-color: rgba(50, 211, 255, 0.4);
}

.zone-list {
  display: grid;
}

.zone-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 10px;
  border-top: 1px solid var(--line);
}

.zone-row:hover {
  background: var(--hover);
}

.zone-favicon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 10px;
  color: var(--brand);
  background: rgba(50, 211, 255, 0.1);
  font-weight: 800;
}

.zone-name {
  flex: 1;
  min-width: 0;
}

.zone-name b {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zone-name small {
  color: var(--muted);
  text-transform: capitalize;
}

.status {
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.status.ok {
  color: var(--success);
}

.status.pending {
  color: var(--warn-ink);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.panel > .setting-row:first-child,
.panel-head + .setting-row {
  border-top: 0;
  padding-top: 0;
}

.setting-row h3 {
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}

.setting-row p {
  margin: 4px 0 0;
  font-size: 0.88rem;
  line-height: 1.5;
}

.setting-control {
  flex: none;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 20px;
  margin: 0 0 18px;
  font-size: 0.92rem;
}

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

.facts dd {
  margin: 0;
}

.ns-list,
.route-list,
.rule-list {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}

.ns-list li,
.route-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 460px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-input);
}

.rule-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.rule-list li div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.rule-list code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rule-form,
.dns-form {
  display: grid;
  gap: 10px;
}

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

.dns-form {
  grid-template-columns: 100px 1fr 2fr auto auto;
  align-items: center;
  margin-bottom: 6px;
}

.plan-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.plan-option {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}

.plan-option:has(input:checked) {
  border-color: var(--brand);
  background: rgba(50, 211, 255, 0.06);
}

.plan-option input {
  margin-top: 3px;
  accent-color: var(--brand);
}

.plan-option span {
  display: grid;
  gap: 4px;
}

.plan-option small {
  color: var(--muted);
  line-height: 1.4;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.segmented a {
  padding: 6px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.segmented a[aria-current="true"] {
  color: var(--text);
  background: rgba(50, 211, 255, 0.14);
}

/* ---------------------------------------------------------------- tables */

.table-scroll {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table th,
.table td {
  padding: 12px 10px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.table th {
  border-top: 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.table td:last-child {
  text-align: right;
}

.link {
  color: var(--link);
  font-weight: 750;
}

.type-tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--link);
  background: rgba(50, 211, 255, 0.1);
  font-size: 0.78rem;
  font-weight: 800;
}

.proxy-toggle {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.proxy-toggle.on {
  border-color: rgba(255, 159, 67, 0.5);
  color: var(--orange-ink);
  background: rgba(255, 159, 67, 0.1);
}

/* ---------------------------------------------------------------- charts */

.chart {
  margin: 0;
}

.chart figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.chart figcaption span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.chart figcaption strong {
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}

.chart-plot {
  position: relative;
  cursor: crosshair;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-grid line {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-area {
  fill: rgba(50, 211, 255, 0.12);
}

.chart-line {
  fill: none;
  stroke: var(--brand);
  stroke-width: 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.chart-cursor {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0;
  vector-effect: non-scaling-stroke;
}

.chart-ticks text {
  fill: var(--muted);
  font-size: 14px;
}

.chart-tooltip {
  position: absolute;
  top: -6px;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-input);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip span {
  color: var(--muted);
}

/* ---------------------------------------------------------------- editor */

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 20px;
}

.editor-panel,
.preview-panel {
  display: flex;
  flex-direction: column;
}

.dash-app .code-editor {
  flex: 1;
  min-height: 380px;
  padding: 14px;
  color: #c4f1ff;
  background: #050810;
  color-scheme: dark;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  tab-size: 2;
  resize: vertical;
}

.preview-panel .row input {
  flex: 1;
  min-width: 0;
}

.preview-output {
  flex: 1;
  min-height: 200px;
  margin: 14px 0 0;
  padding: 14px;
  overflow: auto;
  border-radius: 10px;
  color: #d7deea;
  background: #050810;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-solid);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: none;
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1020px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2,
  .grid-3,
  .editor-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 820px) {
  .dash-app {
    grid-template-columns: 1fr;
  }

  .dash-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 200ms ease;
  }

  .dash-app.sidebar-open .dash-sidebar {
    transform: none;
    box-shadow: var(--shadow);
  }

  .icon-button {
    display: inline-grid;
    place-items: center;
  }

  .dash-topbar,
  .dash-content {
    padding-inline: 16px;
  }

  .zone-picker select {
    max-width: 150px;
  }

  .preview-pill {
    display: none;
  }
}

@media (max-width: 560px) {
  .stat-grid,
  .dns-form,
  .rule-form {
    grid-template-columns: 1fr;
  }

  .setting-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .rule-list li {
    grid-template-columns: 1fr auto;
  }

  .plan-pill {
    display: none;
  }
}
