:root {
  --ink: #1C2B39;
  --ink-soft: #4A5A6A;
  --ink-faint: #7B8896;
  --paper: #EEF1F4;
  --sheet: #FFFFFF;
  --line: #D6DCE2;
  --line-soft: #E8ECF0;
  --manila: #E4C57E;
  --manila-deep: #B8954A;
  --manila-wash: #FBF5E6;
  --focus: #2F6FD0;
  --red: #B42318;
  --amber: #A45F00;
  --blue: #2F5F9E;
  --green: #2E7D5B;
  --grey: #6B7785;
  --radius-sm: 4px;
  --radius: 6px;
  --font: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 30px; height: 30px; fill: var(--manila); stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.crumb { margin: 0; color: var(--ink-faint); font-size: 13px; }
.account { display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--ink-soft); font-size: 13px; }
.demo-badge { white-space: nowrap; background: var(--manila-wash); border: 1px solid var(--manila-deep); color: #6E5418; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--sheet); border-radius: var(--radius-sm);
  padding: 6px 12px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-faint); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2B3F52; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.icon { padding: 6px; display: inline-grid; place-items: center; background: transparent; }
.btn.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Sign-in */
.signin { display: grid; place-items: center; min-height: 70vh; padding: 24px; }
.signin-card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; max-width: 420px; }
.signin-card h2 { margin: 0 0 8px; font-size: 20px; }
.signin-card p { color: var(--ink-soft); margin: 0 0 20px; }
.error { color: var(--red); margin-top: 12px !important; }

/* App frame */
.app { padding: 0 28px 28px; }

/* Folder tabs — the one distinctive element */
.tabs {
  display: flex; gap: 2px; align-items: flex-end; overflow-x: auto;
  padding: 0 4px; margin-bottom: -1px; position: relative; z-index: 1;
  scrollbar-width: thin;
}
.tab {
  position: relative; border: 1px solid var(--line); border-bottom: none;
  background: #E3E8ED; color: var(--ink-soft);
  padding: 8px 18px 7px 14px; border-radius: 8px 14px 0 0;
  cursor: pointer; display: flex; align-items: baseline; gap: 8px; white-space: nowrap;
  font-weight: 500; transition: background .12s;
}
.tab:hover { background: #EDF0F3; }
.tab .swatch { width: 8px; height: 8px; border-radius: 2px; align-self: center; }
.tab .count { font-variant-numeric: tabular-nums; color: var(--ink-faint); font-size: 12px; }
.tab[aria-selected="true"] {
  background: var(--manila); border-color: var(--manila-deep); color: var(--ink);
  font-weight: 600; padding-top: 11px;
}
.tab[aria-selected="true"] .count { color: #5E4816; }

.sheet {
  background: var(--sheet); border: 1px solid var(--line); border-top: 4px solid var(--manila);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  position: relative;
}

/* Toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft); position: relative;
}
.search { position: relative; flex: 1 1 260px; max-width: 380px; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--ink-faint); stroke-width: 1.8; }
.search input { width: 100%; padding: 7px 10px 7px 32px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.field-inline { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 13px; }
.field-inline select, .extra-filters select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; max-width: 220px;
}
.extra-filters { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 6px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.check { display: flex; gap: 6px; align-items: center; color: var(--ink-soft); font-size: 13px; margin-right: 6px; cursor: pointer; }

.columns-menu {
  position: absolute; right: 16px; top: calc(100% - 6px); z-index: 20;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
  box-shadow: 0 8px 24px rgba(28, 43, 57, .14); max-height: 360px; overflow: auto; min-width: 220px;
}
.columns-menu label { display: flex; gap: 8px; padding: 5px 6px; border-radius: 3px; cursor: pointer; }
.columns-menu label:hover { background: var(--paper); }

.summary { padding: 10px 16px; color: var(--ink-faint); font-size: 13px; border-bottom: 1px solid var(--line-soft); }

/* Register table */
.table-wrap { overflow: auto; position: relative; min-height: 200px; max-height: calc(100vh - 250px); }
.register { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.register th {
  position: sticky; top: 0; background: #F7F8FA; z-index: 2;
  text-align: left; font-weight: 600; font-size: 12.5px; color: var(--ink-soft);
  padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none;
}
.register th[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
.register th[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
.register td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; max-width: 320px; min-width: 110px; }
.register td.loc { min-width: 190px; font-size: 13px; }
.register tbody tr { cursor: pointer; }
.register tbody tr:hover { background: #F6F8FA; }
.register tbody tr.selected { background: var(--manila-wash); box-shadow: inset 3px 0 0 var(--manila-deep); }
.register tbody tr.is-folder td.name { font-weight: 600; }
.name-cell { display: flex; gap: 9px; align-items: flex-start; min-width: 240px; }
.name-cell .ico { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.name-cell .ico.folder { fill: var(--manila); stroke: var(--manila-deep); stroke-width: 1.3; }
.name-cell .ico.file { fill: #fff; stroke: var(--ink-faint); stroke-width: 1.3; }
.name-cell .sub { display: block; color: var(--ink-faint); font-size: 12px; font-weight: 400; margin-top: 1px; }
.cell-muted { color: var(--ink-faint); }
.cell-clip { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px 1px 7px; border-radius: 3px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap; border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 8%, white);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 1px; background: currentColor; }
.tone-red { color: var(--red); }
.tone-amber { color: var(--amber); }
.tone-blue { color: var(--blue); }
.tone-green { color: var(--green); }
.tone-grey { color: var(--grey); }
.bool-yes { color: var(--green); font-weight: 600; }

.empty, .loading { padding: 48px 24px; text-align: center; color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* Drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw);
  background: #fff; border-left: 1px solid var(--line); z-index: 40;
  transform: translateX(100%); transition: transform .18s ease-out;
  display: flex; flex-direction: column; overflow-y: auto;
  box-shadow: -12px 0 32px rgba(28, 43, 57, .10);
}
.drawer.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(28, 43, 57, .18); z-index: 30; }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 20px 20px 12px; border-top: 4px solid var(--manila); }
.drawer-kind { margin: 0; color: var(--ink-faint); font-size: 12.5px; }
.drawer-head h2 { margin: 2px 0 2px; font-size: 18px; line-height: 1.3; word-break: break-word; }
.drawer-path { margin: 0; color: var(--ink-faint); font-size: 12.5px; word-break: break-word; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 20px 14px; border-bottom: 1px solid var(--line-soft); }
.drawer-actions a.btn { text-decoration: none; }
.preview { height: 380px; border-bottom: 1px solid var(--line-soft); background: var(--paper); }
.preview iframe { width: 100%; height: 100%; border: 0; }
.preview p { padding: 20px; color: var(--ink-soft); margin: 0; }

.meta-form { padding: 16px 20px; display: grid; gap: 14px; }
.meta-form h3 { margin: 0; font-size: 14px; }
.meta-form .f { display: grid; gap: 4px; }
.meta-form .f > span { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); }
.meta-form .f > span .req { color: var(--red); }
.meta-form .f small { color: var(--ink-faint); font-size: 12px; }
.meta-form input[type=text], .meta-form input[type=number], .meta-form input[type=date],
.meta-form input[type=datetime-local], .meta-form select, .meta-form textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff;
}
.meta-form textarea { min-height: 84px; resize: vertical; }
.meta-form .f.dirty input, .meta-form .f.dirty select, .meta-form .f.dirty textarea, .meta-form .f.dirty .multi { border-color: var(--manila-deep); background: var(--manila-wash); }
.meta-form .multi { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 2px; border: 1px solid transparent; border-radius: var(--radius-sm); }
.meta-form .multi label { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.meta-form .readonly { padding: 7px 0; color: var(--ink-soft); }
.form-foot { display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; background: #fff; padding: 12px 0 4px; border-top: 1px solid var(--line-soft); }
.audit { margin: 0; padding: 4px 20px 24px; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.audit dt { color: var(--ink-faint); }
.audit dd { margin: 0; }

/* Dropzone */
.dropzone {
  position: fixed; inset: 12px; z-index: 60; border: 3px dashed var(--manila-deep); border-radius: 12px;
  background: rgba(251, 245, 230, .94); display: grid; place-items: center; font-size: 18px;
}

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(440px, 92vw); }
dialog::backdrop { background: rgba(28, 43, 57, .25); }
dialog h3 { margin: 0 0 14px; }
dialog label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; }
dialog input { padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-weight: 400; }
dialog .hint { color: var(--ink-faint); font-size: 12.5px; margin: 8px 0 0; }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }

/* Toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 70; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 520px; }
.toast.err { background: var(--red); }

@media (max-width: 760px) {
  .topbar { padding: 14px 14px 10px; }
  .app { padding: 0 8px 16px; }
  .toolbar-actions { margin-left: 0; }
  .user-name { display: none; }
  .table-wrap { max-height: none; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer, .tab { transition: none; }
}
