:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #20262d;
  --muted: #66717d;
  --line: #d9e0e6;
  --soft: #edf2f5;
  --blue: #1463a5;
  --cyan: #087b8f;
  --green: #16805a;
  --amber: #9a6210;
  --red: #a0422a;
  --violet: #6553b8;
  --shadow: 0 18px 45px rgba(28, 43, 56, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: #aebbc6;
  background: #f9fbfc;
}

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

.rail {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: block;
  max-height: 52px;
  width: auto;
}

.brand h1,
.toolbar h2,
.empty-state h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p,
.toolbar p,
.empty-state p,
.drop-sub,
.status,
.node-sub,
.details p {
  margin: 5px 0 0;
  color: var(--muted);
}

.drop-zone {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px;
  border: 1px dashed #9db1c2;
  border-radius: 8px;
  background: #f8fbfd;
  cursor: pointer;
}

.drop-zone:focus-within,
.drop-zone:hover {
  border-color: var(--blue);
  background: #f3f9fd;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.drop-title {
  font-weight: 700;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.stats div {
  display: grid;
  gap: 2px;
  padding: 12px 8px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.stats div:last-child {
  border-right: 0;
}

.stats strong {
  font-size: 19px;
}

.stats span {
  color: var(--muted);
  font-size: 12px;
}

.status {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.app-ready-only {
  display: none !important;
}

body.app-ready .app-ready-only {
  display: flex !important;
}

body.app-ready .field.app-ready-only {
  display: grid !important;
}

body.app-ready .stats.app-ready-only {
  display: grid !important;
}

body.app-ready .toolbar.app-ready-only {
  display: flex !important;
}

.welcome-card {
  margin: 18px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 14px 18px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.tab {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  padding: 10px 13px;
  border-bottom-color: transparent;
}

.tab.is-active {
  background: var(--bg);
  border-color: var(--line);
  border-bottom-color: var(--bg);
  transform: translateY(1px);
  color: var(--blue);
  font-weight: 700;
}

.subtabs {
  display: flex;
  gap: 8px;
  padding: 10px 18px 0;
  background: var(--panel);
}

.subtab {
  padding: 7px 10px;
  font-size: 12px;
  border-radius: 999px;
}

.subtab.is-active {
  background: #e8f2fb;
  border-color: #a7c4de;
  color: var(--blue);
  font-weight: 700;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px;
}

.actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.actions button {
  min-width: 78px;
  padding: 9px 12px;
}

.export-opt {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  align-self: start;
  margin: 24px 18px;
  max-width: 700px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.diagram-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(360px, 1fr) auto;
  gap: 12px;
  padding: 0 18px 18px;
}

.diagram-wrap {
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(#eef3f6 1px, transparent 1px),
    linear-gradient(90deg, #eef3f6 1px, transparent 1px),
    var(--panel);
  background-size: 32px 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

svg {
  display: block;
  min-width: 100%;
  min-height: 100%;
}

.edge {
  fill: none;
  stroke: #8695a1;
  stroke-width: 2;
}

.edge-label {
  fill: #334155;
  font-size: 11px;
  font-weight: 600;
}

.edge-chip rect { fill: #f8fafc; stroke: #cbd5e1; stroke-width: 1; }
.edge-chip-office rect { fill: #eff6ff; stroke: #93c5fd; }
.edge-chip-after rect { fill: #f5f3ff; stroke: #c4b5fd; }
.edge-chip-holiday rect { fill: #ecfdf5; stroke: #86efac; }
.edge-chip-timeout rect { fill: #fff7ed; stroke: #fdba74; }
.edge-chip-no-answer rect { fill: #fef2f2; stroke: #fca5a5; }

.node-card {
  fill: #fff;
  stroke: #bdc9d3;
  stroke-width: 1.5;
  filter: drop-shadow(0 8px 18px rgba(31, 44, 56, 0.10));
}

.node-title {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.node-sub {
  fill: var(--muted);
  font-size: 12px;
}

.kind-trunk .node-card {
  stroke: var(--blue);
  fill: #f0f7fc;
}

.kind-did .node-card {
  stroke: var(--amber);
  fill: #fff8ea;
}

.kind-ivr .node-card {
  stroke: var(--violet);
  fill: #f3f1ff;
}

.kind-ringgroup .node-card,
.kind-queue .node-card {
  stroke: var(--green);
  fill: #effaf4;
}

.kind-extension .node-card {
  stroke: var(--red);
  fill: #fff3ef;
}

.kind-voicemail .node-card {
  stroke: #9b3d62;
  fill: #fff1f6;
}

.kind-external .node-card {
  stroke: var(--cyan);
  fill: #effbfc;
}

.kind-end .node-card {
  stroke-dasharray: 5 4;
  fill: #f7f8f9;
}

.kind-summary .node-card {
  stroke: #64748b;
  fill: #f8fafc;
  stroke-dasharray: 4 3;
}

.expand-dot {
  fill: #e2e8f0;
  stroke: #64748b;
  cursor: pointer;
}

.expand-glyph {
  fill: #334155;
  font-size: 14px;
  font-weight: 700;
  pointer-events: none;
}

.details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.detail-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.detail-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.detail-card ul {
  margin: 0;
  padding-left: 18px;
}

.detail-card li {
  margin: 4px 0;
}

.is-hidden {
  display: none;
}

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

  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    overflow-x: auto;
  }
}


.edge-office { stroke: #2563eb; }
.edge-after { stroke: #7c3aed; stroke-dasharray: 7 4; }
.edge-holiday { stroke: #059669; stroke-dasharray: 3 3; }
.edge-timeout { stroke: #ea580c; stroke-dasharray: 10 4; }
.edge-no-answer { stroke: #dc2626; stroke-dasharray: 2 5; }

.route-legend { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.legend-item { position: relative; padding-left: 28px; color: var(--muted); font-size: 12px; }
.legend-item::before { content: ""; position: absolute; left: 0; top: 50%; width: 22px; border-top: 3px solid #8695a1; transform: translateY(-50%); }
.legend-item.edge-office::before { border-color: #2563eb; }
.legend-item.edge-after::before { border-color: #7c3aed; border-top-style: dashed; }
.legend-item.edge-holiday::before { border-color: #059669; border-top-style: dashed; }
.legend-item.edge-timeout::before { border-color: #ea580c; border-top-style: dashed; }
.legend-item.edge-no-answer::before { border-color: #dc2626; border-top-style: dotted; }


.node.is-muted, .edge.is-muted, .edge-chip.is-muted { opacity: 0.2; }

.office-hours-badge {
  display: inline-block;
  margin: 6px 0 0;
  padding: 3px 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.office-hours-badge.is-hidden { display: none; }
.node.kind-did { cursor: pointer; }
.node.is-focused .node-card { stroke-width: 2.5; stroke: #b45309; }
.depth-lane { fill: #94a3b8; opacity: 0.06; }
.depth-lane-label { fill: #64748b; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
