@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,500;8..60,600;8..60,700&family=Public+Sans:wght@400;500;600;700;800&display=swap');

:root {
  --color-navy: #14213D;
  --color-navy-light: #1F3A5F;
  --color-gold: #C9862A;
  --color-gold-dark: #A96C1C;
  --color-bg: #F6F4EF;
  --color-bg-soft: #FBFAF7;
  --color-white: #FFFFFF;
  --color-border: #E9E6DD;
  --color-border-soft: #F1EFE8;
  --color-input-border: #DCD9CE;
  --color-text: #1A1D29;
  --color-text-muted: #6B6F76;
  --color-text-faint: #9A968B;
  --color-avatar-bg: #EDE9DD;
  --color-success: #3F7A56;
  --color-success-bg: #E7F1EA;
  --color-warning: #B9791F;
  --color-warning-bg: #FBF0DD;
  --color-warning-border: #F0DFB8;
  --color-danger: #B4453B;
  --color-danger-bg: #FBEAE8;
  --color-danger-border: #E4C4C0;
  --color-info: #2F6690;
  --color-info-bg: #E8F1F7;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;
  --shadow: 0 1px 3px rgba(20, 33, 61, 0.06);
  --shadow-modal: 0 20px 60px rgba(0, 0, 0, 0.25);
  --shadow-dropdown: 0 12px 36px rgba(20, 33, 61, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: 'Public Sans', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #D8D4C8; border-radius: 4px; }

h1, h2, h3 {
  font-family: 'Source Serif 4', serif;
  margin: 0 0 8px 0;
}

a { color: var(--color-gold); text-decoration: none; }
a:hover { color: var(--color-gold-dark); text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* Layout shell */
.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  background: var(--color-navy);
  color: var(--color-white);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  padding: 8px 6px 20px;
}

.sidebar-brand-card {
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-brand-logo {
  width: 100%;
  height: auto;
  display: block;
}

.sidebar-brand-divider {
  height: 1px;
  margin: 14px 4px 0;
  background: linear-gradient(90deg, transparent, rgba(201, 134, 42, 0.45), transparent);
}

.sidebar-brand-kiati {
  padding: 10px 10px 0;
  text-align: center;
}

.sidebar-brand-name {
  font-family: 'Source Serif 4', serif;
  font-weight: 700;
  font-size: 15px;
  color: var(--color-white);
  letter-spacing: 1.5px;
}

.sidebar-brand-sub {
  font-size: 9.5px;
  color: #7C8AA3;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 2px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.75);
  font-weight: 600;
  font-size: 13.5px;
  text-decoration: none;
}

.sidebar-nav a:hover { text-decoration: none; }

.sidebar-nav a svg { flex-shrink: 0; width: 18px; height: 18px; }

.sidebar-nav a:hover {
  background: var(--color-navy-light);
  color: var(--color-white);
}

.sidebar-nav a.active {
  background: var(--color-gold);
  color: var(--color-navy);
}

.sidebar-nav a.disabled {
  opacity: 0.35;
  pointer-events: none;
}

.sidebar-nav-badge {
  margin-left: auto;
  background: var(--color-gold);
  color: var(--color-navy);
  font-size: 10.5px;
  font-weight: 800;
  border-radius: 10px;
  padding: 1px 7px;
}

a.active .sidebar-nav-badge {
  background: var(--color-navy);
  color: var(--color-gold);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid #223956;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--color-navy);
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--color-white);
  white-space: nowrap;
}

.sidebar-user-role {
  font-size: 11px;
  color: #7C8AA3;
}

.sidebar-user-avatar-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 0;
}

.sidebar-user-avatar-btn .avatar-circle {
  width: 48px;
  height: 48px;
  font-size: 16px;
  background: var(--color-gold);
  color: var(--color-navy);
}

.sidebar-footer button:not(.sidebar-user-avatar-btn) {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--color-white);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  margin-top: 8px;
  width: 100%;
}

.sidebar-footer button:not(.sidebar-user-avatar-btn):hover {
  background: rgba(255,255,255,0.1);
}

.main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  height: 64px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.topbar h2 {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 19px;
  color: var(--color-navy);
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-search-wrap { position: relative; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 12px;
  width: 280px;
}

.topbar-search input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--color-text);
  width: 100%;
  font-family: inherit;
}

.topbar-search svg { flex-shrink: 0; }

.search-clear { font-size: 15px; color: var(--color-text-faint); cursor: pointer; line-height: 1; }

.search-dropdown, .notif-dropdown {
  position: absolute;
  top: 42px;
  right: 0;
  width: 340px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dropdown);
  z-index: 200;
  display: none;
}

.topbar-search-wrap .search-dropdown { left: 0; right: auto; }

.search-dropdown.visible, .notif-dropdown.visible { display: block; }

.dropdown-section-label {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.search-result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
}

.search-result-row:hover { background: var(--color-bg-soft); }

.search-result-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--color-avatar-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 800; color: var(--color-navy);
  flex-shrink: 0;
}

.search-empty {
  padding: 18px 16px;
  font-size: 12.5px;
  color: var(--color-text-faint);
  text-align: center;
}

.notif-btn {
  position: relative;
  width: 32px; height: 32px;
  border: none; background: transparent;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.notif-btn:hover { background: var(--color-bg); }

.notif-dot {
  position: absolute; top: 3px; right: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-danger);
}

.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-soft);
}

.notif-header h4 {
  font-family: 'Source Serif 4', serif; font-weight: 600; font-size: 14.5px; color: var(--color-navy); margin: 0;
}

.notif-mark-read { font-size: 11.5px; font-weight: 700; color: var(--color-gold); cursor: pointer; }

.notif-item {
  display: flex; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-soft);
}

.notif-item.unread { background: #FBFAF3; }

.notif-dot-small {
  width: 7px; height: 7px; border-radius: 50%;
  margin-top: 5px; flex-shrink: 0;
}

.notif-text { font-size: 12.5px; color: var(--color-text); line-height: 1.5; }
.notif-time { font-size: 11px; color: var(--color-text-faint); margin-top: 2px; }

.content {
  padding: 28px;
  flex: 1;
}

/* Cards */
.card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card { padding: 18px 20px; }

.kpi-card .kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 10px;
}

.kpi-card .kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kpi-card .kpi-value {
  font-family: 'Source Serif 4', serif;
  font-size: 30px;
  font-weight: 700;
  color: var(--color-navy);
}

.kpi-card .kpi-delta {
  font-size: 12.5px;
  font-weight: 700;
}

.section-title {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--color-navy);
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Lists of rows (clients, queue, registrations) */
.row-list { display: flex; flex-direction: column; gap: 10px; }

.row-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}

.row-card.clickable { cursor: pointer; }
.row-card.clickable:hover { border-color: var(--color-gold); }

.avatar-circle {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--color-avatar-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: var(--color-navy);
  flex-shrink: 0;
}

.avatar-circle.sm { width: 30px; height: 30px; font-size: 11.5px; }
.avatar-circle.lg { width: 48px; height: 48px; font-size: 16px; }

.avatar-circle.avatar-photo { padding: 0; overflow: hidden; }
.avatar-circle.avatar-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Avatar crop editor */
.avatar-crop-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.avatar-crop-stage {
  position: relative;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  overflow: hidden;
  background: #12131a;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.avatar-crop-stage.dragging { cursor: grabbing; }

.avatar-crop-stage img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  pointer-events: none;
  will-change: transform, width, height;
}

.avatar-crop-mask {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 2000px rgba(20, 22, 28, 0.55);
  pointer-events: none;
}

.avatar-crop-zoom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  color: var(--color-text-faint);
}

.avatar-zoom-range {
  flex: 1;
  accent-color: var(--color-gold);
  cursor: pointer;
}

.avatar-crop-change-btn {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--color-gold);
  cursor: pointer;
}

.avatar-crop-change-btn:hover { color: var(--color-gold-dark); text-decoration: underline; }

.avatar-rotate-reset-btn {
  flex-shrink: 0;
  min-width: 34px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-text-muted);
  cursor: pointer;
}

.avatar-rotate-reset-btn:hover { border-color: var(--color-gold); color: var(--color-gold-dark); }

.file-thumb {
  width: 44px; height: 56px; border-radius: 6px;
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.row-title { font-size: 14px; font-weight: 700; color: var(--color-text); }
.row-subtitle { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }

.row-chevron { flex-shrink: 0; color: var(--color-text-faint); }

.empty-state {
  background: var(--color-white);
  border: 1px dashed var(--color-input-border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  color: var(--color-text-faint);
  font-size: 13.5px;
}

/* Pills (filters/tabs) */
.pill-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.pill {
  font-size: 12.5px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.pill:hover { border-color: var(--color-gold); color: var(--color-navy); }

.pill.active {
  background: var(--color-navy);
  color: var(--color-white);
  border-color: var(--color-navy);
}

/* Tabs (admin) */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.tab-btn:hover { border-color: var(--color-navy); }

.tab-btn.active {
  background: var(--color-navy);
  border-color: var(--color-navy);
  color: var(--color-white);
}

.tab-btn.has-alert {
  background: var(--color-danger-bg);
  border-color: var(--color-danger-border);
  color: var(--color-danger);
}

.tab-btn.has-alert:hover { border-color: var(--color-danger); }

.tab-badge {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  font-size: 10.5px;
  font-weight: 800;
  border-radius: 10px;
  padding: 1px 7px;
}

.tab-btn.active .tab-badge {
  background: var(--color-gold);
  color: var(--color-navy);
}

.tab-alert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-danger);
  color: var(--color-white);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.tab-btn.active .tab-alert {
  background: var(--color-white);
  color: var(--color-danger);
}

/* Data grid table (checks, logs, admin users) */
.data-grid {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-grid-row {
  display: grid;
  padding: 13px 18px;
  align-items: center;
  border-bottom: 1px solid var(--color-border-soft);
}

.data-grid-row:last-child { border-bottom: none; }

.data-grid-head {
  background: var(--color-bg-soft);
  border-bottom: 1px solid var(--color-border);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 12px 18px;
}

.data-grid-row.clickable { cursor: pointer; }
.data-grid-row.clickable:hover { background: var(--color-bg-soft); }

.cell-main { font-size: 13px; font-weight: 700; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-sub { font-size: 11.5px; color: var(--color-text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-mono { font-size: 12px; color: var(--color-text-muted); font-family: monospace; }

/* Badges (status) */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.success { background: var(--color-success-bg); color: var(--color-success); }
.badge.warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge.danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge.info { background: var(--color-info-bg); color: var(--color-info); }
.badge.neutral { background: var(--color-bg); color: var(--color-text-muted); }

/* Forms */
.field { margin-bottom: 16px; }

.field label, .field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.field input, .field select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--color-input-border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--color-white);
  color: var(--color-text);
}

.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--color-gold);
}

.password-input-wrapper {
  position: relative;
}

.password-input-wrapper input {
  padding-right: 42px;
}

.toggle-password-btn {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
}

.toggle-password-btn:hover {
  color: var(--color-text);
}

.toggle-password-btn:focus-visible {
  outline: 2px solid var(--color-gold);
  outline-offset: 2px;
  border-radius: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 9px;
  border: none;
  font-weight: 700;
  font-size: 13.5px;
}

.btn-primary { background: var(--color-navy); color: var(--color-white); }
.btn-primary:hover { background: var(--color-navy-light); }

.btn-secondary { background: var(--color-white); color: var(--color-navy); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }

.btn-success { background: var(--color-success); color: var(--color-white); }
.btn-success:hover { opacity: 0.9; }

.btn-danger { background: var(--color-white); color: var(--color-danger); border: 1px solid var(--color-danger-border); }
.btn-danger:hover { background: var(--color-danger-bg); }

.btn-danger-solid { background: var(--color-danger); color: var(--color-white); }
.btn-danger-solid:hover { opacity: 0.9; }

.btn-gold { background: var(--color-gold); color: var(--color-navy); }
.btn-gold:hover { background: var(--color-gold-dark); }

.btn-sm { padding: 7px 13px; font-size: 12.5px; }

.icon-btn {
  width: 26px; height: 26px;
  border: none; background: transparent;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
}

.icon-btn:hover { background: var(--color-bg); }
.icon-btn.danger { color: var(--color-danger); }
.icon-btn.info { color: var(--color-info); }

.error-message {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.error-message.visible { display: block; }

.success-message {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.success-message.visible { display: block; }

/* Toast */
.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 360px;
  max-width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--color-white);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-modal);
  pointer-events: auto;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.toast-visible {
  opacity: 1;
  transform: translateX(0);
}

.toast.toast-leaving {
  opacity: 0;
  transform: translateX(24px);
}

.toast-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.toast-body { flex: 1; min-width: 0; }

.toast-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
}

.toast-message {
  font-size: 12.5px;
  color: var(--color-text-muted);
  line-height: 1.4;
  margin-top: 2px;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-faint);
  font-size: 16px;
  line-height: 1;
  padding: 2px;
  margin: -2px -2px 0 0;
}

.toast-close:hover { color: var(--color-text); }

.toast-danger .toast-icon { background: var(--color-danger-bg); color: var(--color-danger); }
.toast-warning .toast-icon { background: var(--color-warning-bg); color: var(--color-warning); }
.toast-success .toast-icon { background: var(--color-success-bg); color: var(--color-success); }
.toast-info .toast-icon { background: var(--color-info-bg); color: var(--color-info); }

.toast-danger { border-left: 3px solid var(--color-danger); }
.toast-warning { border-left: 3px solid var(--color-warning); }
.toast-success { border-left: 3px solid var(--color-success); }
.toast-info { border-left: 3px solid var(--color-info); }

@media (max-width: 480px) {
  .toast-stack { top: 12px; right: 12px; left: 12px; }
  .toast { width: 100%; }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--color-white);
  border-radius: var(--radius-xl);
  padding: 26px;
  width: 460px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
}

.modal-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.modal-header h3 {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--color-navy);
  margin: 0 0 4px 0;
}

.modal-subtitle { font-size: 13px; color: var(--color-text-muted); margin-bottom: 20px; }

.modal-close-x, .modal-close {
  position: absolute;
  top: 18px; right: 18px;
  background: none; border: none;
  font-size: 20px; color: var(--color-text-muted);
}

.modal-actions { display: flex; gap: 10px; margin-top: 4px; }

/* Confirm dialog */
.confirm-overlay { animation: confirmFadeIn 0.15s ease-out; }

.confirm-modal {
  width: 380px;
  text-align: center;
  padding: 30px 26px 26px;
  animation: confirmPopIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.confirm-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.confirm-icon.danger { background: var(--color-danger-bg); color: var(--color-danger); }
.confirm-icon.warning { background: var(--color-warning-bg); color: var(--color-warning); }

.confirm-modal h3 {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 17px;
  color: var(--color-navy);
  margin: 0 0 8px 0;
}

.confirm-message {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--color-text-muted);
  margin: 0 0 22px 0;
}

.reason-options {
  text-align: left;
  margin: 0 0 20px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reason-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--color-text);
  cursor: pointer;
}

.reason-option input[type="radio"] {
  flex-shrink: 0;
  accent-color: var(--color-gold);
}

.reason-other-text {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--color-input-border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--color-text);
  resize: vertical;
  min-height: 60px;
}

.reason-other-text:focus {
  outline: none;
  border-color: var(--color-gold);
}

.confirm-modal .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@keyframes confirmFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes confirmPopIn {
  from { opacity: 0; transform: scale(0.94) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Login page (split-screen, no sidebar) */
.login-page {
  min-height: 100vh;
  display: flex;
  background: var(--color-bg-soft);
}

.login-brand-panel {
  position: relative;
  flex: 0 0 44%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 40px;
  background:
    radial-gradient(circle at 50% 0%, rgba(201, 134, 42, 0.14), transparent 55%),
    linear-gradient(160deg, var(--color-navy) 0%, #0F1A30 100%);
  color: var(--color-white);
  overflow: hidden;
}

.login-brand-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at 50% 40%, black, transparent 75%);
  pointer-events: none;
}

.login-brand-content {
  position: relative;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-brand-logo {
  width: 100%;
  max-width: 280px;
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
}

.login-brand-divider {
  width: 64px;
  height: 1px;
  margin: 22px 0 20px;
  background: linear-gradient(90deg, transparent, rgba(201, 134, 42, 0.7), transparent);
}

.login-brand-name {
  font-family: 'Source Serif 4', serif;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 2px;
  color: var(--color-white);
}

.login-brand-sub {
  font-size: 11px;
  color: #8D9BB5;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 4px;
}

.login-brand-tagline {
  font-family: 'Source Serif 4', serif;
  font-size: 16.5px;
  font-weight: 500;
  font-style: italic;
  line-height: 1.5;
  color: #D7DDE8;
  margin: 28px 0 0;
}

.login-brand-features {
  list-style: none;
  margin: 32px 0 0;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
}

.login-brand-features li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: #C7CFDD;
}

.login-brand-features .feature-icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(201, 134, 42, 0.14);
  border: 1px solid rgba(201, 134, 42, 0.3);
  color: var(--color-gold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-form-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--color-bg-soft);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card-header {
  margin-bottom: 28px;
}

.login-card-eyebrow {
  font-size: 12px;
  font-weight: 700;
  color: var(--color-gold-dark);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.login-card h1 {
  color: var(--color-navy);
  font-size: 26px;
  margin-bottom: 6px;
}

.login-card-subtitle {
  font-size: 14px;
  color: var(--color-text-muted);
}

.login-card .btn-primary {
  padding: 12px 18px;
  font-size: 14px;
  margin-top: 4px;
}

.login-card-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.login-card-footer a { font-weight: 600; }

.login-card-footer .sep {
  color: var(--color-border-soft);
  margin: 0 8px;
}

.login-mobile-brand { display: none; }

@media (max-width: 860px) {
  .login-page { flex-direction: column; }

  .login-brand-panel { display: none; }

  .login-mobile-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px 20px 22px;
    background: linear-gradient(160deg, var(--color-navy) 0%, #0F1A30 100%);
  }

  .login-mobile-brand img {
    height: 40px;
    width: auto;
  }

  .login-mobile-brand-text {
    text-align: left;
    line-height: 1.2;
  }

  .login-mobile-brand-name {
    font-family: 'Source Serif 4', serif;
    font-weight: 700;
    font-size: 15px;
    color: var(--color-white);
    letter-spacing: 1px;
  }

  .login-mobile-brand-sub {
    font-size: 10px;
    color: #8D9BB5;
    letter-spacing: 1px;
    text-transform: uppercase;
  }

  .login-form-panel {
    flex-direction: column;
    padding: 0 0 32px;
    align-items: stretch;
    justify-content: flex-start;
  }

  .login-card {
    margin: 32px 20px 0;
    width: auto;
  }
}

@media (min-width: 861px) {
  .login-brand-features { display: flex; }
}

/* Folder tree */
.tree-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.tree-row.selected .tree-row-main { background: var(--color-warning-bg); }

.tree-actions { opacity: 0; transition: opacity .12s; }
.tree-row:hover .tree-actions { opacity: 1; }

.tree-row-main {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 13px;
  cursor: default;
}

.tree-row-main.tree-folder-label {
  cursor: pointer;
  font-weight: 700;
  color: var(--color-text);
}

.tree-row-main.tree-folder-label:hover { background: var(--color-bg); }

.tree-row-main.tree-doc-label {
  color: var(--color-text-muted);
}

.tree-row-main .tree-icon { opacity: 0.65; flex-shrink: 0; display: flex; }
.tree-row-main .tree-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row-main.tree-doc-label .tree-icon { cursor: pointer; }
.tree-row-main.tree-doc-label .tree-text { cursor: pointer; }

.tree-chevron {
  flex-shrink: 0;
  color: var(--color-text-faint);
  transform: rotate(90deg);
  transition: transform .12s;
}
.tree-chevron.collapsed { transform: rotate(0deg); }

.tree-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

/* Timeline (client history) */
.timeline-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
}

.timeline-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.timeline-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--color-gold);
  margin-top: 3px;
}

.timeline-line {
  width: 1.5px; flex: 1;
  background: var(--color-border-soft);
  margin-top: 3px;
}

.timeline-action { font-size: 12.5px; font-weight: 700; color: var(--color-text); }
.timeline-meta { font-size: 11.5px; color: var(--color-text-faint); margin-top: 1px; }

.muted { color: var(--color-text-muted); font-size: 13px; }
.faint { color: var(--color-text-faint); font-size: 12px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 14px;
}

.checkbox-row input { width: auto; }

.info-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-faint);
  cursor: help;
  flex-shrink: 0;
}

.info-tooltip:hover,
.info-tooltip:focus {
  color: var(--color-navy);
  outline: none;
}

.info-tooltip-bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 9px);
  transform: translateX(-50%) translateY(4px);
  width: max-content;
  max-width: 240px;
  background: var(--color-navy);
  color: var(--color-white);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  padding: 8px 11px;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(20, 33, 61, 0.25);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 40;
}

.info-tooltip-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--color-navy);
}

.info-tooltip:hover .info-tooltip-bubble,
.info-tooltip:focus .info-tooltip-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.doc-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 20px;
}

.doc-preview {
  background: #2A2E38;
  border-radius: var(--radius-lg);
  min-height: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  color: #9CA3AF;
}

.doc-preview .doc-preview-name { color: #6B7280; font-size: 11.5px; }
.doc-preview.clickable { cursor: pointer; }
.doc-preview-thumb-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  flex: 1;
  min-height: 0;
  padding: 16px 0;
}
.doc-preview-thumb-wrap canvas,
.doc-preview-thumb-wrap img {
  max-width: calc(100% - 32px);
  max-height: 420px;
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
  object-fit: contain;
}
.doc-preview.clickable:hover { outline: 2px solid var(--color-gold); outline-offset: -2px; }

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text-muted);
  cursor: pointer;
  margin-bottom: 16px;
  width: fit-content;
}

.back-link:hover { color: var(--color-navy); }

@media (max-width: 900px) {
  .doc-detail-grid { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
}

/* Document viewer modal */
.viewer-modal {
  position: relative;
  background: var(--color-white);
  border-radius: var(--radius-xl);
  width: min(920px, 92vw);
  max-height: calc(100vh - 64px);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.viewer-title { font-family: 'Source Serif 4', serif; font-weight: 700; font-size: 16px; color: var(--color-navy); }
.viewer-subtitle { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }

.viewer-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.viewer-zoom-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--color-navy);
}

.viewer-zoom-btn:hover { background: var(--color-bg); }

.viewer-zoom-value { font-size: 12.5px; font-weight: 700; color: var(--color-text-muted); width: 44px; text-align: center; }

.viewer-close {
  width: 32px; height: 32px;
  border: none; background: transparent;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
}

.viewer-close:hover { background: var(--color-bg); }

.viewer-body {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--color-bg);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: auto;
  padding: 24px;
  user-select: none;
}

.viewer-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin: auto;
}

.viewer-pages canvas,
.viewer-body img {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  max-width: none;
}

.viewer-body img {
  transition: transform .1s ease;
  transform-origin: center center;
}

.viewer-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-navy);
  box-shadow: var(--shadow-dropdown);
}

.viewer-nav-btn:hover { background: var(--color-bg); }
.viewer-nav-btn.prev { left: 16px; }
.viewer-nav-btn.next { right: 16px; }
.viewer-nav-btn:disabled { opacity: 0.3; pointer-events: none; }

.viewer-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 33, 61, 0.85);
  color: var(--color-white);
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
}

.viewer-page-badge {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 33, 61, 0.85);
  color: var(--color-white);
  font-size: 12.5px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  z-index: 2;
  pointer-events: none;
}

/* Threshold sliders (admin > margem de confiança) */
.threshold-block { margin-bottom: 26px; }

.threshold-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.threshold-label { font-size: 13px; font-weight: 700; color: var(--color-text); }
.threshold-value { font-family: monospace; font-size: 14px; font-weight: 700; }

.threshold-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
  outline: none;
}

.threshold-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--color-white);
  border: 3px solid currentColor;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.threshold-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--color-white);
  border: 3px solid currentColor;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.threshold-hint { font-size: 12px; color: var(--color-text-faint); margin-top: 6px; }

.threshold-info-box {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  margin-top: 14px;
  line-height: 1.5;
}

.threshold-info-box.ok { background: var(--color-info-bg); color: var(--color-info); border: 1px solid #C9DCE8; }
.threshold-info-box.warn { background: var(--color-warning-bg); color: #8A5A17; border: 1px solid var(--color-warning-border); }

/* Invite link / QR */
.invite-qr-row { display: flex; gap: 22px; align-items: flex-start; flex-wrap: wrap; }

.invite-qr-box {
  width: 180px; height: 180px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-bg);
  display: flex; align-items: center; justify-content: center;
}

.invite-qr-box img { width: 100%; height: 100%; object-fit: contain; }
