/* ==========================================================================
   Document Manager — Pearl Insurance theme
   ========================================================================== */

:root {
  --navy:        #0A3D78;
  --navy-soft:   #134B8C;
  --navy-line:   #1F5A9E;
  --blue:        #2E86DE;
  --blue-dark:   #2169B3;
  --paper:       #F4F6F9;
  --paper-card:  #FFFFFF;
  --paper-line:  #E0E6ED;
  --text:        #1A2B3C;
  --text-muted:  #64748B;
  --green:       #2E9E5B;
  --red:         #D64545;
  --shadow:      0 1px 2px rgba(10,61,120,.06), 0 6px 16px rgba(10,61,120,.06);
  --shadow-lift: 0 4px 10px rgba(10,61,120,.10), 0 14px 28px rgba(10,61,120,.12);
  --radius:      8px;
  --radius-sm:   6px;
  --font-display:"Poppins","Inter",-apple-system,BlinkMacSystemFont,sans-serif;
  --font-body:   "Inter",-apple-system,BlinkMacSystemFont,sans-serif;
  --font-mono:   "JetBrains Mono","Courier New",monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--paper); color: var(--text);
  font-family: var(--font-body); font-size: 15px; line-height: 1.45;
}
[hidden] { display: none !important; }

button { font-family: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--navy); color: #D6E4F5;
  padding: 24px 16px 16px;
  display: flex; flex-direction: column; gap: 18px;
  max-height: 100vh; overflow-y: auto;
}

.sidebar__brand {
  padding: 0 6px 20px;
  border-bottom: 1px solid var(--navy-line);
  flex-shrink: 0;
}
.selected-file-name {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin: -6px 0 12px;
  min-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-optional {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 4px;
}

.sidebar__logo {
  width: 100%;
  max-width: 180px;
  height: auto;
  display: block;
}

.folder-nav {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}

.folder-nav__item {
  all: unset; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 9px 10px; border-radius: var(--radius-sm);
  cursor: pointer; color: #B9CFE8; font-size: 14px;
}
.folder-nav__item:hover { background: var(--navy-soft); color: #fff; }
.folder-nav__item.is-active { background: var(--blue); color: #fff; font-weight: 600; }
.folder-nav__item .count { font-family: var(--font-mono); font-size: 11px; opacity: .8; }

.folder-nav__divider {
  margin: 12px 0 2px; padding: 0 10px;
  font-weight: 600; font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: #7FA0C7;
}

.folder-tree { display: flex; flex-direction: column; gap: 1px; }
.folder-tree .folder-tree { margin-left: 14px; }

.folder-row { display: flex; align-items: center; border-radius: var(--radius-sm); padding-right: 4px; }
.folder-row:hover { background: var(--navy-soft); }
.folder-row.is-active { background: var(--blue); }
.folder-row.is-active .folder-row__name { color: #fff; font-weight: 600; }

.folder-row__name {
  all: unset; flex: 1; display: block; padding: 8px 0 8px 10px;
  color: #B9CFE8; font-size: 14px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.folder-row__ops { display: flex; gap: 2px; opacity: 0; transition: opacity .1s; }
.folder-row:hover .folder-row__ops { opacity: 1; }
.folder-row__ops button {
  all: unset; width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: #9DB9DC; cursor: pointer; font-size: 13px;
}
.folder-row__ops button:hover { background: rgba(255,255,255,.14); color: #fff; }

.btn {
  all: unset; display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; cursor: pointer; text-align: center; flex-shrink: 0;
}

.btn--ghost { border: 1.5px solid var(--navy-line); color: #D6E4F5; }
.btn--ghost:hover { background: var(--navy-soft); }
.btn--accent { background: var(--blue); color: #fff; }
.btn--accent:hover { background: var(--blue-dark); }

/* ── Main ────────────────────────────────────────────────────────────────── */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; padding: 26px 36px 18px;
  border-bottom: 1px solid var(--paper-line); background: var(--paper-card);
}
.topbar__title h2 {
  font-family: var(--font-display); font-weight: 700; font-size: 24px;
  margin: 0; color: var(--navy); letter-spacing: -.01em;
}
.topbar__subtitle { font-size: 12.5px; color: var(--text-muted); }
.topbar__actions { display: flex; align-items: center; gap: 12px; }

.search input {
  font-family: var(--font-body); font-size: 14px;
  border: 1.5px solid var(--paper-line); background: var(--paper-card);
  border-radius: 999px; padding: 9px 16px; width: 240px;
}
.search input:focus { border-color: var(--blue); }

.doc-grid {
  padding: 28px 36px 60px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px; align-content: start;
}

.empty-state { margin: 60px auto; color: var(--text-muted); font-size: 15px; }

/* ── Doc card ─────────────────────────────────────────────────────────────── */

.doc-card {
  background: var(--paper-card); border: 1px solid var(--paper-line);
  border-radius: var(--radius); padding: 16px 16px 14px; position: relative;
  box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s;
  border-top: 3px solid var(--blue);
}
.doc-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }

.doc-card__type-badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  margin-bottom: 8px;
}

/* Kept for public page */
.doc-card__stamp {
  position: absolute; top: 14px; right: 14px;
  background: #EAF2FC; color: var(--blue-dark);
  border-radius: 999px; padding: 3px 10px;
  font-weight: 600; font-size: 10.5px; letter-spacing: .02em;
  display: flex; align-items: center; gap: 5px;
}
.doc-card__version { border-left: 1px solid var(--blue); padding-left: 5px; opacity: .85; }

.doc-card__name {
  font-family: var(--font-display); font-weight: 600; font-size: 15.5px;
  margin: 4px 0 6px; line-height: 1.3; color: var(--navy);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-all;
}

.doc-card__issue {
  font-size: 12.5px; color: var(--text-muted);
  font-family: var(--font-mono); margin-bottom: 10px;
}

.doc-card__meta {
  margin: 0 0 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 4px;
}
.doc-card__meta div { display: flex; flex-direction: column; }
.doc-card__meta dt { font-size: 10px; letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted); }
.doc-card__meta dd { margin: 0; font-family: var(--font-mono); font-size: 12.5px; }

.doc-card__actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  border-top: 1px solid var(--paper-line); padding-top: 12px;
}
.doc-card__actions button,
.doc-card__actions a {
  all: unset; font-size: 12px; font-weight: 500; padding: 5px 10px;
  border-radius: 999px; cursor: pointer; color: var(--navy); border: 1px solid var(--paper-line);
}
.doc-card__actions button:hover,
.doc-card__actions a:hover { background: #EAF2FC; border-color: #C7DCF5; }
.doc-card__actions button.danger { color: var(--red); border-color: #F2C9C9; }
.doc-card__actions button.danger:hover { background: #FCEAEA; }

/* ── Public page ─────────────────────────────────────────────────────────── */

.doc-card__url {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 12px; padding: 8px 10px;
  background: var(--paper); border: 1px solid var(--paper-line); border-radius: var(--radius-sm);
}
.doc-card__url input {
  all: unset; flex: 1; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: text;
}
.doc-card__url button {
  all: unset; font-family: var(--font-body); font-weight: 600; font-size: 10.5px;
  letter-spacing: .02em; text-transform: uppercase;
  color: var(--blue-dark); cursor: pointer; padding: 3px 9px; border-radius: 999px; flex-shrink: 0;
}
.doc-card__url button:hover { background: #EAF2FC; }

.folder-tree--readonly .folder-row__ops { display: none; }
.folder-tree--readonly .folder-row__name { cursor: pointer; }

/* ── Modals ──────────────────────────────────────────────────────────────── */

.modal {
  position: fixed; inset: 0; background: rgba(10,30,56,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal[hidden] { display: none; }

.modal__panel {
  background: var(--paper-card); border-radius: 12px; padding: 26px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow-lift);
}
.modal--wide .modal__panel { max-width: 880px; height: 88vh; display: flex; flex-direction: column; }
.modal__panel--edit { max-width: 480px; }

.modal__panel h3 {
  font-family: var(--font-display); font-weight: 600;
  margin: 0 0 18px; font-size: 19px; color: var(--navy);
}

.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 12px; min-width: 0;
}
.modal__header h3 {
  margin: 0; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; min-width: 0;
}

.modal__hint { font-size: 13px; color: var(--text-muted); margin-top: -8px; margin-bottom: 14px; }

.field-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }

select, .text-input, input[type="file"], input[type="url"], input[type="text"] {
  width: 100%; font-family: var(--font-body); font-size: 14px;
  padding: 9px 12px; border: 1.5px solid var(--paper-line);
  border-radius: var(--radius-sm); background: #fff; margin-bottom: 14px;
}
select:focus, .text-input:focus,
input[type="url"]:focus, input[type="text"]:focus { border-color: var(--blue); outline: none; }

.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.date-row select { margin-bottom: 0; }

.dropzone {
  border: 1.5px dashed var(--paper-line); border-radius: var(--radius);
  padding: 26px 14px; text-align: center; color: var(--text-muted);
  font-size: 13.5px; cursor: pointer; margin-bottom: 12px;
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--blue); color: var(--blue-dark); background: #EAF2FC; }

.upload-list {
  list-style: none; margin: 0 0 6px; padding: 0;
  max-height: 160px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.upload-list li {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 13px; padding: 7px 10px; border-radius: var(--radius-sm); background: var(--paper);
}
.status-ok    { color: var(--green); font-family: var(--font-mono); font-size: 11px; }
.status-error { color: var(--red);   font-family: var(--font-mono); font-size: 11px; }

.modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

.icon-btn { all: unset; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text-muted); padding: 2px 6px; }
.icon-btn:hover { color: var(--text); }

.viewer-frame {
  flex: 1; width: 100%; border: 1px solid var(--paper-line);
  border-radius: var(--radius-sm); background: #525659;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */

.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 11px 22px;
  border-radius: 999px; font-size: 13.5px; box-shadow: var(--shadow-lift); z-index: 200;
}
.toast[hidden] { display: none; }
.toast.is-error { background: var(--red); }

/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { max-height: 50vh; padding: 18px 16px 14px; }
  .topbar { flex-direction: column; align-items: stretch; padding: 18px; }
  .search input { width: 100%; }
  .doc-grid { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .doc-card, .folder-row__ops { transition: none; }
}


/* ── Analytics ───────────────────────────────────────────────────────────── */

.range-tabs {
  display: flex;
  border: 1.5px solid var(--paper-line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--paper-card);
}

.range-tab {
  all: unset;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .12s, color .12s;
}
.range-tab:hover     { background: var(--paper); color: var(--text); }
.range-tab.is-active { background: var(--navy);  color: #fff; }

.analytics-body {
  padding: 28px 36px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--paper-card);
  border: 1px solid var(--paper-line);
  border-top: 3px solid var(--blue);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.stat-card__value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  color: var(--navy);
  line-height: 1.1;
  margin-bottom: 6px;
}

.stat-card__label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.analytics-card {
  background: var(--paper-card);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.analytics-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.analytics-card__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--navy);
  margin: 0 0 16px;
}
.analytics-card__header .analytics-card__title { margin: 0; }

.chart-wrap {
  width: 100%;
  min-height: 220px;
  display: flex;
  align-items: center;
}
.chart-wrap svg { display: block; }

.chart-legend {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}

.legend-swatch {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 2px;
  margin-right: 5px;
  flex-shrink: 0;
}

.an-loading {
  color: var(--text-muted);
  font-size: 14px;
  margin: auto;
  padding: 24px;
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.an-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.an-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 10px 10px 0;
  border-bottom: 1px solid var(--paper-line);
}

.an-table tbody tr:hover { background: var(--paper); }

.an-table tbody td {
  padding: 10px 10px 10px 0;
  border-bottom: 1px solid var(--paper-line);
  vertical-align: middle;
}
.an-table tbody tr:last-child td { border-bottom: none; }

.an-num {
  text-align: right !important;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  padding-right: 0 !important;
}

.an-doc-name {
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--navy);
  font-weight: 500;
}

.an-folder {
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.an-empty {
  color: var(--text-muted);
  font-style: italic;
  padding: 16px 0;
  text-align: center;
}

.an-table--wide .an-doc-name { max-width: none; }

.ref-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ref-label {
  font-size: 13.5px;
  color: var(--text);
  font-weight: 500;
}

.ref-bar-track {
  height: 6px;
  background: var(--paper);
  border-radius: 999px;
  overflow: hidden;
  width: 100%;
  max-width: 400px;
}

.ref-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 999px;
  transition: width .3s ease;
}

.ref-pct {
  color: var(--text-muted);
  font-size: 12px;
}

.folder-nav a.folder-nav__item {
  text-decoration: none;
  display: flex;
  align-items: center;
}

@media (max-width: 900px) {
  .stat-cards    { grid-template-columns: 1fr 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .analytics-body { padding: 18px; }
}