* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px "Segoe UI", Arial, sans-serif;
  background: #1e1e1e;
  color: #d4d4d4;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; }
#nav {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0 14px;
  background: #252526;
  border-bottom: 1px solid #3c3c3c;
}
#nav a {
  padding: 10px 16px;
  color: #bbb;
  text-decoration: none;
  border-bottom: 2px solid transparent;
}
#nav a:hover { color: #fff; }
#nav a.active { color: #fff; border-bottom-color: #569cd6; }
#page { display: flex; flex: 1; min-height: 0; }
#control-panel {
  width: 460px;
  min-width: 320px;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  background: #252526;
  border-right: 1px solid #3c3c3c;
}
#control-scroll { flex: 1; overflow-y: auto; padding: 14px; }
.section { margin: 0 0 20px; padding: 0 0 4px; }
.section-heading {
  margin: 0 0 11px;
  color: #8f8f8f;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.field { margin-bottom: 10px; }
.field > label, .inline-fields label {
  display: block;
  margin-bottom: 4px;
  color: #b7b7b7;
  font-size: 12px;
  font-weight: 600;
}
small, .hint { color: #777; font-size: 11px; font-weight: 400; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 7px 9px;
  color: #d4d4d4;
  background: #3c3c3c;
  border: 1px solid #555;
  border-radius: 4px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 1px solid #0e639c; border-color: #0e639c; }
input::placeholder { color: #777; }
.row { display: flex; gap: 6px; align-items: center; }
.row > input, .row > select { flex: 1; min-width: 0; }
.button {
  padding: 6px 11px;
  color: #d4d4d4;
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.button:hover:not(:disabled) { background: #444; border-color: #777; }
.button:disabled { color: #666; background: #2b2b2b; cursor: default; }
.button.primary { color: #fff; background: #0e639c; border-color: #0e639c; }
.button.primary:hover:not(:disabled) { background: #1177bb; }
.button.success { color: #fff; background: #2b7a43; border-color: #2b7a43; }
.button.compact { padding: 4px 8px; font-size: 12px; }
.button.full { width: 100%; margin-top: 4px; }
.template-summary {
  padding: 10px;
  background: #1f1f1f;
  border: 1px solid #3c3c3c;
  border-radius: 5px;
  line-height: 1.45;
}
.template-summary p { margin: 6px 0 0; color: #999; font-size: 12px; }
.status-pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 7px;
  color: #aaa;
  background: #333;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-pill.available { color: #89d185; background: #193b24; }
.status-pill.planned { color: #ddb96d; background: #493817; }
.dataset-row, .stratum-row { display: flex; gap: 5px; margin-bottom: 5px; }
.dataset-row input { flex: 1; }
.stratum-row .stratum-label { flex: 0 0 105px; }
.stratum-row .stratum-expression { flex: 1; }
.remove-button { color: #f48771; padding: 4px 8px; }
.inline-fields { display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: end; }
.check-field { display: flex !important; align-items: center; gap: 6px; padding: 7px 0; }
.check-field input { width: auto; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  color: #9cdcfe;
  background: #16364b;
  border: 1px solid #245777;
  border-radius: 4px;
  font-size: 12px;
}
.chip button { color: #f48771; background: none; border: 0; cursor: pointer; padding: 0; }
.status-badge { display: inline-block; margin-left: 6px; padding: 2px 5px; border-radius: 3px; font-size: 10px; }
.status-badge.ok { color: #89d185; background: #193b24; }
.status-badge.error { color: #f48771; background: #4b2020; }
#control-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  padding: 10px 14px;
  border-top: 1px solid #3c3c3c;
}
#splitter { width: 4px; flex-shrink: 0; background: #3c3c3c; cursor: col-resize; }
#splitter:hover, #splitter:focus { background: #0e639c; outline: none; }
#preview-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: #2d2d30;
  border-bottom: 1px solid #3c3c3c;
}
#preview-toolbar h1 { flex: 1; margin: 0; color: #ccc; font-size: 14px; text-align: right; }
#preview-body { flex: 1; overflow: auto; }
#preview-area {
  min-height: 360px;
  padding: 16px;
}
#previewPlaceholder, #previewSpinner { color: #777; font-style: italic; text-align: center; }
#previewSheet { width: 100%; }
#detailPanel { padding: 14px 18px 22px; background: #181818; border-top: 1px solid #3c3c3c; overflow-x: auto; }
#detailPanel h2 { margin: 0 0 10px; color: #9cdcfe; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.detail-table { border-collapse: collapse; min-width: 680px; font-size: 12px; }
.detail-table th, .detail-table td { padding: 5px 8px; border: 1px solid #444; text-align: center; }
.detail-table th { background: #2d2d30; }
.detail-table td { background: #202020; }
.detail-table td:first-child { text-align: left; }
.detail-header td { color: #4ec9b0; background: #292929; font-weight: 700; }
.overlay { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.72); }
.overlay[hidden] { display: none; }
.dialog { width: min(1000px, 92vw); height: min(760px, 88vh); display: flex; flex-direction: column; background: #252526; border: 1px solid #555; border-radius: 8px; }
.dialog header, .dialog footer { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid #444; }
.dialog footer { justify-content: flex-end; border-top: 1px solid #444; border-bottom: 0; }
.dialog h2 { flex: 1; margin: 0; font-size: 15px; }
.dialog pre { flex: 1; margin: 0; padding: 14px; overflow: auto; white-space: pre-wrap; font: 12px Consolas, monospace; }
.status-bar { display: flex; align-items: center; gap: 9px; flex-shrink: 0; padding: 4px 14px; color: #fff; background: #007acc; font-size: 12px; }
.status-bar.idle { color: #aaa; background: #333; }
.status-bar.error { background: #b93030; }
.status-indicator { width: 8px; height: 8px; background: #fff; border-radius: 50%; }
.status-bar.idle .status-indicator { background: #4ec9b0; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #1e1e1e; }
::-webkit-scrollbar-thumb { background: #4b4b4b; border-radius: 4px; }
@media (max-width: 850px) {
  #control-panel { width: 390px; min-width: 300px; }
  #preview-toolbar h1 { display: none; }
}
