:root {
  color-scheme: light;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-strong: #eef3f8;
  --border: #d7e0ea;
  --border-strong: #becad8;
  --text: #182230;
  --muted: #5d6b7c;
  --muted-2: #7f8c9b;
  --primary: #132033;
  --accent: #2f6fed;
  --accent-soft: #e9f0ff;
  --success: #18794e;
  --shadow: 0 18px 44px rgba(14, 23, 34, 0.08);
  --shadow-soft: 0 8px 24px rgba(14, 23, 34, 0.06);
  --overlay: rgba(17, 24, 39, 0.42);
  --table-hover: #f4f8ff;
  --table-active: #eaf1ff;
  --viewer-bg: #eef3f8;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1722;
  --surface: #121c28;
  --surface-soft: #182433;
  --surface-strong: #1d2a3a;
  --border: #29384b;
  --border-strong: #3a4d64;
  --text: #e6edf5;
  --muted: #9dafc2;
  --muted-2: #8495a8;
  --primary: #f7fafc;
  --accent: #8bb4ff;
  --accent-soft: #1c2f49;
  --success: #4ecb8d;
  --shadow: 0 22px 52px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.22);
  --overlay: rgba(3, 7, 18, 0.64);
  --table-hover: #162437;
  --table-active: #1b3151;
  --viewer-bg: #0d1621;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body.portal-body {
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(47, 111, 237, 0.06), transparent 28%), var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

.portal-shell {
  max-width: 1520px;
  margin: 0 auto;
  padding: 32px 32px 56px;
}

.login-body {
  display: flex;
  align-items: center;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.panel,
.summary-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
}

.section-kicker {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 22px;
}

.section-heading h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 650;
}

.section-heading p {
  margin: 0;
  max-width: 480px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 15px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 28px;
  margin-bottom: 32px;
}

.brand-wrap {
  display: flex;
  gap: 20px;
}

.brand-wrap-horizontal {
  align-items: flex-start;
}

.brand-logo {
  width: 172px;
  min-width: 172px;
  height: 60px;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text {
  min-width: 0;
  max-width: 600px;
}

.brand-text h1 {
  margin: 0 0 10px;
  font-size: 32px;
  font-weight: 650;
  line-height: 1;
  color: var(--primary);
}

.brand-text p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
  max-width: 58ch;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 240px;
}

.topbar-actions-auth {
  gap: 12px;
  flex-wrap: wrap;
}

.user-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 12px 15px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.user-pill {
  gap: 8px;
}

.user-pill-label {
  color: var(--muted);
}

.user-pill-value {
  font-weight: 600;
}

.top-filters-panel {
  padding: 26px 28px 22px;
  margin-bottom: 28px;
}

.top-filters-grid {
  display: grid;
  gap: 16px;
  align-items: end;
}

.top-filters-grid-portal {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.filter-field {
  min-width: 0;
}

.filter-field-search-wide {
  grid-column: span 2;
}

.filter-field label {
  display: block;
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.filter-field input,
.filter-field select {
  width: 100%;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.filter-field input::placeholder {
  color: var(--muted-2);
}

.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(183, 121, 60, 0.12);
  background: var(--surface);
}

.date-input-wrap input[type="date"]::-webkit-calendar-picker-indicator {
  opacity: 0.75;
  cursor: pointer;
}

.filter-presets {
  grid-column: span 3;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.preset-btn {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.preset-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.filter-actions-top {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: end;
  grid-column: span 2;
}

.filter-help {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.top-filter-help {
  margin: 16px 0 0;
}

.summary-panel {
  padding: 24px;
  margin-bottom: 28px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 16px;
}

.stat-card {
  min-height: 128px;
  background: linear-gradient(180deg, var(--surface), var(--surface-soft));
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}

.stat-icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stat-label {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.3;
}

.stat-value {
  color: var(--primary);
  font-weight: 650;
  font-size: 34px;
  line-height: 1.1;
  word-break: break-word;
}

.stat-value-small {
  font-size: 20px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(520px, 0.9fr);
  gap: 24px;
  align-items: start;
}

.workspace-grid.viewer-hidden {
  grid-template-columns: 1fr;
}

.register-panel,
.viewer-panel {
  padding: 26px;
  min-height: 760px;
}

.viewer-panel-hidden {
  display: none;
}

.register-head,
.viewer-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.register-head h3,
.viewer-panel-header h3 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 650;
  color: var(--primary);
}

.register-head p,
.viewer-panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.table-meta-chip {
  display: inline-flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-soft);
}

.status-message {
  min-height: 24px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 14px;
}

.table-wrap {
  width: 100%;
}

.table-wrap-vertical-only {
  max-height: 980px;
  overflow-y: auto;
  overflow-x: auto;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.doc-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.doc-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.doc-table th,
.doc-table td {
  text-align: left;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 14px;
  line-height: 1.45;
}

.doc-table tbody tr {
  transition: background 0.16s ease;
}

.doc-table tbody tr:hover {
  background: var(--table-hover);
}

.doc-table th {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.sort-btn:hover {
  color: var(--primary);
}

.sort-btn.active {
  color: var(--primary);
}

.sort-indicator::before {
  content: "↕";
  font-size: 13px;
  letter-spacing: 0;
  color: var(--muted-2);
}

.sort-btn.active[data-direction="asc"] .sort-indicator::before {
  content: "↑";
  color: var(--accent);
}

.sort-btn.active[data-direction="desc"] .sort-indicator::before {
  content: "↓";
  color: var(--accent);
}

.col-site {
  width: 12%;
}

.col-function {
  width: 18%;
}

.col-reference {
  width: 16%;
}

.col-client-ref {
  width: 18%;
}

.col-date {
  width: 14%;
}

.col-files {
  width: 14%;
}

.cell-function,
.cell-client-ref {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.cell-reference,
.cell-date {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.action-heading,
.action-cell {
  text-align: right;
}

.download-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: stretch;
}

.download-actions-row {
  flex-direction: row;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn,
.open-doc-btn,
.secondary-doc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease;
  text-decoration: none;
}

.primary-btn,
.open-doc-btn {
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
}

.secondary-btn,
.secondary-doc-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.primary-btn:hover,
.secondary-btn:hover,
.open-doc-btn:hover,
.secondary-doc-btn:hover {
  transform: translateY(-1px);
}

.secondary-btn:hover,
.secondary-doc-btn:hover {
  border-color: var(--accent);
  color: var(--primary);
}

.primary-btn:disabled,
.secondary-btn:disabled,
.open-doc-btn:disabled,
.secondary-doc-btn:disabled,
.login-btn:disabled {
  opacity: 1;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.primary-btn:disabled,
.login-btn:disabled {
  background: #b7c3d4;
  border-color: #b7c3d4;
  color: #f8fafc;
}

.secondary-btn:disabled,
.open-doc-btn:disabled,
.secondary-doc-btn:disabled {
  background: var(--surface-strong);
  border-color: var(--border-strong);
  color: var(--muted);
}

.icon-btn {
  padding-left: 14px;
  padding-right: 14px;
}

.open-doc-btn,
.secondary-doc-btn {
  min-height: 44px;
  min-width: 122px;
  white-space: nowrap;
}

.btn-icon {
  width: 16px;
  height: 16px;
  display: inline-grid;
  place-items: center;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.compact-action-btn {
  min-width: 0;
  white-space: nowrap;
  padding: 9px 12px;
  font-size: 12px;
}

.empty-state {
  padding: 36px 0;
  color: var(--muted);
  text-align: center;
}

.active-row {
  background: var(--table-active);
}

.file-missing {
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  display: block;
}

.viewer-reference-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.viewer-reference-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.viewer-reference-value {
  font-size: 16px;
  font-weight: 650;
  color: var(--primary);
}

.viewer-frame-wrap {
  position: relative;
  height: 100%;
  border-radius: 22px;
  overflow: hidden;
  background: var(--viewer-bg);
  border: 1px solid var(--border);
}

.viewer-frame-wrap-large {
  min-height: 920px;
  height: 920px;
}

#pdfViewerFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
}

.viewer-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, transparent), color-mix(in srgb, var(--bg) 96%, transparent));
}

.viewer-placeholder.hidden {
  display: none;
}

.viewer-placeholder-inner {
  max-width: 320px;
  text-align: center;
}

.viewer-placeholder-inner h4 {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 650;
}

.viewer-placeholder-inner p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.session-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--overlay);
  backdrop-filter: blur(4px);
}

.session-overlay.hidden {
  display: none;
}

.session-card {
  width: 100%;
  max-width: 460px;
  padding: 30px;
  text-align: center;
}

.session-card h2 {
  margin: 0 0 12px;
  font-size: 28px;
  font-weight: 650;
  color: var(--primary);
}

.session-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.session-actions {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 580px;
  padding: 34px;
  border-radius: 28px;
  background: linear-gradient(180deg, var(--surface), var(--surface-soft));
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 32px;
}

.login-brand-logo {
  width: 180px;
  min-width: 180px;
  height: 64px;
}

.login-brand-text h1 {
  margin: 0 0 10px;
  font-size: 30px;
  font-weight: 650;
}

.login-brand-text p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

.login-copy h2 {
  margin: 0 0 10px;
  font-size: 26px;
  font-weight: 650;
}

.login-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  margin-top: 28px;
}

.login-actions {
  margin-top: 24px;
}

.login-btn {
  min-width: 220px;
}

.login-footnote {
  margin-top: 18px;
  color: var(--muted-2);
  font-size: 14px;
  min-height: 20px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1440px) {
  .top-filters-grid-portal {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .filter-field-search-wide {
    grid-column: span 2;
  }

  .filter-presets {
    grid-column: span 2;
  }

  .filter-actions-top {
    grid-column: span 2;
  }

  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1320px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap-vertical-only {
    max-height: 720px;
  }

  .viewer-frame-wrap-large {
    min-height: 760px;
    height: 760px;
  }
}

@media (max-width: 980px) {
  .portal-shell {
    padding: 20px;
  }

  .topbar,
  .section-heading {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    min-width: 0;
    width: 100%;
    justify-content: flex-start;
  }

  .top-filters-grid-portal {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-field-search-wide,
  .filter-presets,
  .filter-actions-top {
    grid-column: span 2;
  }

  .login-brand {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 760px) {
  .brand-wrap-horizontal {
    flex-direction: column;
    align-items: flex-start;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-filters-grid-portal {
    grid-template-columns: 1fr;
  }

  .filter-field-search-wide,
  .filter-presets,
  .filter-actions-top {
    grid-column: span 1;
  }

  .filter-actions-top {
    flex-direction: column;
    width: 100%;
  }

  .register-panel,
  .viewer-panel {
    min-height: auto;
    padding: 20px;
  }

  .table-wrap-vertical-only {
    max-height: none;
  }

  .doc-table th,
  .doc-table td {
    padding: 12px 10px;
    font-size: 12px;
  }

  .download-actions-row {
    flex-direction: column;
  }

  .viewer-frame-wrap-large {
    min-height: 520px;
    height: 520px;
  }

  .login-card {
    padding: 24px;
  }
}

@media (max-width: 520px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .open-doc-btn,
  .secondary-doc-btn,
  .primary-btn,
  .secondary-btn,
  .login-btn {
    width: 100%;
  }
}

.theme-toggle {
  min-width: 128px;
}

.theme-toggle .theme-toggle-label {
  pointer-events: none;
}

.theme-toggle::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.16;
  box-shadow: inset 0 0 0 5px color-mix(in srgb, currentColor 32%, transparent);
}

.secondary-btn.theme-toggle:hover {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .brand-logo img {
  filter: brightness(0.95) contrast(1.05);
}

:root[data-theme="dark"] .doc-table thead th,
:root[data-theme="dark"] .table-wrap-vertical-only,
:root[data-theme="dark"] .viewer-reference-bar,
:root[data-theme="dark"] .user-pill,
:root[data-theme="dark"] .status-pill {
  background: var(--surface-soft);
}

:root[data-theme="dark"] .secondary-btn,
:root[data-theme="dark"] .secondary-doc-btn {
  background: #18283a;
  border-color: #34506d;
  color: #eaf2ff;
}

:root[data-theme="dark"] .secondary-btn:hover,
:root[data-theme="dark"] .secondary-doc-btn:hover {
  background: #1d3148;
  border-color: #6fa4ff;
  color: #ffffff;
}

:root[data-theme="dark"] .primary-btn,
:root[data-theme="dark"] .open-doc-btn,
:root[data-theme="dark"] .login-btn {
  background: #dbe8ff;
  border-color: #dbe8ff;
  color: #102033;
}

:root[data-theme="dark"] .primary-btn:hover,
:root[data-theme="dark"] .open-doc-btn:hover,
:root[data-theme="dark"] .login-btn:hover {
  background: #ffffff;
  border-color: #ffffff;
  color: #0f1d2e;
}

:root[data-theme="dark"] .primary-btn:disabled,
:root[data-theme="dark"] .login-btn:disabled {
  background: #6b7c92;
  border-color: #6b7c92;
  color: #eef4fb;
}

:root[data-theme="dark"] .secondary-btn:disabled,
:root[data-theme="dark"] .open-doc-btn:disabled,
:root[data-theme="dark"] .secondary-doc-btn:disabled {
  background: #223142;
  border-color: #31485f;
  color: #93a4b8;
}

:root[data-theme="dark"] #pdfViewerFrame {
  background: #0f1722;
}

@media (max-width: 760px) {
  .theme-toggle {
    width: 100%;
  }
}


.file-missing {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
}

:root[data-theme="dark"] .file-missing {
  color: #9fb1c6;
}


/* Remove empty helper copy blocks after the hint text was deleted. */
.filters-copy p:empty,
.filter-note:empty,
.table-meta-chip:empty {
  display: none;
}


/* Keeps the filter intro block balanced after removing the large heading. */
.filter-copy h2:empty {
  display: none;
}


/* Clean up empty descriptive text blocks removed from the login/admin pages. */
.login-brand-text p:empty,
.login-copy p:empty,
.brand-text p:empty {
  display: none;
}
