:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e5e8ee;
  --text: #1f2933;
  --muted: #7b8794;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eaf1ff;
  --success: #16a34a;
  --success-soft: #e7f6ec;
  --amber: #b25e09;
  --amber-soft: #fff4e5;
  --error: #d64545;
  --sidebar: #0f2747;
  --sidebar-text: #c9d6ea;
  --sidebar-active: #1d4ed8;
  /* File-type accents (#045) */
  --type-pdf: #d64545;       --type-pdf-soft: #fdeaea;
  --type-word: #2563eb;      --type-word-soft: #eaf1ff;
  --type-excel: #16a34a;     --type-excel-soft: #e7f6ec;
  --type-image: #7c3aed;     --type-image-soft: #f1e9fe;
  --type-archive: #b25e09;   --type-archive-soft: #fff4e5;
  --type-folder: #2563eb;    --type-folder-soft: #eaf1ff;
  --type-other: #64748b;     --type-other-soft: #eef1f6;
}

/* ---------- Web font: Inter, self-hosted (#045) ----------
   Self-hosted under web/static/fonts so it loads under our strict CSP
   (default-src 'self'); a Google Fonts CDN @import would be blocked. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/inter-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/inter-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/inter-latin-600-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin-700-normal.woff2") format("woff2");
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.006em;
}

/* ---------- Typographic scale (#045) ---------- */
h1, h2, h3 { letter-spacing: -0.02em; }

/* ---------- Login (standalone) ---------- */
body.centered {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d4ed8 0%, #0f2747 100%);
}
.login { width: 350px; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; color: var(--brand); }

/* ---------- App shell ---------- */
body.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7c97;
  padding: 16px 12px 6px;
}
.nav-link {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-link.logout { margin-top: auto; color: #f3b4b4; }
.nav-link.logout:hover { background: rgba(214,69,69,0.18); color: #fff; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 28px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.user { display: flex; align-items: center; gap: 10px; }

.nav-toggle { display: none; }
.nav-burger { display: none; cursor: pointer; color: var(--text); }

.content {
  padding: 28px;
  display: grid;
  gap: 22px;
  max-width: 1100px;
  width: 100%;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 24px;
  box-shadow: 0 1px 2px rgba(16,40,80,0.04);
}
.card h2 { margin-top: 0; font-size: 15px; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 22px;
}
.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-head { display: flex; align-items: center; gap: 10px; }
.stat-head h2 { margin: 0; }
.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
}
.stat-icon.blue { background: var(--brand-soft); color: var(--brand); }
.stat-icon.green { background: var(--success-soft); color: var(--success); }
.stat-icon.amber { background: var(--amber-soft); color: var(--amber); }
.stat-big { font-size: 26px; font-weight: 700; margin: 8px 0 2px; }
.stat-big .muted { font-size: 15px; font-weight: 400; }

.bar {
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin: 6px 0;
}
.bar-fill { height: 100%; background: var(--brand); border-radius: 99px; }

/* ---------- Forms & buttons ---------- */
label { display: grid; gap: 6px; font-size: 14px; }

input[type="text"], input[type="password"], input[type="file"], select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

button, .action-btn {
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .action-btn:hover { background: var(--brand-dark); }
button.secondary, .action-btn.secondary { background: #eef1f6; color: var(--text); }
button.secondary:hover, .action-btn.secondary:hover { background: #e2e7ef; }
button.danger { background: var(--error); }
button.danger:hover { background: #b83838; }

.form-row { display: flex; gap: 24px; flex-wrap: wrap; }
.upload-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stack-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.quick-actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: #fafbfd; }

td.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: flex; gap: 6px; align-items: center; margin: 0; }
.inline-form input[type="text"] { width: 130px; padding: 6px 8px; font-size: 13px; }
.inline-form input[type="password"] { width: 140px; padding: 6px 8px; font-size: 13px; }
.inline-form select { padding: 6px 8px; font-size: 13px; width: auto; }
.inline-form button { padding: 6px 10px; font-size: 13px; }

.ficon { color: var(--brand); vertical-align: middle; margin-right: 4px; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--error); font-size: 14px; margin: 0; }

.btn-link { color: var(--brand); text-decoration: none; font-size: 14px; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }

/* ---------- Document table polish (#035) ---------- */
.doc-table td { vertical-align: middle; }
.doc-table .col-actions { text-align: right; }

.name-cell { display: flex; align-items: center; gap: 10px; }
.name-cell .ficon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--type-other-soft);
  color: var(--type-other);
  flex: 0 0 auto;
  margin: 0;
}
/* Per file-type icon accents (#045). Class set by app.js from the extension. */
.ficon.type-pdf     { background: var(--type-pdf-soft);     color: var(--type-pdf); }
.ficon.type-word    { background: var(--type-word-soft);    color: var(--type-word); }
.ficon.type-excel   { background: var(--type-excel-soft);   color: var(--type-excel); }
.ficon.type-image   { background: var(--type-image-soft);   color: var(--type-image); }
.ficon.type-archive { background: var(--type-archive-soft); color: var(--type-archive); }
.ficon.type-folder  { background: var(--type-folder-soft);  color: var(--type-folder); }
.ficon.type-other   { background: var(--type-other-soft);   color: var(--type-other); }
.name-link { color: var(--text); text-decoration: none; font-weight: 500; }
.name-link:hover { color: var(--brand); text-decoration: underline; }
.name-text { color: var(--text); }

td.actions { justify-content: flex-end; gap: 4px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); border-color: var(--border); }
.icon-btn.danger { background: transparent; color: var(--muted); }
.icon-btn.danger:hover { background: #fdeaea; color: var(--error); border-color: #f3c2c2; }
.icon-btn.copy-link.copied { background: var(--success-soft); color: var(--success); }
.actions .inline-form { margin: 0; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 36px 0;
  color: var(--muted);
  font-size: 14px;
}
.empty-state svg { color: var(--border); }

/* ---------- Modals (#035) ---------- */
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 39, 71, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(16, 40, 80, 0.25);
  animation: modal-in 0.14s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal label { margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

button.copy-link { background: transparent; }

.badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
}
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 600;
}

.breadcrumb {
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.breadcrumb .sep { color: var(--muted); }

.flash {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
}
.flash.ok { background: var(--success-soft); color: #1c7a3f; border: 1px solid #b6e0c4; }
.flash.err { background: #fdeaea; color: #b22; border: 1px solid #f3c2c2; }

/* ---------- Toast notifications (#045) ---------- */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 15px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 8px 28px rgba(16, 40, 80, 0.16);
  font-size: 14px;
  color: var(--text);
  border-left: 4px solid var(--muted);
  animation: toast-in 0.18s ease-out;
}
.toast.hide { animation: toast-out 0.25s ease-in forwards; }
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--error); }
.toast-icon { flex: 0 0 auto; margin-top: 1px; }
.toast.ok .toast-icon { color: var(--success); }
.toast.err .toast-icon { color: var(--error); }
.toast-msg { flex: 1; }
.toast-close {
  flex: 0 0 auto;
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
}
.toast-close:hover { background: transparent; color: var(--text); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

.pager {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  body.app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 20;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .nav-toggle:checked ~ .sidebar { transform: translateX(0); }
  .nav-burger { display: inline-flex; }
  .content { padding: 18px; }
}
