:root {
  --bg: #1e2530;
  --bg-elev: #2a3441;
  --bg-hover: #34404f;
  --fg: #e6edf3;
  --muted: #8b98a5;
  --accent: #58a6ff;
  --accent-dark: #3a82e0;
  --warn: #f97583;
  --ok: #56d364;
  --border: #3a4655;
  --code-bg: #2a3441;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  /* Sticky footer: full-height flex column so the footer sits at the bottom
     of the viewport even when page content is short. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { color: var(--accent); margin-top: 0; }
h2 { color: var(--fg); margin-top: 1.6rem; margin-bottom: 0.6rem; font-size: 1.15rem; }
code {
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.92em;
}
.muted { color: var(--muted); font-size: 0.9em; }
small.muted { display: block; margin-top: 0.2rem; }

/* Top navigation */
.topnav {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.7rem 1.5rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topnav-brand a {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--accent);
}
.topnav-brand a:hover { text-decoration: none; }
.topnav-links {
  display: flex;
  gap: 1.2rem;
  flex: 1;
}
.topnav-links a {
  color: var(--fg);
  padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
}
.topnav-links a:hover { text-decoration: none; color: var(--accent); }
.topnav-links a.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.topnav-user {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.topnav-name { color: var(--muted); font-size: 0.9em; }
.lang-switch {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 4px; font-size: 0.8em; cursor: pointer;
}
.lang-footer {
  text-align: center; padding: 1rem; font-size: 0.8em; color: var(--muted);
}
.lang-footer a { margin: 0 0.3em; }
.lang-footer strong { margin: 0 0.3em; color: var(--fg); }

.site-footer {
  text-align: center; padding: 1.5rem 1rem; font-size: 0.8em; color: var(--muted);
  flex-shrink: 0;
}
.lang-footer { flex-shrink: 0; }

main {
  max-width: 920px;
  margin: 2rem auto;
  padding: 0 1.5rem;
  /* Grow to fill leftover vertical space so the footer is pushed to the bottom. */
  flex: 1 0 auto;
  width: 100%;
}

/* Auth (login) */
.auth-card {
  max-width: 380px;
  margin: 6rem auto 2rem;
  padding: 2rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.auth-logo { display: block; width: 220px; height: 220px; margin: 0 auto 1.25rem; }
.auth-card h1 { text-align: center; margin-bottom: 0.3rem; }
.auth-card .muted { text-align: center; margin-bottom: 1.5rem; }
.auth-card .hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.auth-card .checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95em;
}
.auth-card .checkbox input { width: auto; }

/* Pages and cards */
.page { max-width: 920px; }

/* Dashboard: grid uses the full viewport, text stays at a comfortable measure */
main:has(.page-dashboard) { max-width: none; }
.page-dashboard { max-width: none; }
.page-dashboard > .breadcrumb,
.page-dashboard > .page-header,
.page-dashboard > .muted,
.page-dashboard > .section-title,
.page-dashboard > .section-empty,
.page-dashboard > .empty-state { max-width: 920px; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem 1.5rem;
  margin: 1rem 0;
}

/* Key-value list */
.kv { list-style: none; padding: 0; margin: 0; }
.kv li {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.kv li:last-child { border-bottom: none; }
.kv span:first-child { color: var(--muted); }

/* Forms */
.form { display: flex; flex-direction: column; gap: 0.9rem; }
.form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.92em;
  color: var(--muted);
}
.form input, .form select, .form textarea {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  font-size: 0.95rem;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.18);
}
.form input:disabled { opacity: 0.6; cursor: not-allowed; }
.form-actions { margin-top: 0.5rem; }

/* Buttons */
.btn {
  display: inline-block;
  background: var(--bg-hover);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.55rem 1.1rem;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn-primary {
  background: var(--accent);
  color: #0c1119;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
}
.btn-link:hover { text-decoration: underline; }
.btn-link.btn-warn { color: var(--warn); }
.inline-form { display: inline; }

/* Tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
table.data th {
  background: var(--bg-hover);
  color: var(--muted);
  font-weight: 500;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr.is-disabled { opacity: 0.55; }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.actions > * { margin-left: 0.6rem; }
table.data th.actions { text-align: right; }

/* Badges */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 9px;
  font-size: 0.78em;
  background: var(--bg-hover);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-admin { background: rgba(88, 166, 255, 0.15); color: var(--accent); border-color: rgba(88, 166, 255, 0.4); }
.badge-user  { background: var(--bg-hover); color: var(--fg); }
.badge-ok    { background: rgba(86, 211, 100, 0.15); color: var(--ok); border-color: rgba(86, 211, 100, 0.4); }
.badge-warn  { background: rgba(249, 117, 131, 0.15); color: var(--warn); border-color: rgba(249, 117, 131, 0.4); }

/* Flash messages */
.flash {
  padding: 0.7rem 1rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  margin: 0 0 1rem;
}
.flash-success { background: rgba(86, 211, 100, 0.10); border-color: rgba(86, 211, 100, 0.4); color: var(--ok); }
.flash-error   { background: rgba(249, 117, 131, 0.10); border-color: rgba(249, 117, 131, 0.4); color: var(--warn); }
.flash-info    { background: rgba(88, 166, 255, 0.10); border-color: rgba(88, 166, 255, 0.4); color: var(--accent); }

/* Diagram grid (dashboard) */
.diagram-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-top: 1rem;
}
.diagram-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s, transform 0.1s;
}
.diagram-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.diagram-card-link {
    display: block;
    padding: 14px 16px 10px;
    color: var(--fg);
    text-decoration: none;
    flex: 1;
}
.diagram-card-link:hover { text-decoration: none; }
.diagram-card h3 {
    margin: 0 0 8px;
    font-size: 1rem;
    color: var(--accent);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.diagram-slug {
    margin: 0 0 6px;
    font-size: 0.78em;
    color: var(--muted);
}
.diagram-slug code { font-size: 0.85em; padding: 0 4px; }
.diagram-meta {
    margin: 0;
    font-size: 0.78em;
    color: var(--muted);
}
.diagram-card-actions {
    padding: 6px 12px 8px;
    border-top: 1px solid var(--border);
    display: flex; gap: 4px; justify-content: flex-end;
}

/* Projects (folders) */
.page-header-actions { display: flex; gap: 0.5rem; align-items: center; }
.section-empty { margin: 0.75rem 0 0; }

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 1rem;
}
.project-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color 0.15s, transform 0.1s;
}
.project-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.project-card-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: var(--fg);
    text-decoration: none;
    flex: 1;
}
.project-card-link:hover { text-decoration: none; }
.project-folder { color: var(--accent); display: inline-flex; flex: none; }
.project-body { display: flex; flex-direction: column; min-width: 0; }
.project-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.project-count { font-size: 0.78em; color: var(--muted); }
.project-heading { display: flex; align-items: center; gap: 0.5rem; }
.project-heading .icon { color: var(--accent); }

/* Breadcrumb (project page) */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85em;
    margin-bottom: 0.75rem;
}
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb-sep { color: var(--border); }
.breadcrumb-current { color: var(--fg); }

/* Icons (SVG sprite, inherits currentColor) */
.icon {
    width: 18px; height: 18px;
    flex: none;
    stroke: currentColor;
    fill: none;
    vertical-align: middle;
    pointer-events: none;
}
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* Icon-only buttons (used in card actions) */
.btn-icon {
    background: none;
    border: 1px solid transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--fg); border-color: var(--border); }
.btn-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-icon.danger:hover { color: var(--warn); border-color: rgba(249, 117, 131, 0.4); background: rgba(249, 117, 131, 0.10); }
.diagram-card-shared { border-style: dashed; }
.card-share-dot {
    display: inline-flex; align-items: center; vertical-align: middle;
    color: var(--accent); opacity: 0.7; margin-left: 4px;
}
.share-perm-badge {
    background: var(--bg-elev, #1c242e);
    color: var(--accent, #88c0d0);
    padding: 1px 6px; border-radius: 3px;
    font-family: monospace; font-size: 0.85em;
}
.section-title {
    font-size: 0.95rem; color: var(--muted, #8fbcbb);
    text-transform: uppercase; letter-spacing: 0.05em;
    margin: 1.5rem 0 0.5rem;
}
.empty-state { text-align: center; padding: 2rem; color: var(--muted); }

/* Share modal (shared by dashboard + editor) */
.modal-wide .modal-box { min-width: 560px; max-width: 720px; max-height: 80vh; overflow: auto; }
.share-add { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.share-add input[type=email] {
    flex: 1; padding: 6px 8px; background: var(--bg-input, #0b0f14);
    border: 1px solid var(--border, #3a4551); color: var(--text, #d8dee9);
    border-radius: 3px; font-family: inherit; font-size: 13px;
}
.share-add select {
    padding: 6px 8px; background: var(--bg-elev, #1c242e); color: var(--text, #d8dee9);
    border: 1px solid var(--border, #3a4551); border-radius: 3px; font-size: 12px;
}
.share-add button {
    background: var(--accent, #5e81ac); border: 1px solid var(--accent, #5e81ac);
    color: var(--text-strong, #eceff4);
    padding: 6px 12px; font-size: 12px; border-radius: 3px; cursor: pointer;
}
#dashShareError { min-height: 16px; font-size: 12px; color: #bf616a; }
.share-list {
    max-height: 320px; overflow: auto;
    border: 1px solid var(--border, #2a3441); border-radius: 4px;
    background: var(--bg-input, #0f1419); margin-top: 8px;
}
.share-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-bottom: 1px solid var(--border, #1c242e);
    font-size: 12px;
}
.share-row:last-child { border-bottom: none; }
.share-row .share-user { flex: 1; color: var(--text, #d8dee9); }
.share-row .share-perm {
    color: var(--accent, #88c0d0); font-family: monospace;
    padding: 2px 6px; border-radius: 3px;
    background: var(--bg-elev, #1c242e); border: 1px solid var(--border, #2a3441);
}
.share-row button {
    background: rgba(191, 97, 106, 0.15); border: 1px solid #bf616a;
    color: #bf616a; padding: 3px 8px; font-size: 11px;
    border-radius: 3px; cursor: pointer;
}
.share-row button:hover { background: rgba(191, 97, 106, 0.30); }
.share-row.disabled { opacity: 0.55; }
.share-empty { padding: 18px; text-align: center; color: var(--muted, #6f7a88); font-size: 12px; }
.muted-small { font-size: 11px; color: var(--muted, #6f7a88); margin: 0 0 8px; }

/* Token management UI */
.token-new { border-color: var(--accent, #88c0d0); }
.token-plaintext {
    display: flex; gap: 8px; align-items: center;
    margin: 8px 0; padding: 10px;
    background: var(--bg-input, #0b0f14);
    border: 1px solid var(--border, #2a3441);
    border-radius: 4px;
}
.token-plaintext code {
    flex: 1; font-family: monospace; font-size: 13px;
    color: var(--accent, #88c0d0); word-break: break-all;
}
.config-snippet {
    background: var(--bg-input, #0b0f14);
    border: 1px solid var(--border, #2a3441);
    border-radius: 4px; padding: 12px;
    font-family: monospace; font-size: 12px;
    overflow-x: auto;
    color: var(--text, #d8dee9);
}
.token-table {
    width: 100%; border-collapse: collapse; font-size: 13px;
}
.token-table th, .token-table td {
    padding: 6px 10px; text-align: left;
    border-bottom: 1px solid var(--border, #2a3441);
}
.token-table th { color: var(--muted, #8fbcbb); font-weight: 600; }
.token-table code { font-family: monospace; font-size: 11px; color: var(--accent, #88c0d0); }
.btn-link.danger { color: #bf616a; background: none; border: none; cursor: pointer; padding: 2px 6px; }
.btn-link.danger:hover { background: rgba(191, 97, 106, 0.15); }
.form-inline {
    display: flex; gap: 8px; align-items: center;
}
.form-inline input[type=text] {
    flex: 1; padding: 6px 8px; background: var(--bg-input, #0b0f14);
    border: 1px solid var(--border, #3a4551); color: var(--text, #d8dee9);
    border-radius: 3px; font-size: 13px;
}

/* Modal (generic, used by dashboard) */
.modal.hidden { display: none; }
.modal {
    position: fixed; inset: 0; z-index: 500;
    display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.6);
}
.modal-box {
    position: relative; z-index: 1;
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: 6px; padding: 20px;
    min-width: 440px; max-width: 540px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}
.modal-box h2 { margin: 0 0 14px; font-size: 1rem; color: var(--accent); font-weight: 600; }
.modal-box .field { display: block; margin-bottom: 12px; font-size: 0.9rem; color: var(--fg); }
.modal-box .field > span { display: block; margin-bottom: 4px; }
.modal-box .field > span small { color: var(--muted); font-weight: normal; }
/* Inline checkbox row (label + checkbox on one line), e.g. subgraph "Collapsible". */
.modal-box .field-check {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 12px; font-size: 0.9rem; color: var(--fg); cursor: pointer;
}
.modal-box .field-check input { width: auto; margin: 0; }
.modal-box .field-check small { color: var(--muted); font-weight: normal; }
.modal-box input[type=text],
.modal-box select {
    width: 100%; padding: 6px 8px;
    background: var(--bg); color: var(--fg);
    border: 1px solid var(--border); border-radius: 3px; font-size: 0.9rem;
    font-family: inherit; appearance: none;
}
.modal-box input[type=text]:focus,
.modal-box select:focus { outline: none; border-color: var(--accent); }

/* Node-link picker (add/edit-node modal): pick a sibling diagram to link to. */
.node-link-control { position: relative; display: flex; gap: 6px; align-items: stretch; }
.node-link-picker {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; text-align: left; cursor: pointer;
    background: var(--bg); color: var(--fg);
    border: 1px solid var(--border); border-radius: 3px;
    font-size: 0.9rem; font-family: inherit;
}
.node-link-picker:hover, .node-link-picker.open { border-color: var(--accent); }
.node-link-picker .icon { width: 15px; height: 15px; flex: none; color: var(--muted); }
.node-link-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-link-text.placeholder { color: var(--muted); }
.node-link-caret {
    flex: none; width: 0; height: 0;
    border-left: 4px solid transparent; border-right: 4px solid transparent;
    border-top: 5px solid var(--muted);
}
.node-link-clear {
    flex: none; width: 32px; padding: 0; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg); color: var(--muted);
    border: 1px solid var(--border); border-radius: 3px;
}
.node-link-clear:hover { color: var(--fg); border-color: var(--accent); }
.node-link-clear .icon { width: 14px; height: 14px; }
.node-link-menu {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
    max-height: 220px; overflow-y: auto; padding: 4px;
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.node-link-menu-empty { padding: 8px; color: var(--muted); font-size: 0.85rem; text-align: center; }
.node-link-menu-item {
    display: flex; flex-direction: column; gap: 1px; align-items: flex-start;
    width: 100%; padding: 6px 8px; cursor: pointer; text-align: left;
    background: transparent; color: var(--fg);
    border: none; border-radius: 3px; font-family: inherit; font-size: 0.9rem;
}
.node-link-menu-item:hover, .node-link-menu-item.active { background: var(--bg-hover); }
.node-link-menu-item.active .node-link-menu-title { color: var(--accent); }
.node-link-menu-title { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-link-menu-slug { color: var(--muted); font-size: 0.78rem; }

.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.modal-buttons button {
    background: var(--bg-elev, #1c242e); color: var(--fg, #d8dee9);
    border: 1px solid var(--border, #3a4551); border-radius: 4px;
    padding: 6px 14px; font-size: 13px; font-family: inherit;
    cursor: pointer;
}
.modal-buttons button:hover { background: var(--bg-hover, #25303c); }
.modal-buttons button.primary {
    background: var(--accent, #5e81ac); border-color: var(--accent, #5e81ac);
    color: var(--text-strong, #eceff4);
}
.modal-buttons button.primary:hover {
    background: var(--accent-dark, #81a1c1); border-color: var(--accent-dark, #81a1c1);
}
.modal-buttons button.danger {
    background: rgba(191, 97, 106, 0.15); border-color: #bf616a; color: #bf616a;
}
.modal-buttons button.danger:hover { background: rgba(191, 97, 106, 0.30); }
.modal-info { font-size: 12px; color: var(--accent-soft, #8fbcbb); margin: 4px 0 8px; }
#newDiagramError, #renameError { min-height: 16px; font-size: 0.78em; color: var(--warn); margin-bottom: 4px; }
