/* ShelterGraph — light by default, dark optional. Print is always light. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme tokens ────────────────────────────────────────────────────────── */
body {
  --bg:         #ffffff;
  --fg:         #1f2230;
  --fg-muted:   #5a6072;
  --fg-faint:   #8a90a0;
  --panel-bg:   #f6f7fa;
  --panel-bd:   #d8dce4;
  --hdr-bg:     #eef0f5;
  --hdr-bd:     #d0d4dc;
  --input-bg:   #ffffff;
  --input-bd:   #c2c8d2;
  --input-focus:#5077c8;
  --btn-bg:     #ffffff;
  --btn-bd:     #c2c8d2;
  --btn-hover:  #eef0f5;
  --accent-bg:  #e7eef9;
  --accent-bd:  #b6c5e1;
  --grid:       #e5e8ee;
  --axis:       #6a7080;
  --plot-bg:    #ffffff;
  --fit-color:  #c97a09;
  --sel-fill:   rgba(255, 200, 60, 0.18);
  --sel-stroke: rgba(190, 130, 0, 0.6);
}
body.theme-dark {
  --bg:         #0f0f1e;
  --fg:         #eef;
  --fg-muted:   #aab;
  --fg-faint:   #889;
  --panel-bg:   #12122a;
  --panel-bd:   #2a2a4a;
  --hdr-bg:     #0d0d20;
  --hdr-bd:     #2a2a4a;
  --input-bg:   #1e1e3a;
  --input-bd:   #3a3a5a;
  --input-focus:#5566aa;
  --btn-bg:     #1e1e3a;
  --btn-bd:     #3a3a5a;
  --btn-hover:  #2a2a4a;
  --accent-bg:  #1a2042;
  --accent-bd:  #3a4480;
  --grid:       #23234a;
  --axis:       #7a7aa6;
  --plot-bg:    #0f0f1e;
  --fit-color:  #ffd34d;
  --sel-fill:   rgba(255, 220, 90, 0.10);
  --sel-stroke: rgba(255, 220, 90, 0.55);
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
input, textarea, select, #data-table, #data-table * {
  -webkit-user-select: text;
  user-select: text;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#site-header {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--hdr-bg);
  border-bottom: 1px solid var(--hdr-bd);
  flex-shrink: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  letter-spacing: 0.04em;
}
.site-header-title { flex: 1; text-align: center; }
.site-header-spacer { flex: 0 0 80px; display: flex; align-items: center; justify-content: flex-end; }
.site-header-spacer:first-child { justify-content: flex-start; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#controls {
  width: 290px;
  flex-shrink: 0;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-bd);
  overflow-y: auto;
  padding: 10px 12px 24px;
}

.ctl-sec {
  border-bottom: 1px solid var(--panel-bd);
  padding: 10px 0;
}
.ctl-sec:first-child { padding-top: 4px; }
.ctl-sec h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--fg-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.ctl-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--fg-muted);
}
.ctl-field input[type="text"],
.ctl-field input[type="number"],
.ctl-field select {
  background: var(--input-bg);
  border: 1px solid var(--input-bd);
  color: var(--fg);
  padding: 4px 6px;
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
}
.ctl-field input:focus, .ctl-field select:focus { outline: 1px solid var(--input-focus); }

.ctl-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* Axis range/tick inputs: a 2x2 grid that must fit inside the 290 px controls
   panel. Without min-width:0, each cell's intrinsic input width (size=20 ≈
   140 px) forces the panel to overflow horizontally. */
.axis-range-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-items: center;
}
.axis-range-grid .ctl-field {
  margin: 0;
  min-width: 0;
}
.axis-range-grid .ctl-field input[type="text"] {
  width: 100%;
  min-width: 0;
}

#data-paste {
  width: 100%;
  height: 90px;
  background: var(--input-bg);
  border: 1px solid var(--input-bd);
  color: var(--fg);
  padding: 6px 8px;
  border-radius: 3px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  resize: vertical;
}

.ctl-status {
  font-size: 11px;
  color: var(--fg-faint);
  margin: 4px 0;
  line-height: 1.4;
}

.ctrl-btn {
  background: var(--btn-bg);
  border: 1px solid var(--btn-bd);
  color: var(--fg);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.ctrl-btn:hover { background: var(--btn-hover); }
.ctl-export { width: 100%; padding: 8px; }

.y-col-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 180px;
  overflow-y: auto;
  background: var(--input-bg);
  border: 1px solid var(--input-bd);
  border-radius: 3px;
  padding: 4px;
}
.y-col-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 2px;
  color: var(--fg);
}
.y-col-row:hover { background: var(--btn-hover); }
.y-col-swatch { width: 12px; height: 12px; flex-shrink: 0; border-radius: 2px; border: 1px solid var(--input-bd); }

#fit-result {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  color: var(--fg);
  background: var(--accent-bg);
  border: 1px solid var(--accent-bd);
  border-radius: 3px;
  padding: 6px 8px;
  margin-top: 6px;
  line-height: 1.5;
  min-height: 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Plot / table area with view tabs ────────────────────────────────────── */
#plot-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
  min-height: 0;
}

#view-tabs {
  display: flex;
  gap: 0;
  background: var(--hdr-bg);
  border-bottom: 1px solid var(--panel-bd);
  flex-shrink: 0;
}
.view-tab {
  background: transparent;
  border: none;
  border-right: 1px solid var(--panel-bd);
  border-bottom: 2px solid transparent;
  color: var(--fg-muted);
  font-family: inherit;
  font-size: 12px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.view-tab:hover { background: var(--btn-hover); color: var(--fg); }
.view-tab.active {
  background: var(--bg);
  color: var(--fg);
  border-bottom-color: var(--input-focus);
  font-weight: 600;
}

#plot-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
}
#plot { width: 100%; height: 100%; display: block; }

#table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0;
}
#data-table {
  border-collapse: collapse;
  font-size: 12px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  width: 100%;
}
#data-table thead th {
  position: sticky;
  top: 0;
  background: var(--hdr-bg);
  border-bottom: 1px solid var(--panel-bd);
  border-right: 1px solid var(--panel-bd);
  padding: 6px 10px;
  font-weight: 600;
  color: var(--fg);
  text-align: right;
  white-space: nowrap;
}
#data-table thead th:first-child { text-align: left; color: var(--fg-muted); }
#data-table tbody td {
  padding: 3px 10px;
  border-bottom: 1px solid var(--panel-bd);
  border-right: 1px solid var(--panel-bd);
  text-align: right;
  white-space: nowrap;
  color: var(--fg);
}
#data-table tbody td:first-child { color: var(--fg-faint); text-align: left; }
#data-table tbody tr.row-x        { background: transparent; }
#data-table tbody tr.row-y        { background: transparent; }
#data-table tbody tr.in-selection td { background: var(--accent-bg); }
#data-table thead th.col-x { background: var(--accent-bg); border-bottom-color: var(--accent-bd); }
#data-table thead th.col-y { background: var(--accent-bg); border-bottom-color: var(--accent-bd); }
#data-table tbody td.col-x { background: rgba(127,127,127,0.06); }
#data-table tbody td.col-y { background: rgba(127,127,127,0.06); }
#data-table tbody tr.in-selection td.col-x,
#data-table tbody tr.in-selection td.col-y { background: var(--accent-bg); }

/* Editable cells / headers — inputs styled to look like the static cells. */
#data-table thead th { padding: 2px 4px; }
#data-table tbody td { padding: 1px 4px; }
.dt-hdr-input,
.dt-cell-input {
  width: 100%;
  min-width: 60px;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  font: inherit;
  padding: 3px 6px;
  text-align: right;
  border-radius: 2px;
  box-sizing: border-box;
}
.dt-hdr-input { font-weight: 600; }
.dt-hdr-input:hover,
.dt-cell-input:hover { border-color: var(--input-bd); }
.dt-hdr-input:focus,
.dt-cell-input:focus {
  outline: none;
  border-color: var(--input-focus);
  background: var(--bg);
}
.dt-del-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-faint);
  font-size: 14px;
  line-height: 1;
  width: 22px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
}
.dt-del-btn:hover { color: #d65c5c; border-color: #d65c5c; }
#data-table tfoot td { background: var(--panel-bg); }

/* ── Print ───────────────────────────────────────────────────────────────── */
#print-block {
  display: none;
  background: #fff;
  color: #000;
}
#print-block h1 { font-size: 22px; margin-bottom: 12px; text-align: center; }
#print-block #print-fit {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  margin-top: 16px;
  white-space: pre-wrap;
}

@media print {
  body { background: #fff; color: #000; overflow: visible; height: auto; }
  #site-header, #controls, #view-tabs { display: none !important; }
  #main, #plot-area, #plot-wrap, #table-wrap { display: none !important; }
  #print-block { display: block; padding: 24px; }
  #print-block canvas { width: 100%; height: auto; }
  @page { size: landscape; margin: 0.4in; }
}
