/* Base look shared by every part of the page. Colours and sizes come only from
   the custom properties in themes.css; each module's own rules are in its own file. */

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-base);
}

[hidden] { display: none !important; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ---- Buttons, inputs, selects ---- */

.btn {
  font: inherit;
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--text-on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { background: var(--disabled-bg); color: var(--disabled-text); border-color: var(--border-subtle); cursor: default; }
.btn.small { padding: 2px 8px; font-size: var(--font-size-sm); }

.icon-btn {
  font: inherit;
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.link-btn {
  font: inherit;
  font-size: var(--font-size-sm);
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

select, input[type="text"], input[type="number"], input[type="search"] {
  font: inherit;
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
}
select:focus, input:focus, .btn:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}
input.invalid { border-color: var(--error); color: var(--error); }
input[type="checkbox"] { accent-color: var(--accent); }

/* ---- Segmented switch (ui.segmented) ---- */

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.seg button {
  font: inherit;
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 0;
  padding: 4px 10px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--text-on-accent); }
.seg.disabled button { color: var(--disabled-text); background: var(--disabled-bg); cursor: default; }

.muted { color: var(--text-muted); font-size: var(--font-size-sm); }
.warn-text { color: var(--error); }

/* ---- Dialogs (ui.openModal) ---- */

dialog.dlg {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.3);
  max-width: min(980px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  width: 100%;
  display: flex;
  flex-direction: column;
}
dialog.dlg:not([open]) { display: none; }
dialog.dlg::backdrop { background: rgba(0, 0, 0, 0.35); }
.dlg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
  font-size: var(--font-size-md);
}
.dlg-body { overflow: auto; flex: 1; min-height: 0; }
.dlg-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
}

/* ---- Error bar under the tab toolbar ---- */

.error-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  background: var(--error-bg);
  border-bottom: 1px solid var(--error-border);
  color: var(--error);
}
