:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1a2332;
  --muted: #667085;
  --line: #e3e8ef;
  --brand: #0b5cad;
  --brand-dark: #084681;
  --brand-soft: #e8f1fb;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

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

a { color: var(--brand); }

/* ---- Header / search ------------------------------------------------------ */
header.topbar {
  background: var(--brand);
  color: #fff;
  padding: 18px 24px;
  box-shadow: var(--shadow);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.brand .brand-sub { opacity: 0.75; font-weight: 400; }
.brand-logo { height: 48px; width: auto; display: block; vertical-align: middle; }

.search {
  display: flex;
  flex: 1;
  min-width: 320px;
  gap: 8px;
  align-items: stretch;
  position: relative;
}

/* Document-search results dropdown */
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 50;
}
.sr-head {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.sr-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--brand-soft); }
.sr-title { font-size: 14px; font-weight: 600; }
.sr-folder {
  font-size: 11.5px; font-weight: 600; color: var(--brand-dark);
  background: var(--brand-soft); border-radius: 999px; padding: 2px 8px; margin-left: 6px;
}
.sr-snippet { font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.sr-snippet mark, .search-results mark { background: #ffe89e; color: inherit; padding: 0 1px; border-radius: 2px; }

.search input {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 15px;
  color: var(--ink);
  outline: none;
}

.nav-link {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid rgba(255,255,255,0.5);
  padding: 9px 14px;
  border-radius: 8px;
  white-space: nowrap;
}
.nav-link:hover { background: rgba(255,255,255,0.12); }

/* ---- Layout --------------------------------------------------------------- */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  font-weight: 700;
  margin: 8px 0 14px;
}

/* ---- Trusted resources ---------------------------------------------------- */
.trusted {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-bottom: 32px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border: 1px solid #cfe1f5;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
}
.chip:hover { background: #dcebfb; }

.pdf-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  font-size: 14.5px;
}
.pdf-link:last-child { border-bottom: none; }
.pdf-link:hover { color: var(--brand); }
.pdf-badge {
  background: #fdecea; color: var(--danger);
  font-size: 11px; font-weight: 700;
  padding: 3px 7px; border-radius: 5px;
}

/* ---- Folders / tiles ------------------------------------------------------ */
.folder { margin-bottom: 30px; }
.folder-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.folder-head h3 { margin: 0; font-size: 17px; }
.folder-count { color: var(--muted); font-size: 13px; margin-left: auto; }
.folder-empty { color: var(--muted); font-size: 14px; padding: 4px 0 2px; }

/* Pinned folder (Processes) */
.folder.pinned {
  background: #fff8ec;
  border: 1px solid #f0d9a8;
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.pin-badge {
  background: #fbe7bf; color: #8a5a00;
  font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.folder.unsorted {
  background: #eef1f4;
  border: 1px dashed #c4d0de;
  border-radius: 12px;
  padding: 16px 18px;
}
.pin-badge.unsorted-badge { background: #dde5ee; color: #4a6076; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex;
  flex-direction: column;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16,24,40,0.12); }

.tile-preview {
  height: 118px;
  background: #f0f3f7;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tile-preview img { width: 100%; height: 100%; object-fit: cover; }
.tile-preview.has-thumb { background: #fff; align-items: flex-start; }
.tile-preview canvas {
  width: 100%; height: 100%;
  object-fit: cover; object-position: top;
}
.tile-icon { font-size: 40px; }

.tile-body { padding: 10px 12px; }
.tile-name {
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-meta {
  font-size: 11.5px; color: var(--muted);
  display: flex; justify-content: space-between; margin-top: 3px;
}
.kind-tag {
  text-transform: uppercase; font-weight: 700; letter-spacing: 0.4px;
}
.kind-pdf { color: var(--danger); }
.kind-image { color: #7a5cc0; }
.kind-audio { color: #b06a00; }
.kind-video { color: #0b7a3b; }

.empty {
  text-align: center; color: var(--muted);
  padding: 50px 20px; font-size: 15px;
}

/* ---- Modal viewer --------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 18, 30, 0.72);
  display: none; align-items: center; justify-content: center;
  padding: 30px; z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: 14px;
  max-width: 92vw; max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 16px;
}
.modal-head strong { font-size: 15px; }
.modal-actions { display: flex; gap: 8px; }
.modal-actions a, .modal-close {
  border: 1px solid var(--line); background: #fff;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none; color: var(--ink);
}
.modal-close:hover, .modal-actions a:hover { background: #f4f6f9; }
.modal-body {
  padding: 12px; overflow: auto;
  display: flex; align-items: center; justify-content: center;
  background: #1b2430;
}
.modal-body img { max-width: 86vw; max-height: 78vh; }
.modal-body video { max-width: 86vw; max-height: 78vh; }
.modal-body iframe { width: 86vw; height: 78vh; border: none; background: #fff; }
.modal-body audio { width: 60vw; }

/* ---- Admin panel ---------------------------------------------------------- */
.admin-grid {
  display: grid; grid-template-columns: 340px 1fr; gap: 24px;
}
@media (max-width: 820px) { .admin-grid { grid-template-columns: 1fr; } }

/* Admin tabs */
.tabs {
  display: flex; flex-wrap: wrap; gap: 4px;
  border-bottom: 1px solid var(--line); margin-bottom: 24px;
}
.tab {
  border: none; background: none; cursor: pointer;
  padding: 11px 16px; font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 720px) { .panel-grid { grid-template-columns: 1fr; } }

/* Watermark check result */
.wm-result { margin-top: 16px; }
.wm-box { border-radius: 10px; padding: 16px 18px; font-size: 14px; }
.wm-none { background: #fdf0ee; border: 1px solid #f3ccc6; color: #8a3227; }
.wm-found { background: #eef7f0; border: 1px solid #bfe3c8; }
.wm-title { font-size: 15px; font-weight: 700; color: #1f7a3d; margin-bottom: 12px; }
.wm-src { font-weight: 500; color: var(--muted); font-size: 12.5px; }
.wm-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 6px 0; border-top: 1px solid #d7ebdd; font-size: 13.5px;
}
.wm-row span { color: var(--muted); }
.wm-row strong { text-align: right; word-break: break-word; }
.wm-raw {
  margin-top: 12px; padding: 8px 10px; background: #fff; border: 1px solid var(--line);
  border-radius: 6px; font-family: monospace; font-size: 11.5px; color: var(--muted); word-break: break-all;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--brand); }

.btn {
  border: none; border-radius: 8px; padding: 10px 16px;
  font-size: 14px; font-weight: 600; color: #fff; background: var(--brand);
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.danger { background: var(--danger); }

.dropzone {
  border: 2px dashed #c4d0de; border-radius: 12px;
  padding: 26px; text-align: center; color: var(--muted);
  background: var(--panel); cursor: pointer; transition: 0.15s;
}
.dropzone.drag { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }

.filelist { margin-top: 10px; font-size: 13px; color: var(--muted); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 200;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }

.admin-folder {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px; margin-bottom: 12px; background: var(--panel);
}
.admin-folder-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.admin-folder-head h4 { margin: 0; font-size: 15px; }
.admin-folder.pinned { background: #fff8ec; border-color: #f0d9a8; }
.admin-file {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-top: 1px solid var(--line); font-size: 13.5px; gap: 12px;
}
.folder-ctrls, .file-ctrls { display: flex; gap: 12px; white-space: nowrap; }
.link-del { color: var(--danger); cursor: pointer; font-size: 12px; font-weight: 600; }
.link-act { color: var(--brand); cursor: pointer; font-size: 12px; font-weight: 600; }
.link-act:hover, .link-del:hover { text-decoration: underline; }

/* Access whitelist editor */
@media (max-width: 640px) { .access-cols { grid-template-columns: 1fr !important; } }
.email-list {
  display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0;
  min-height: 30px; align-content: flex-start;
}
.email-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--brand-soft); color: var(--brand-dark);
  border: 1px solid #cfe1f5; border-radius: 999px;
  padding: 4px 10px; font-size: 12.5px; font-weight: 600;
}
.email-x { cursor: pointer; color: var(--danger); font-size: 11px; }
.email-add { display: flex; gap: 6px; }
.email-add input {
  flex: 1; padding: 7px 10px; font-size: 13px; min-width: 0;
  border: 1px solid var(--line); border-radius: 8px; outline: none;
}
.email-add input:focus { border-color: var(--brand); }

/* Branding editor */
.brand-logo-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.logo-preview {
  height: 40px; width: auto; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; padding: 3px;
}
input[type="color"] {
  width: 46px; height: 38px; border: 1px solid var(--line);
  border-radius: 8px; padding: 2px; cursor: pointer; background: #fff;
}

/* Trusted-websites editor rows */
.link-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.link-row .link-label { flex: 0 0 38%; }
.link-row .link-url { flex: 1; }
.link-row input {
  padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; outline: none; min-width: 0;
}
.link-row input:focus { border-color: var(--brand); }
.link-row-del { font-size: 14px; padding: 0 4px; }
.muted { color: var(--muted); }

/* ---- Login page ----------------------------------------------------------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px 30px;
  width: 100%; max-width: 360px;
}
.login-error {
  color: var(--danger); font-size: 13.5px; font-weight: 600;
  min-height: 18px; margin: 4px 0 12px;
}
