/* Layout of drawApp: a sidebar on the left, the tabs on the right. Colours are tokens, redefined for the
   dark theme (chosen by the system, or by the theme menu in the sidebar). */
:root {
  --bg: #ffffff;
  --sidebar: #f0f2f6;
  --text: #262730;
  --muted: #6b6f7b;
  --accent: #e8444d;
  --border: #d9dbe1;
  --cell: #ffffff;
  --cellAlt: #f7f8fa;
  --header: #eef0f4;
  --readOnly: #f2f3f5;
  --code: #f6f7f9;
  --info: #e8f1fb;
  --infoText: #1c4f8a;
  --warning: #fff6d6;
  --warningText: #7a5800;
  --error: #fde8e8;
  --errorText: #9b1c1c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117; --sidebar: #262730; --text: #fafafa; --muted: #a3a8b8; --border: #3d404a;
    --cell: #161a22; --cellAlt: #1b2029; --header: #222733; --readOnly: #1f232b; --code: #161a22;
    --info: #172a40; --infoText: #9cc7f5; --warning: #3a3112; --warningText: #f3d27a;
    --error: #3d1a1a; --errorText: #f5a3a3;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1117; --sidebar: #262730; --text: #fafafa; --muted: #a3a8b8; --border: #3d404a;
  --cell: #161a22; --cellAlt: #1b2029; --header: #222733; --readOnly: #1f232b; --code: #161a22;
  --info: #172a40; --infoText: #9cc7f5; --warning: #3a3112; --warningText: #f3d27a;
  --error: #3d1a1a; --errorText: #f5a3a3;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Source Sans Pro", "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
/* The bar on top; under it either the diagram (the editor fills the window) or the converter. */
#app { display: flex; flex-direction: column; min-height: 100vh; }
[hidden] { display: none !important; }
.topBar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
  height: auto; min-height: 52px; padding: 8px 16px; background: var(--sidebar); border-bottom: 1px solid var(--border); }
.topBar .appTitle { font-size: 1.1rem; margin-right: 8px; }
.topBar .views, .topBar .actions, .topBar .settings { display: flex; align-items: center; gap: 6px; }
.topBar .settings { margin-left: auto; }
.topBar .account { display: flex; align-items: center; gap: 6px; margin-left: 8px; }
.topBar .userName { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem;
  color: var(--muted); }
.topBar .iconButton { width: 32px; padding: 4px 0; text-align: center; }
.topBar button.view { font-weight: 600; }
.topBar button.view.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge { padding: 3px 10px; border-radius: 12px; background: var(--warning); color: var(--warningText); font-size: 0.85rem; }
/* In the diagram the page does not scroll: the editor takes whatever height the bar leaves. */
#app.diagramMode { height: 100vh; overflow: hidden; }
.diagramView { flex: 1; min-height: 0; display: flex; }
.editor { position: relative; flex: 1; display: flex; }
.editor iframe { flex: 1; width: 100%; height: 100%; border: 0; }
.editorStatus { position: absolute; inset: 24px auto auto 24px; max-width: 480px; padding: 10px 14px; border-radius: 8px;
  background: var(--info); color: var(--infoText); }
.editorStatus p { margin: 0; }
.noDiagram { flex: 1; padding: 32px; max-width: 760px; }
.convertView { display: flex; flex: 1; }
.sidebar { width: 280px; flex: none; padding: 20px 16px; background: var(--sidebar); display: flex; flex-direction: column; gap: 8px; }
.sidebar h2 { font-size: 1.05rem; margin: 12px 0 4px; }
.sidebar h2:first-child { margin-top: 0; }
/* Room below the tables, so the page can always scroll to keep a table still when a warning box above it
   grows (ui/dom.js keepPlace does the scrolling; the browser's own anchoring would add to it). */
body { overflow-anchor: none; }
.main { flex: 1; min-width: 0; padding: 16px 32px 50vh; }
.main h1 { margin: 0 0 4px; }
.caption { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.text p, .stats p { margin: 6px 0; }
.text ul { margin: 4px 0 8px; padding-left: 22px; }
code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 20px; border-bottom: 1px solid var(--border); margin: 20px 0 16px; }
.tab { background: none; border: none; padding: 8px 0; font-size: 1.15rem; font-weight: 600; color: var(--text);
       cursor: pointer; border-bottom: 3px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel { display: none; }
.panel.active { display: block; }
.panel h3 { margin: 20px 0 8px; }

/* Boxes, fields, buttons */
.box { padding: 10px 14px; border-radius: 8px; margin: 10px 0; font-size: 0.95rem; }
.box p { margin: 4px 0; }
.box ul { margin: 4px 0; padding-left: 20px; }
.box.info { background: var(--info); color: var(--infoText); }
.box.warning { background: var(--warning); color: var(--warningText); }
.box.error { background: var(--error); color: var(--errorText); }
.status { padding: 0 16px; }
.status .box { margin: 8px 0; }
.status .close { float: right; margin-left: 12px; padding: 0 6px; border: none; background: none; color: inherit; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; font-size: 0.9rem; }
input[type="text"], select, .field textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--cell); color: var(--text); }
.field textarea { resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: 1; }
button { font: inherit; padding: 6px 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--cell);
  color: var(--text); cursor: pointer; }
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); color: #fff; }
.radios { display: flex; flex-direction: column; gap: 4px; font-size: 0.95rem; }
.dropZone { border: 2px dashed var(--border); border-radius: 8px; padding: 16px 12px; text-align: center; cursor: pointer;
  font-size: 0.9rem; color: var(--muted); background: var(--cell); }
.dropZone p { margin: 0; }
.dropZone.over, .dropZone:hover { border-color: var(--accent); color: var(--text); }
details { margin: 12px 0; }
summary { cursor: pointer; font-weight: 600; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 24px; }
.row { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
pre.code { background: var(--code); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto;
  max-height: 70vh; font-size: 0.85rem; }
table.simple { border-collapse: collapse; margin: 8px 0; font-size: 0.9rem; }
table.simple th, table.simple td { border: 1px solid var(--border); padding: 4px 10px; text-align: left; vertical-align: top; }
table.simple th { background: var(--header); }
.lines { white-space: pre-line; }

/* Tabulator, in the page's colours */
/* Prefixed with .tableHolder to win over tabulator.min.css, which is loaded after this file. */
.tableHolder { margin: 10px 0; }
.tableHolder .tabulator { background: var(--cell); border-color: var(--border); font-size: 0.9rem; }
.tableHolder .tabulator .tabulator-header, .tableHolder .tabulator .tabulator-header .tabulator-col { background: var(--header); color: var(--text); border-color: var(--border); }
.tableHolder .tabulator .tabulator-tableholder { background: var(--cell); }
.tableHolder .tabulator-row { background: var(--cell); color: var(--text); border-color: var(--border); }
.tableHolder .tabulator-row.tabulator-row-even { background: var(--cellAlt); }
.tableHolder .tabulator-row .tabulator-cell { border-color: var(--border); }
.tableHolder .tabulator-row.tabulator-selectable:hover,
.tableHolder .tabulator-row.tabulator-selectable:hover .tabulator-cell.readOnly { background: var(--header); }
.tableHolder .clamp { white-space: pre-wrap; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
  line-clamp: 3; overflow: hidden; }
.tableHolder .tabulator-row .tabulator-cell.readOnly { background: var(--readOnly); color: var(--muted); }
.tableHolder .tabulator-row .tabulator-cell.checkCell input { pointer-events: none; }
.tableHolder .tabulator-row .tabulator-cell.tabulator-editing { background: var(--bg); }
.tableHolder .tabulator-row .tabulator-cell.tabulator-editing input,
.tableHolder .tabulator-row .tabulator-cell.tabulator-editing textarea,
.tableHolder .tabulator-row .tabulator-cell.tabulator-editing select { background: var(--bg); color: var(--text); }
.tableHolder .tabulator .tabulator-placeholder .tabulator-placeholder-contents { color: var(--muted); }
/* The list editor's menu is placed in <body>, outside the table. */
body .tabulator-edit-list { background: var(--cell); color: var(--text); }
body .tabulator-edit-list .tabulator-edit-list-item.active,
body .tabulator-edit-list .tabulator-edit-list-item:hover { background: var(--accent); color: #fff; }

@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar { width: auto; }
  .main { padding: 16px; }
}
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
button:disabled { opacity: 0.5; cursor: default; }
.tableHolder .tabulator-row .tabulator-cell.removeCell { cursor: pointer; color: var(--muted); }
.tableHolder .tabulator-row .tabulator-cell.removeCell:hover { color: var(--accent); }
/* Drop-down menus of the bar */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--cell); font-weight: 400; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { border-color: var(--accent); }
.menuItems { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; display: flex; flex-direction: column; gap: 4px;
  min-width: 200px; padding: 6px; background: var(--sidebar); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.settings .menuItems { left: auto; right: 0; }
.menuItems button { text-align: left; border: none; background: none; }
.menuItems button:hover { background: var(--cell); }
.topBar { flex-wrap: nowrap; }
.menu:not([open]) > .menuItems { display: none; }
.topBar .settings .menu { display: block; }
/* A smaller bar, so the editor and the tables keep the room */
.topBar { min-height: 40px; padding: 4px 12px; gap: 6px 12px; font-size: 0.85rem; }
.topBar .appTitle { font-size: 0.95rem; }
.topBar button, .topBar select, .menu > summary { padding: 3px 10px; font-size: 0.85rem; }
/* The converter's sidebar, folded to a thin strip */
.sidebar { position: relative; transition: width 0.15s; }
.sidebar .fold { align-self: flex-end; padding: 0 8px; font-size: 1rem; line-height: 1.4; }
.sidebar.folded { width: 36px; padding: 12px 4px; }
.sidebar.folded .sidebarBody { display: none; }
.sidebarBody { display: flex; flex-direction: column; gap: 8px; }
input.search { font: inherit; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--cell);
  color: var(--text); width: min(320px, 100%); margin: 6px 0; }
body .tabulator-edit-list .tabulator-edit-list-item { color: var(--text); }
body .tabulator-edit-list .tabulator-edit-list-notice { color: var(--muted); }
.diagramView.offstage { position: fixed; left: -200vw; top: 0; width: 100vw; height: 100vh; visibility: hidden; }
.menuItems hr { width: 100%; border: none; border-top: 1px solid var(--border); margin: 2px 0; }
/* A long list of warnings scrolls inside its box, so the table below stays in view */
.panel .box.warning { max-height: 30vh; overflow: auto; }

/* Open from the server (remoteFiles.js) */
.remoteDialog { width: min(640px, 92vw); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
  background: var(--bg); color: var(--text); }
.remoteDialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.remoteDialog h2 { margin: 0 0 10px; font-size: 1.1rem; }
.remoteDialog input[type=search] { width: 100%; box-sizing: border-box; margin-bottom: 8px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--cell); color: var(--text); font: inherit; }
.remoteList { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 6px;
  background: var(--cell); color: var(--text); font: inherit; }
.remoteDialog .dialogButtons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

