:root {
  --ink: #2B2B2E;
  --ink-deep: #151517;
  --teal: #7A1014;
  --paper: #FAFAF8;
  --paper-raised: #FFFFFF;
  --gold: #D6202A;
  --gold-soft: #F5D6D4;
  --text: #242426;
  --text-soft: #6f6f72;
  --line: #E4E2DE;
  --success: #2F6B4F;
  --success-bg: #E4EFE7;
  --alert: #8C1015;
  --alert-bg: #F5E1E0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 22, 0.06), 0 6px 20px rgba(20, 20, 22, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, rgba(27, 42, 74, 0.05) 1px, transparent 0);
  background-size: 22px 22px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
.serif {
  font-family: 'Source Serif 4', serif;
}

.mono {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

a {
  color: inherit;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection {
  background: var(--gold-soft);
}

/* ---------- Top bar ---------- */
.topbar {
  background: var(--ink);
  color: #F3EFE2;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-seal {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(214, 32, 42, 0.5);
}

.brand-seal img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-text .brand-name {
  font-family: 'Source Serif 4', serif;
  font-weight: 600;
  font-size: 16.5px;
  letter-spacing: .2px;
  line-height: 1.1;
}

.brand-text .brand-sub {
  font-size: 10.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--gold-soft);
  opacity: .9;
  font-style: italic;
}

.admin-nav {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.07);
  padding: 4px;
  border-radius: 999px;
  flex-wrap: wrap;
}

.admin-nav a {
  border: none;
  background: transparent;
  color: #E9E4D4;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .2px;
  transition: .18s;
  white-space: nowrap;
}

.admin-nav a.active {
  background: var(--gold);
  color: var(--ink-deep);
}

.admin-nav a:not(.active):hover {
  background: rgba(255, 255, 255, 0.1);
}

.admin-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.view {
  max-width: 100%;
  margin: 0 auto;
  padding: 30px 18px 60px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: .15s;
}

.btn-primary {
  background: var(--ink);
  color: #fff;
}

.btn-primary:hover {
  background: var(--ink-deep);
}

.btn-gold {
  background: var(--gold);
  color: var(--ink-deep);
}

.btn-gold:hover {
  filter: brightness(1.06);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--line);
  color: var(--text);
}

.btn-outline:hover {
  border-color: var(--ink);
}

.btn-danger {
  background: transparent;
  color: var(--alert);
  border: 1.5px solid var(--alert-bg);
}

.btn-danger:hover {
  background: var(--alert-bg);
}

.btn-full {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
  border-radius: 6px;
}

.lookup-error {
  margin-top: 14px;
  background: var(--alert-bg);
  color: var(--alert);
  padding: 10px 12px;
  border-radius: 7px;
  font-size: 13.5px;
  display: none;
}

.lookup-card {
  background: var(--paper-raised);
  max-width: 480px;
  margin: 26px auto 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 26px 26px 22px;
}

.lookup-card label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  display: block;
  margin-bottom: 6px;
}

.lookup-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  font-size: 15px;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: .4px;
  background: #FBFAF5;
  color: var(--text);
}

.lookup-card input:focus {
  outline: none;
  border-color: var(--gold);
}

.admin-login-wrap {
  max-width: 400px;
  margin: 60px auto;
}

.lookup-hero {
  text-align: center;
  padding: 36px 16px 8px;
}

.lookup-hero .eyebrow {
  text-transform: uppercase;
  letter-spacing: 2.5px;
  font-size: 11.5px;
  color: var(--teal);
  font-weight: 600;
}

.lookup-hero h1 {
  font-size: clamp(22px, 4vw, 30px);
  margin: 10px 0 6px;
  color: var(--ink-deep);
  font-weight: 600;
}

/* ---------- Admin dashboard ---------- */
.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  margin-top: 4px;
  padding: 3px 10px;
  border-radius: 99px;
}

.cloud-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cloud-badge.on {
  background: var(--success-bg);
  color: var(--success);
}

.cloud-badge.on::before {
  background: var(--success);
}

.cloud-badge.off {
  background: var(--alert-bg);
  color: var(--alert);
}

.cloud-badge.off::before {
  background: var(--alert);
}

.admin-topbar h2 {
  margin: 0;
  font-size: 23px;
  color: var(--ink-deep);
  font-weight: 600;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.stat-box {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.stat-box .sval {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 22px;
  font-weight: 600;
  color: var(--ink-deep);
}

.stat-box .slbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-soft);
  margin-top: 2px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar input,
.toolbar select {
  padding: 9px 12px;
  border-radius: 7px;
  border: 1.5px solid var(--line);
  font-size: 13.5px;
  background: #fff;
  font-family: inherit;
}

.toolbar input {
  flex: 1;
  min-width: 180px;
}

.table-wrap {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 11px 14px;
  background: #F1ECDC;
  color: var(--ink);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #FBF9F1;
}

.cell-ref {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12.5px;
  color: var(--ink);
}

.cell-name {
  font-weight: 600;
}

.cell-sub {
  font-size: 11.5px;
  color: var(--text-soft);
  margin-top: 2px;
}

.stage-select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  font-size: 12.5px;
  font-family: inherit;
  background: #fff;
  max-width: 150px;
}

.pay-badge {
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
}

.pay-badge.paid {
  background: var(--success-bg);
  color: var(--success);
}

.pay-badge.partial {
  background: var(--gold-soft);
  color: #6b4e12;
}

.pay-badge.unpaid {
  background: var(--alert-bg);
  color: var(--alert);
}

.pay-badge.cancelled {
  background: var(--line);
  color: var(--text-soft);
}

.days-mini {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--text-soft);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-soft);
}

.icon-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.icon-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.icon-btn:disabled:hover {
  border-color: var(--line);
  color: var(--text-soft);
}

.empty-state {
  padding: 50px 20px;
  text-align: center;
  color: var(--text-soft);
}

.empty-state .es-title {
  font-family: 'Source Serif 4', serif;
  font-size: 18px;
  color: var(--ink-deep);
  margin-bottom: 4px;
}

/* ---------- Country/document-type/stage chip manager ---------- */
.country-row {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.country-row:last-child {
  border-bottom: none;
}

.country-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.country-name {
  font-weight: 600;
  color: var(--ink-deep);
  font-size: 14px;
}

.country-stages {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.stage-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 99px;
  font-size: 12px;
  background: #F1ECDC;
  color: var(--ink);
}

.stage-chip.default {
  background: var(--line);
  color: var(--text-soft);
}

.stage-chip.custom {
  cursor: grab;
  user-select: none;
}

.stage-chip.custom:active {
  cursor: grabbing;
}

.stage-chip.custom.dragging {
  opacity: .4;
}

.stage-chip.custom.drag-over {
  outline: 2px dashed var(--gold);
  outline-offset: 2px;
}

.stage-drag-handle {
  color: var(--text-soft);
  font-size: 11px;
  margin-right: 1px;
  line-height: 1;
}

.stage-chip button {
  border: none;
  background: transparent;
  color: var(--alert);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.stage-add-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.stage-add-row input {
  padding: 6px 9px;
  border-radius: 6px;
  border: 1.5px solid var(--line);
  font-size: 12.5px;
}

/* ---------- Side-nav layout (client detail page) ---------- */
.side-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 22px;
  align-items: start;
}

.side-nav {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 80px;
}

.side-nav button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 13px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-soft);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.side-nav button:last-child {
  border-bottom: none;
}

.side-nav button.active {
  background: var(--gold-soft);
  color: var(--ink-deep);
}

.side-panel {
  display: none;
}

.side-panel.active {
  display: block;
}

@media (max-width:760px) {
  .side-layout {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: static;
    display: flex;
    overflow-x: auto;
  }

  .side-nav button {
    border-bottom: none;
    border-right: 1px solid var(--line);
    white-space: nowrap;
  }
}

/* ---------- Client picker (search + suggestions) ---------- */
.client-picker {
  position: relative;
}

.client-suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
}

.client-suggestions.show {
  display: block;
}

.client-suggestion-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}

.client-suggestion-item:last-child {
  border-bottom: none;
}

.client-suggestion-item:hover,
.client-suggestion-item.active {
  background: #FBF9F1;
}

.client-suggestion-item .csi-name {
  font-weight: 600;
  color: var(--ink-deep);
}

.client-suggestion-item .csi-sub {
  font-size: 11.5px;
  color: var(--text-soft);
  margin-top: 1px;
}

.client-suggestion-item.create {
  color: var(--gold);
  font-weight: 600;
}

.client-selected-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--success-bg);
  color: var(--success);
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
}

.client-selected-note button {
  border: none;
  background: transparent;
  color: var(--success);
  text-decoration: underline;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  margin-left: auto;
}

.client-create-panel {
  margin-top: 10px;
  padding: 12px;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  display: none;
}

.client-create-panel.show {
  display: block;
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18, 30, 56, 0.55);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 30px 14px;
  backdrop-filter: blur(2px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--paper-raised);
  border-radius: 12px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.modal-head {
  background: var(--ink);
  color: #fff;
  padding: 16px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  opacity: .8;
}

.modal-close:hover {
  opacity: 1;
}

.modal-body {
  padding: 22px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-body-flush {
  padding: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .full {
  grid-column: 1/-1;
}

.field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  display: block;
  margin-bottom: 5px;
  letter-spacing: .2px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 7px;
  border: 1.5px solid var(--line);
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.field-hint {
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 3px;
}

.modal-foot {
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Wider variant for modals that need two side-by-side sections (e.g. case details +
   payment details) instead of one long stacked form. Rendered full-screen so there's
   room for both columns without cramping the form. */
#case-modal.modal-overlay {
  padding: 0;
}

.modal-wide {
  max-width: 100vw;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
}

.modal-wide .modal-head {
  flex: 0 0 auto;
}

.modal-wide .modal-body {
  flex: 1 1 auto;
  max-height: none;
  overflow: hidden;
}

.modal-wide .modal-foot {
  flex: 0 0 auto;
}

.modal-wide .modal-split {
  height: 100%;
}

.modal-split {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 0;
}

.modal-split-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.modal-split-col {
  padding: 18px 20px;
  overflow-y: auto;
  height: 100%;
}

.modal-split-col+.modal-split-col {
  border-left: 1px solid var(--line);
  background: var(--paper);
}

.modal-split-col .form-grid {
  gap: 12px;
}

.modal-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-soft);
  margin: 0 0 14px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--line);
}

@media (max-width:1100px) {
  .modal-split-3 {
    grid-template-columns: 1fr 1fr;
  }

  .modal-split-3 .modal-split-col:last-child {
    grid-column: 1/-1;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

@media (max-width:820px) {
  .modal-split {
    grid-template-columns: 1fr;
  }

  .modal-split-col+.modal-split-col {
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

/* Collapsible field hints: hidden by default, revealed via the "?" icon next to a label. */
.field label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-help-toggle {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.3px solid var(--line);
  background: transparent;
  color: var(--text-soft);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  flex: none;
}

.field-help-toggle:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.field-help {
  display: none;
}

.field-help.show {
  display: block;
}

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink-deep);
  color: #fff;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  z-index: 200;
  opacity: 0;
  transition: .25s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-soft);
  font-size: 14px;
}

@media (max-width:640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .stat-strip {
    grid-template-columns: 1fr 1fr;
  }

  .brand-text .brand-sub {
    display: none;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tbody tr {
    border-bottom: 8px solid var(--paper);
    padding: 10px 0;
  }

  tbody td {
    border: none;
    padding: 6px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    text-align: right;
  }

  tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-soft);
    text-align: left;
  }

  .row-actions {
    justify-content: flex-end;
  }
}