:root {
  color-scheme: light;
  --indigo: #21165f;
  --indigo-dark: #171044;
  --gold: #f5c400;
  --red: #c92a2a;
  --green: #16834a;
  --ink: #211f2b;
  --muted: #656274;
  --line: #e4e1eb;
  --paper: #fff;
  --surface: #f6f5f8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  font-family: "Segoe UI", Arial, sans-serif;
}

a { color: var(--indigo); }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, var(--indigo-dark), var(--indigo) 68%, #302274);
}

.auth-card {
  width: min(440px, 100%);
  padding: 38px;
  overflow: hidden;
  text-align: center;
  background: var(--paper);
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 6px;
  box-shadow: 0 24px 70px rgba(8, 5, 37, .3);
}

.auth-card::before {
  content: "";
  display: block;
  height: 6px;
  margin: -38px -38px 30px;
  background: linear-gradient(90deg, var(--red) 0 25%, var(--gold) 25% 50%, var(--indigo) 50% 75%, var(--green) 75%);
}

.auth-logo { width: 82px; height: 82px; object-fit: contain; }
.auth-card h1, .panel h1, .document h1 { font-family: Georgia, "Times New Roman", serif; }
.auth-card h1 { margin: 18px 0 8px; color: var(--indigo); font-size: 30px; }
.auth-card > p { margin: 0; color: var(--muted); }

.login-form { display: grid; gap: 10px; margin-top: 26px; text-align: left; }
.login-form label { color: var(--ink); font-size: 13px; font-weight: 700; }
.login-form input, .datatable-toolbar input, .datatable-toolbar select {
  min-height: 40px;
  padding: 9px 11px;
  color: var(--ink);
  background: white;
  border: 1px solid #d5d1df;
  border-radius: 4px;
}
.login-form input:focus, .datatable-toolbar input:focus, .datatable-toolbar select:focus {
  outline: 2px solid rgba(33, 22, 95, .18);
  border-color: var(--indigo);
}

button, .login-form button {
  min-height: 40px;
  padding: 10px 16px;
  color: white;
  font-weight: 700;
  background: var(--indigo);
  border: 1px solid var(--indigo);
  border-radius: 4px;
  cursor: pointer;
}
button:hover, .login-form button:hover { background: var(--indigo-dark); }
button.secondary { color: var(--indigo); background: white; border-color: #c9c4d6; }
button.secondary:hover { color: white; background: var(--indigo); }

.alert {
  margin: 16px 0;
  padding: 12px;
  color: #842323;
  background: #fff4f1;
  border: 1px solid #edc8c0;
  border-left: 4px solid var(--red);
  border-radius: 3px;
}
.success-alert {
  color: #12643b;
  background: #eaf7ef;
  border-color: #ccebd8;
  border-left-color: var(--green);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 84px;
  align-items: center;
  justify-content: space-between;
  padding: 12px max(24px, calc((100vw - 1320px) / 2));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(20, 15, 54, .04);
}

.topbar::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 5px;
  content: "";
  background: linear-gradient(90deg, var(--red) 0 25%, var(--gold) 25% 50%, var(--indigo) 50% 75%, var(--green) 75%);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand img { width: 52px; height: 52px; object-fit: contain; }
.brand div { display: grid; gap: 3px; }
.brand strong { color: var(--indigo); font-family: Georgia, "Times New Roman", serif; font-size: 21px; }
.brand span { color: var(--muted); font-size: 12px; }
.account { display: flex; align-items: center; gap: 12px; }
.account > span { color: var(--muted); font-size: 13px; }

.shell { max-width: 1380px; margin: auto; padding: 30px 28px 52px; }
.tabs { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  color: var(--indigo);
  background: white;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: color .15s ease, background .15s ease, border-color .15s ease, transform .15s ease;
}
.tabs a:hover { transform: translateY(-1px); border-color: var(--indigo); }
.tabs a.active { color: white; background: var(--indigo); border-color: var(--indigo); box-shadow: 0 5px 12px rgba(33,22,95,.16), inset 0 -3px var(--gold); }

.dashboard-intro {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 20px;
  padding: 2px 2px 18px;
  border-bottom: 1px solid var(--line);
}
.intro-icon, .title-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--indigo);
  background: #eeebf7;
  border: 1px solid #e1dced;
}
.intro-icon { width: 52px; height: 52px; border-radius: 14px; }
.dashboard-intro h1 { margin: 0; color: var(--indigo); font-family: Georgia, "Times New Roman", serif; font-size: 25px; }
.dashboard-intro p { margin: 0; }
.eyebrow { margin-bottom: 4px !important; color: #777387; font-size: 11px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.intro-caption { margin-top: 4px !important; color: var(--muted); font-size: 13px; }
.record-summary { display: grid; justify-items: end; gap: 2px; margin-left: auto; }
.record-summary strong { color: var(--indigo); font-size: 22px; line-height: 1.1; }
.record-summary > span:last-child { color: var(--muted); font-size: 12px; }

.panel { padding: 22px; background: var(--paper); border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 5px 18px rgba(26, 19, 63, .055); }
.panel h1, .panel-title { margin: 0 0 17px; padding-bottom: 13px; color: var(--indigo); border-bottom: 1px solid var(--line); font-family: Georgia, "Times New Roman", serif; font-size: 22px; }
.panel-title { display: flex; align-items: center; gap: 10px; }
.title-icon { width: 34px; height: 34px; border-radius: 10px; }
.table-wrap { overflow: auto; }
.panel table { width: 100%; border-collapse: collapse; }
.panel th, .panel td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; }
.panel th { color: #625e75; background: #f8f7fb; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.panel tbody tr { transition: background .12s ease; }
.panel tbody tr:hover { background: #fbf9ff; }
.panel tbody tr:last-child td { border-bottom: 0; }
.panel tbody td:first-child { font-weight: 500; }
.user-password-reset {
  display: grid;
  min-width: 520px;
  grid-template-columns: minmax(130px, 1fr) minmax(130px, 1fr) auto;
  align-items: center;
  gap: 7px;
}
.user-password-reset input {
  min-width: 0;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid #d5d1df;
  border-radius: 4px;
}
.user-password-reset input:focus { outline: 2px solid rgba(33, 22, 95, .18); border-color: var(--indigo); }
.user-password-reset button { min-height: 36px; padding: 7px 10px; white-space: nowrap; }
.user-manager-dialog {
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 24px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(8, 5, 37, .3);
}
.user-manager-dialog::backdrop { background: rgba(15, 11, 42, .58); }
.user-manager-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.user-manager-header h2 { margin: 0; color: var(--indigo); font-family: Georgia, "Times New Roman", serif; font-size: 21px; overflow-wrap: anywhere; }
.user-manager-close { min-height: 34px; padding: 6px 10px; }
.user-manager-section { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.user-manager-section h3 { margin: 0 0 6px; color: var(--indigo); font-size: 15px; }
.user-manager-section p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.user-manager-dialog .user-password-reset { min-width: 0; grid-template-columns: 1fr; align-items: stretch; }
.user-manager-dialog .user-password-reset label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.user-manager-dialog .user-password-reset input { width: 100%; }
.user-manager-dialog .user-password-reset button { justify-self: start; }
.user-manager-dialog form:not(.user-password-reset) { display: grid; gap: 10px; }
.user-manager-dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.user-manager-dialog input, .user-manager-dialog select { min-height: 36px; padding: 7px 9px; border: 1px solid #d5d1df; border-radius: 4px; }
.user-manager-dialog .danger-button { color: #842323; background: #fff4f1; border-color: #edc8c0; }
.user-manager-dialog .danger-button:hover { color: white; background: var(--red); }
.table-action { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; color: var(--indigo); background: #f5f3fa; border: 1px solid #e6e1f1; border-radius: 7px; font-size: 12px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.table-action:hover { color: white; background: var(--indigo); border-color: var(--indigo); }

.icon { display: block; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-large { width: 24px; height: 24px; }
.control-label { display: inline-flex; align-items: center; gap: 6px; }
.control-label .icon { width: 14px; height: 14px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: max-content;
  padding: 4px 9px;
  color: var(--indigo);
  background: #f0eef8;
  border: 1px solid #e2deef;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}
.role-badge { color: #4a4382; background: #f0eef8; }
.admin-badge { color: #74420a; background: #fff4d6; border-color: #f2dfaa; }
.status-badge.success { color: #12643b; background: #eaf7ef; border-color: #ccebd8; }
.status-badge.muted { color: #6e6a78; background: #f1f0f3; border-color: #e3e1e7; }
.status-badge.neutral { color: #625e75; background: #f5f3fa; }
.status-dot { width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.summary-badge { margin-bottom: 4px; color: #12643b; background: #eaf7ef; border-color: #ccebd8; }

.datatable-toolbar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  background: white;
  border: 1px solid var(--line);
  border-top: 3px solid var(--indigo);
  border-radius: 9px;
}
.datatable-toolbar label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.datatable-toolbar input[type="search"] { min-width: 220px; }
.datatable-toolbar button { min-height: 40px; }
.reset-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  padding: 8px 14px;
  color: var(--indigo);
  border: 1px solid #c9c4d6;
  border-radius: 4px;
  text-decoration: none;
}
.reset-button:hover { background: #f5f3fa; }

.datatable-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 13px; }
.datatable-pager div { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.datatable-pager a, .datatable-pager strong, .datatable-pager .disabled { padding: 7px 10px; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; }
.datatable-pager a { color: var(--indigo); background: white; }
.datatable-pager a:hover { color: white; background: var(--indigo); }
.datatable-pager strong { color: white; background: var(--indigo); border-color: var(--indigo); }
.datatable-pager .disabled { opacity: .48; }

.document-page { min-height: 100vh; padding: 32px; background: #f3f1f8; }
.document { max-width: 900px; margin: auto; padding: 48px; color: #24212b; background: white; border-top: 6px solid var(--indigo); box-shadow: 0 8px 30px rgba(20, 15, 54, .1); }
.document-logo { display: block; width: 74px; height: 74px; margin: 0 auto 10px; object-fit: contain; }
.document-kicker { color: var(--indigo); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-align: center; }
.document h1 { padding-bottom: 16px; color: var(--indigo); border-bottom: 2px solid var(--gold); text-align: center; }
.document dl { display: grid; grid-template-columns: 180px 1fr; gap: 12px; }
.document dt { font-weight: 700; }
.document dd { margin: 0; }
.back-link { color: var(--indigo); }
.admin-create-panel { margin: 0 0 18px; padding: 12px 14px; background: #faf9fc; border: 1px solid var(--line); border-radius: 8px; }
.admin-create-panel > summary, .row-editor > summary { color: var(--indigo); cursor: pointer; font-size: 13px; font-weight: 700; }
.inline-editor-form, .metadata-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 11px; margin-top: 14px; }
.inline-editor-form label, .metadata-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.inline-editor-form input, .inline-editor-form select, .metadata-form input, .metadata-form select, .metadata-form textarea {
  min-width: 0; min-height: 36px; padding: 7px 9px; color: var(--ink); background: white; border: 1px solid #d5d1df; border-radius: 4px;
}
.metadata-form textarea { resize: vertical; }
.inline-editor-form button, .metadata-form button { align-self: end; }
.row-editor { min-width: 130px; }
.row-editor form { display: grid; gap: 9px; min-width: 220px; margin: 12px 0; }
.row-editor label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.row-editor input, .row-editor select { min-height: 34px; padding: 6px 8px; border: 1px solid #d5d1df; border-radius: 4px; }
.danger-button { color: #842323; background: #fff4f1; border-color: #edc8c0; }
.sync-form { margin: 0 0 14px; }
.cell-subtitle { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 400; }
.action-cell { min-width: 180px; }
.document-controls { display: flex; max-width: 900px; align-items: center; justify-content: space-between; margin: 0 auto 16px; }
.laa-document { max-width: 21cm; min-height: 29.7cm; padding: 1cm 1.5cm 2cm 2cm; border-top: 0; font-family: "Book Antiqua", Georgia, serif; font-size: 10.5pt; line-height: 1.25; }
.laa-letterhead { display: block; width: 10cm; max-width: 100%; max-height: 3cm; margin: 0 0 8px; object-fit: contain; object-position: left center; }
.laa-document-meta { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin: 12px 0 24px; }
.laa-barcode-value { display: grid; justify-items: start; gap: 2px; padding: 5px 8px; border: 1px solid #c8c8c8; font: 7pt Arial, sans-serif; letter-spacing: .04em; }
.laa-barcode-value svg { max-width: 190px; height: 34px; }
.laa-reference { text-align: right; white-space: nowrap; }
.laa-reference p { margin: 0 0 4px; }
.laa-document .laa-title { margin: 0 0 18px; padding: 0; color: #111; border: 0; font: 700 12pt Arial, sans-serif; text-align: center; }
.laa-document > p { margin: 0 0 9px; text-align: justify; }
.laa-details { width: 100%; margin: 14px 0; border-collapse: collapse; }
.laa-details th, .laa-details td { padding: 3px 4px; vertical-align: top; text-align: left; }
.laa-details th { width: 130px; white-space: nowrap; }
.laa-details td { overflow-wrap: anywhere; }
.laa-details a, .laa-validation a { color: #174ea6; overflow-wrap: anywhere; }
.laa-signoff { margin: 20px 0 0 30px; }
.laa-signoff p { margin: 0 0 5px; }
.laa-qr-link { display: block; width: 78px; height: 78px; margin: 5px 0 2px; padding: 2px; border: 1px solid #e5e3e8; }
.laa-qr-link svg { display: block; width: 100%; height: 100%; }
.laa-qr-caption { display: block; width: 78px; color: var(--muted); font: 7pt Arial, sans-serif; text-align: center; }
.laa-signatory { margin-top: 20px !important; font-weight: 700; }
.laa-note { margin: -20px 0 0 auto !important; text-align: right; }
.laa-validation { margin-top: 10px !important; font-size: 9pt; }
.laa-footer { margin-top: 22px; padding-top: 5px; color: #002060; border-top: 1px solid #002060; font: 700 8pt/1.3 Arial, sans-serif; text-align: center; }
@page { size: A4; margin: 10mm; }
@media print {
  .document-page { min-height: auto; padding: 0; background: white; }
  .document-controls { display: none; }
  .laa-document { max-width: none; min-height: 0; margin: 0; padding: 0; border: 0; box-shadow: none; }
  .laa-letterhead, .laa-details, .laa-footer { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}

@media (max-width: 640px) {
  .topbar { padding-right: 16px; padding-left: 16px; }
  .brand strong { font-size: 17px; }
  .brand span { font-size: 11px; }
  .account { gap: 7px; }
  .account > span:first-child { display: none; }
  .shell { padding: 22px 14px 36px; }
  .dashboard-intro { align-items: flex-start; }
  .intro-icon { width: 42px; height: 42px; border-radius: 12px; }
  .dashboard-intro h1 { font-size: 21px; }
  .record-summary { align-self: center; }
  .record-summary .badge { display: none; }
  .record-summary strong { font-size: 18px; }
  .datatable-toolbar { align-items: stretch; }
  .datatable-toolbar label, .datatable-toolbar input[type="search"] { width: 100%; min-width: 0; }
  .datatable-pager { align-items: flex-start; flex-direction: column; }
  .document-page { padding: 12px; }
  .document { padding: 24px 18px; }
  .document dl { grid-template-columns: 1fr; gap: 5px; }
  .document dd { margin-bottom: 10px; }
  .laa-document { padding: 18px; }
  .laa-document-meta { flex-direction: column; }
  .laa-reference { text-align: left; }
}
