/* Visual Studio — styles */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --ink: #0b1220;
  --ink-2: #334155;
  --muted: #64748b;
  --border: #e7ebf3;
  --border-2: #eef1f6;
  --accent: #6366f1;
  --accent-ink: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #15803d;
  --warn: #b91c1c;
  --warn-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 14px rgba(15,23,42,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'Space Grotesk', 'Inter', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  z-index: 10;
}
.header-inner {
  width: 100%;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { display: flex; align-items: baseline; gap: .5rem; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand-mark { font-size: 1.25rem; }
.brand-text { font-size: 1.05rem; }
.brand-sub { font-size: .75rem; color: var(--muted); font-weight: 500; }
.header-actions { display: flex; gap: .5rem; align-items: center; }
.theme-picker { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.theme-picker select { padding: .35rem .5rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font-family: inherit; font-size: .85rem; }

/* Buttons */
.btn {
  padding: .5rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
}
.btn:hover { background: var(--surface-2); border-color: #d6dbe6; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-ghost { background: transparent; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-danger-ghost { color: var(--warn); border-color: var(--border); }
.btn-danger-ghost:hover { background: var(--warn-soft); border-color: #fca5a5; }
.btn-icon {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; font-size: 1rem; line-height: 1; color: var(--ink-2);
}
.btn-icon:hover { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--accent); }
.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; }

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr 320px;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-section { padding: .85rem; border-bottom: 1px solid var(--border-2); overflow: hidden; display: flex; flex-direction: column; }
.sidebar-section:nth-child(1) { flex: 0 0 auto; max-height: 40%; }
.sidebar-section:nth-child(2) { flex: 1 1 auto; min-height: 0; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; }
.sidebar-head h3 { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.sidebar-foot { padding: .75rem .85rem; border-top: 1px solid var(--border-2); color: var(--muted); font-size: .72rem; line-height: 1.4; }

.scenario-list, .chart-list { list-style: none; overflow-y: auto; flex: 1; min-height: 0; }
.scenario-list li, .chart-list li {
  display: flex; align-items: center; justify-content: space-between; gap: .25rem;
  padding: .45rem .55rem; border-radius: var(--radius-sm); cursor: pointer;
  font-size: .85rem; color: var(--ink-2);
  border: 1px solid transparent;
}
.scenario-list li:hover, .chart-list li:hover { background: var(--surface-2); }
.scenario-list li.active, .chart-list li.active { background: var(--accent-soft); color: var(--accent-ink); border-color: #c7d2fe; font-weight: 600; }
.list-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-actions { display: none; gap: .2rem; }
.scenario-list li:hover .list-actions,
.chart-list li:hover .list-actions,
.scenario-list li.active .list-actions,
.chart-list li.active .list-actions { display: inline-flex; }
.list-actions button {
  width: 22px; height: 22px; border: none; background: transparent; cursor: pointer;
  border-radius: 4px; color: var(--muted); font-size: .85rem;
}
.list-actions button:hover { background: var(--border-2); color: var(--ink); }

/* Canvas */
.canvas-wrap {
  display: flex; flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.canvas-head { padding: .85rem 1.25rem .25rem; }
.chart-title-input {
  width: 100%; border: none; background: transparent;
  font-size: 1.35rem; font-weight: 700; color: var(--ink);
  padding: .25rem 0; outline: none;
}
.chart-title-input:focus { box-shadow: inset 0 -2px 0 var(--accent); }
.chart-subtitle-input {
  width: 100%; border: none; background: transparent;
  font-size: .9rem; color: var(--muted); padding: .15rem 0; outline: none;
}
.chart-subtitle-input:focus { box-shadow: inset 0 -1px 0 var(--border); }

.canvas-stage {
  flex: 1; min-height: 0;
  margin: .5rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
}
.chart-host { width: 100%; height: 100%; position: relative; padding: 1.25rem; display: flex; flex-direction: column; }
.chart-host canvas { max-width: 100%; max-height: 100%; }
.chart-host svg { width: 100%; height: 100%; display: block; }

.canvas-foot { display: flex; justify-content: space-between; padding: .25rem 1.25rem .85rem; }
.muted { color: var(--muted); font-size: .8rem; }
.save-status { font-size: .75rem; }
.save-status.saving { color: var(--accent); }

/* Panel (right) */
.panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.panel-tab {
  flex: 1; padding: .7rem .5rem; border: none; background: transparent;
  font-family: inherit; font-size: .82rem; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent;
}
.panel-tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); background: var(--surface); }
.panel-body { padding: 1rem; overflow-y: auto; flex: 1; }
.panel-body.hidden { display: none; }

.field { margin-bottom: 1rem; }
.field label {
  display: block; font-size: .78rem; font-weight: 600; color: var(--ink-2);
  margin-bottom: .35rem;
}
.field label input[type="checkbox"] { margin-right: .4rem; vertical-align: middle; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.field input[type="text"], .field input[type="number"], .field select, .field textarea {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); font-family: inherit;
  font-size: .85rem; color: var(--ink); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hint { font-size: .75rem; color: var(--muted); font-weight: 400; }

/* Data grid */
.grid-wrap { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); margin-bottom: .5rem; }
.data-grid { width: 100%; border-collapse: collapse; font-size: .82rem; }
.data-grid th, .data-grid td {
  border: 1px solid var(--border-2);
  padding: 0;
  min-width: 70px;
}
.data-grid th input, .data-grid td input {
  width: 100%; padding: .4rem .5rem; border: none; background: transparent;
  font-family: inherit; font-size: inherit; color: var(--ink); outline: none;
}
.data-grid th input { font-weight: 600; background: var(--surface); }
.data-grid td input:focus, .data-grid th input:focus { background: var(--accent-soft); }

/* Series colors */
.series-colors { display: flex; flex-wrap: wrap; gap: .4rem; }
.series-color { display: flex; align-items: center; gap: .4rem; padding: .3rem .5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: .78rem; }
.series-color input[type="color"] { width: 24px; height: 24px; border: none; padding: 0; background: transparent; cursor: pointer; }

/* Type grid */
.type-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.type-card {
  padding: .75rem .5rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer; text-align: center; font-size: .78rem;
  font-weight: 500; color: var(--ink-2); transition: all .15s ease;
}
.type-card:hover { background: var(--accent-soft); border-color: var(--accent); }
.type-card.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.type-card .icon { display: block; font-size: 1.35rem; margin-bottom: .2rem; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 520px;
  box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
  max-height: 90vh;
}
.modal-card.modal-sm { max-width: 380px; }
.modal-card header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-card header h3 { font-size: 1rem; font-weight: 600; }
.modal-card .modal-body { padding: 1rem 1.25rem; overflow-y: auto; }
.modal-card footer { padding: .75rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; }
.modal textarea { width: 100%; padding: .65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: 'JetBrains Mono', monospace; font-size: .82rem; resize: vertical; }

/* Toast */
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: .65rem 1rem; border-radius: var(--radius-sm);
  font-size: .85rem;
  z-index: 2000;
  box-shadow: var(--shadow-md);
}
.toast.hidden { display: none; }
.toast.err { background: var(--warn); }
.toast.ok { background: var(--ok); }

/* SVG chart helpers */
.vs-svg text { font-family: var(--font-sans); fill: var(--ink-2); }
.vs-svg .axis-line { stroke: var(--border); }
.vs-svg .grid-line { stroke: var(--border-2); stroke-dasharray: 3 3; }
.vs-svg .axis-label { font-size: 12px; font-weight: 600; fill: var(--ink); }
.vs-svg .tick-label { font-size: 11px; }
.vs-svg .value-label { font-size: 11px; font-weight: 600; }
.vs-svg .bar { transition: opacity .15s; }
.vs-svg .connector { stroke: var(--muted); stroke-dasharray: 2 2; fill: none; }
.vs-svg .net-line { stroke-width: 2; fill: none; }
.vs-svg .net-dot { r: 3.5; }

/* Frappe Gantt overrides (milestone diamonds) */
.gantt .bar-milestone .bar { fill: var(--accent) !important; }
.gantt .bar-wrapper.milestone .bar { display: none; }
.gantt .bar-wrapper.milestone .milestone-diamond { fill: var(--accent); stroke: var(--accent-ink); stroke-width: 1; }

/* Responsive */
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 200px 1fr 280px; }
}
@media (max-width: 860px) {
  body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; height: auto; }
  .sidebar, .panel { border-right: none; border-left: none; border-bottom: 1px solid var(--border); }
  .sidebar { max-height: 260px; }
  .panel { max-height: 420px; }
  .canvas-stage { min-height: 420px; }
  .header-actions .btn-ghost { display: none; }
}
