:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #dde3e9;
  --brand: #1f5f8b;
  --brand-dark: #174a6e;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --ok: #1e7d4f;
  --ok-bg: #e8f5ee;
  --info-bg: #e8f0fa;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar ------------------------------------------------------------------ */
.topbar { background: var(--brand); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 24px; min-height: 56px;
}
.brand { display: flex; align-items: center; }
.brand img { height: 30px; width: auto; display: block; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: #dbe7f0; padding: 6px 12px; border-radius: 6px; font-size: .95rem;
}
.nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.nav a.active { background: var(--brand-dark); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.who { color: #dbe7f0; font-size: .9rem; }
.link-btn {
  background: none; border: 1px solid rgba(255,255,255,.4); color: #fff;
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: .85rem;
}
.link-btn:hover { background: rgba(255,255,255,.15); }

/* Layout ------------------------------------------------------------------- */
.container { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 30px 0; }

h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.subtitle { color: var(--muted); margin: 0 0 18px; }

/* Panels & cards ----------------------------------------------------------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.panel h2 { margin-top: 0; }

/* Flash -------------------------------------------------------------------- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: .92rem; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--info-bg); color: var(--brand-dark); }

/* Tables ------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

/* Folder groups (admin Files) ---------------------------------------------- */
.folder-group { margin-bottom: 22px; }
.folder-group:last-child { margin-bottom: 0; }
.folder-group-head {
  display: flex; align-items: center; gap: 4px; color: var(--brand-dark);
  font-size: 1rem; margin: 0 0 8px; padding-bottom: 8px; border-bottom: 2px solid var(--line);
}
/* Each folder group is its own <table>, so by default every table auto-sizes its columns to its
   own rows — making the Type/Updated columns and the action buttons land at different x positions
   per group. Pin identical column widths (Title takes the remainder) so every group lines up. */
.folder-group table { table-layout: fixed; }
.folder-group th:nth-child(2), .folder-group td:nth-child(2) { width: 84px; }   /* Type */
.folder-group th:nth-child(3), .folder-group td:nth-child(3) { width: 200px; }  /* Updated */
.folder-group th:nth-child(4), .folder-group td:nth-child(4) { width: 256px; }  /* Actions */
.folder-group td:first-child { overflow-wrap: anywhere; }
.folder-group td.actions { justify-content: flex-end; }

/* Forms -------------------------------------------------------------------- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=email], input[type=datetime-local], input[type=search], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; background: #fff; color: var(--ink);
}
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 200px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label {
  display: inline-flex; align-items: center; gap: 6px; font-weight: 400; color: var(--ink);
  border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; margin: 0; cursor: pointer;
}
.checks input { width: auto; }

/* Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-block; background: var(--brand); color: #fff; border: none;
  padding: 9px 16px; border-radius: 6px; cursor: pointer; font: inherit; font-size: .92rem;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn-secondary { background: #eef2f6; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #e2e8ee; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f1d17; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* Badges/pills ------------------------------------------------------------- */
.pill { display: inline-block; background: #eef2f6; border: 1px solid var(--line); color: var(--muted); border-radius: 20px; padding: 2px 9px; font-size: .78rem; margin: 2px 2px 0 0; }
.status { font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 20px; }
.status-active { background: var(--ok-bg); color: var(--ok); }
.status-revoked { background: var(--danger-bg); color: var(--danger); }
.status-expired { background: #fff4e5; color: #9a5b00; }

.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 30px; text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* Auth / centered cards ---------------------------------------------------- */
.center-card { max-width: 380px; margin: 8vh auto; }
.login-logo { display: block; width: 240px; max-width: 80%; height: auto; margin: 0 auto 22px; }

/* Document viewer ---------------------------------------------------------- */
.doc-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.doc-text { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; white-space: pre-wrap; word-wrap: break-word; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9rem; max-height: 78vh; overflow: auto; }

/* Link reveal box ---------------------------------------------------------- */
.link-box { display: flex; gap: 8px; margin: 12px 0; }
.link-box input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

/* Search ------------------------------------------------------------------- */
.search-form { display: flex; gap: 8px; margin-bottom: 20px; }
.search-form input { flex: 1; }
.result { border-bottom: 1px solid var(--line); padding: 14px 0; }
.result:last-child { border-bottom: none; }
.result h3 { margin: 0 0 4px; font-size: 1.02rem; }
.result .snippet { color: var(--muted); font-size: .9rem; }
.result mark { background: #fff3b0; padding: 0 2px; }
.result-count { margin: 0 0 14px; }

/* Live-search indicator (HTMX toggles .htmx-request on the indicator during a request). */
.htmx-indicator { opacity: 0; transition: opacity 150ms ease-in; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }

/* Doc grid ----------------------------------------------------------------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.doc-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; }
.doc-card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.doc-card .desc { color: var(--muted); font-size: .88rem; flex: 1; margin-bottom: 12px; }
.doc-card .snippet-section { color: var(--brand); font-size: .8rem; font-weight: 600; margin-bottom: 6px; }
.doc-card .snippet { display: block; flex: 1; color: var(--muted); font-size: .85rem; margin-bottom: 12px; text-decoration: none; border-left: 3px solid var(--line); padding-left: 10px; transition: border-color .12s ease, color .12s ease; }
.doc-card a.snippet:hover { border-left-color: var(--brand); color: var(--ink, #222); }
.doc-card .snippet mark { background: #fff3b0; padding: 0 2px; }
.filetype { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--brand); font-weight: 700; }

/* "The Boss" talking avatar --------------------------------------------------- */
.boss-avatar { position: fixed; left: 18px; bottom: 18px; z-index: 1000; width: 112px; }
.boss-bubble { position: absolute; bottom: 100%; left: 0; margin-bottom: 12px; width: max-content; max-width: 280px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 13px; font-size: .85rem; line-height: 1.35; color: var(--ink, #222); box-shadow: 0 6px 18px rgba(0,0,0,.18); cursor: pointer; opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 1.8s ease, transform 1.8s ease; }
.boss-bubble.show { opacity: 1; transform: translateY(0); pointer-events: auto; transition: opacity .5s ease, transform .5s ease; }
.boss-bubble::after { content: ''; position: absolute; left: 30px; bottom: -7px; width: 12px; height: 12px; background: #fff; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); }
.boss-face { border: none; padding: 0; background: none; cursor: pointer; display: block; }
.boss-face img { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; object-position: center top; display: block; border: 3px solid #fff; box-shadow: 0 4px 14px rgba(0,0,0,.28); transition: transform .12s ease; }
.boss-face:hover img { transform: scale(1.06); }

/* Dialog ------------------------------------------------------------------- */
dialog { border: none; border-radius: var(--radius); padding: 0; max-width: 560px; width: 92%; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.dialog-body { padding: 22px; }
.dialog-body h2 { margin-top: 0; }
