:root {
  --brand-gold: #d0b078;
  --brand-navy: #17152e;
  --bg: #0f0f1d; /* deep background to complement navy */
  --surface: #ffffff;
  --surface-2: #f7f7fb;
  --border: #e5e7eb;
  --text: #111827;
  --text-inverse: #ffffff;
  --muted: #6b7280;
  --primary: var(--brand-navy);
  --accent: var(--brand-gold);
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
  color: var(--text);
  background: var(--surface-2);
}

.bg-white {
  background: var(--surface);
}

.topbar {
  padding: 16px 24px;
  background: linear-gradient(90deg, var(--brand-navy), #221f44);
  color: var(--text-inverse);
  border-bottom: 3px solid var(--brand-gold);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.topbar-flex {
  display: flex;
  align-items: center;
}
.topbar-spacer {
  flex: 1;
}
.greeting {
  font-weight: 600;
  font-size: 14px;
  color: var(--brand-gold);
}

/* Flash messages */
.flash {
  max-width: 1100px;
  margin: 12px auto 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(23, 21, 46, 0.12);
  border: 1px solid transparent;
}
.flash.info {
  background: #eef4ff;
  color: #1e3a8a;
  border-color: #bfdbfe;
}
.flash.success {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}
.flash.error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}
.flash.hidden {
  display: none;
}

/* Wizard */
.wizard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 21, 46, 0.12);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
}
.wizard {
  background: #fff;
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.wizard-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}
.wizard-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}
.wizard-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
}
.wizard-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}
.wizard-left,
.wizard-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.section-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 6px 18px rgba(23, 21, 46, 0.06);
}
.section-title {
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.section-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 8px;
}
.section-card input[type="text"],
.section-card input[type="number"],
.section-card input[type="date"],
.section-card textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: #2b2f51;
}
.section-card textarea {
  resize: none;
  width: 100%;
}

/* Inline field row to align label text and toggle */
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.docs-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.dropzone {
  border: 2px dashed #cfd8ff;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}
.dropzone.dragover {
  background: #f4f7ff;
}
.table.compact td,
.table.compact th {
  padding: 10px;
}

/* Card title row */
.card-title-row {
  display: flex;
  align-items: center;
}
.card-title-row h2 {
  margin: 0;
}
.card-title-row .btn {
  margin-left: auto;
}

.container {
  max-width: 1440px;
  margin: 24px auto;
  padding: 0 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(23, 21, 46, 0.06);
}
.card h2 {
  margin-top: 0;
}

.center-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(23, 21, 46, 0.15);
  position: relative;
}
.modal-title {
  margin: 0 0 12px;
  text-align: center;
  font-weight: 800;
  color: var(--brand-navy);
}

.label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0 6px;
}
.input,
.textarea,
.table input,
.table select {
  width: 100%;
  padding: 12px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: white;
  transition:
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}
.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--brand-gold);
  box-shadow: 0 0 0 3px rgba(208, 176, 120, 0.25);
}
.textarea {
  resize: vertical;
}
.field-error {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}
.error-text {
  color: #b91c1c;
  font-size: 12px;
  margin-top: 4px;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.actions-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.actions-bar .spacer {
  flex: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  background: var(--primary);
  color: var(--text-inverse);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.2px;
  box-shadow: 0 6px 16px rgba(23, 21, 46, 0.2);
  transition:
    transform 0.05s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(23, 21, 46, 0.24);
}
.btn:active {
  transform: translateY(0);
}
.btn.secondary {
  background: #eef0f8;
  color: #2b2f51;
  box-shadow: none;
}
.btn.primary {
  background: var(--brand-navy);
}
.btn.accent {
  background: var(--brand-gold);
  color: #2b1f0a;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.table-wrap {
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
}
.table.modern thead th {
  background: #fbfbfe;
  color: #2b2f51;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  max-width: 550px;
}
.table.modern tbody td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  max-width: 550px;
}
.table.modern tbody tr:hover {
  background: #f7f8ff;
}
.table.modern tbody tr:last-child td {
  border-bottom: none;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
}
.badge-draft {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #e2e8f0;
}
.badge-pending {
  background: rgba(208, 176, 120, 0.18);
  color: #5b4723;
  border: 1px solid rgba(208, 176, 120, 0.6);
}
.badge-completed {
  background: rgba(23, 21, 46, 0.1);
  color: var(--brand-navy);
  border: 1px solid rgba(23, 21, 46, 0.3);
}

/* Filter tiles */
.filter-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 4px 0 16px;
}
.filter-tile {
  position: relative;
  background: #fafbff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  flex: 0 0 auto;
  align-items: flex-start;
  gap: 4px;
  box-shadow: 0 4px 12px rgba(23, 21, 46, 0.05);
  transition:
    background 0.2s,
    border-color 0.2s,
    box-shadow 0.2s;
}
.filter-tile:hover {
  background: #f4f7ff;
}
.filter-tile.active {
  border-color: var(--brand-gold);
  background: linear-gradient(135deg, #fff, #fdf7eb);
  box-shadow: 0 6px 18px rgba(23, 21, 46, 0.12);
}
.filter-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-count {
  font-size: 22px;
  font-weight: 800;
  color: #2b2f51;
  line-height: 1;
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 21, 46, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 2000;
}
.modal-overlay.hidden {
  display: none;
}
.modal-card.large {
  max-width: 560px;
}
.muted {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 2px solid #eef0f8;
  margin-bottom: 12px;
}
.tab {
  appearance: none;
  background: transparent;
  border: none;
  padding: 10px 12px;
  font-weight: 700;
  color: #2b2f51;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active {
  color: var(--brand-navy);
  border-bottom-color: var(--brand-gold);
}

/* Tiles (Case Overview) */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 4px 12px rgba(23, 21, 46, 0.05);
}
.tile .tile-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.tile .tile-value {
  margin-top: 6px;
  font-weight: 800;
  color: #2b2f51;
}

/* Letter editor layout */
.editor-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.preview-pane {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px rgba(23, 21, 46, 0.06);
}
.preview-pane img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.section h4 {
  margin: 0 0 8px;
  color: #2b2f51;
}
.section .actions {
  justify-content: flex-start;
}

/* Documents */
.files-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.files-head .spacer {
  flex: 1;
}
.file-list {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
}
.file-list th,
.file-list td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.file-list tbody tr:last-child td {
  border-bottom: none;
}
.file-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}
.drag-handle {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: grab;
  user-select: none;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}
.drag-handle:hover {
  color: var(--brand-navy);
  background: var(--surface-2);
}
.drag-handle.drag-disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: transparent;
}
.file-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--brand-navy);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-icon i {
  font-size: 19px;
}
.file-row.dragging {
  opacity: 0.55;
}
.file-row-letter .drag-handle {
  pointer-events: none;
}

/* Toggle */
.switch {
  position: relative;
  width: 44px;
  height: 24px;
  display: inline-block;
}
.switch input {
  display: none;
}
.slider {
  position: absolute;
  inset: 0;
  background: #e5e7eb;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .slider {
  background: var(--brand-gold);
}
.switch input:checked + .slider:before {
  transform: translateX(20px);
}

/* Action buttons */
.icon-btn {
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2b2f51;
  transition:
    background 0.15s ease,
    color 0.15s ease;
}
.icon-btn:hover {
  background: #f1f2f8;
}
.icon-btn:active {
  background: #e6e8f2;
}
.icon-btn.destructive {
  color: #b42318;
}
.icon-btn.destructive:hover {
  background: #fdecea;
}
.icon-btn.disabled,
.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: transparent;
}
.icon-btn + .icon-btn {
  margin-left: 4px;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Search results dropdown */
.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(23, 21, 46, 0.12);
  z-index: 1000;
  margin-top: -1px;
}
.search-results.hidden {
  display: none;
}
.search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}
.search-result-item:last-child {
  border-bottom: none;
}
.search-result-item:hover {
  background: #f7f8ff;
}
.search-result-name {
  font-weight: 600;
  color: #2b2f51;
  font-size: 14px;
  margin-bottom: 4px;
}
.search-result-details {
  font-size: 12px;
  color: var(--muted);
}
.search-result-empty {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.search-result-loading {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.signature-image {
  max-width: 100%;
  max-height: 100px;
}

#aiSectionsContainer{
  max-width: 550px;
}

/* Responsive */
@media (max-width: 900px) {
  .editor-split {
    grid-template-columns: 1fr;
  }
}

#uploadFileName {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fileUploadingProgress {
  width: 100%;
}

#generateLetterBtn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
}

.btn.primary:disabled {
  opacity: 0.6;
}

input:disabled + .slider {
  opacity: 0.2;
}

button i {
  margin-right: 6px;
}

.ql-editor {
  font-family: "Times New Roman", sans-serif;
  font-size: 13pt;
}

.ql-snow .ql-editor h4 {
  margin: 1.3em 0;
}

.loader-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgb(255 255 255);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loader {
  box-sizing: border-box;
  display: inline-block;
  width: 50px;
  height: 80px;
  border-top: 5px solid #808080;
  border-bottom: 5px solid #808080;
  position: relative;
  background: linear-gradient(#ff3d00 30px, transparent 0) no-repeat;
  background-size: 2px 40px;
  background-position: 50% 0px;
  animation: spinx 5s linear infinite;
}
.loader:before,
.loader:after {
  content: "";
  width: 40px;
  left: 50%;
  height: 35px;
  position: absolute;
  top: 0;
  transform: translatex(-50%);
  background: rgb(170 170 170 / 40%);
  border-radius: 0 0 20px 20px;
  background-size: 100% auto;
  background-repeat: no-repeat;
  background-position: 0 0px;
  animation: lqt 5s linear infinite;
}
.loader:after {
  top: auto;
  bottom: 0;
  border-radius: 20px 20px 0 0;
  animation: lqb 5s linear infinite;
}
@keyframes lqt {
  0%,
  100% {
    background-image: linear-gradient(#ff3d00 40px, transparent 0);
    background-position: 0% 0px;
  }
  50% {
    background-image: linear-gradient(#ff3d00 40px, transparent 0);
    background-position: 0% 40px;
  }
  50.1% {
    background-image: linear-gradient(#ff3d00 40px, transparent 0);
    background-position: 0% -40px;
  }
}
@keyframes lqb {
  0% {
    background-image: linear-gradient(#ff3d00 40px, transparent 0);
    background-position: 0 40px;
  }
  100% {
    background-image: linear-gradient(#ff3d00 40px, transparent 0);
    background-position: 0 -40px;
  }
}
@keyframes spinx {
  0%,
  49% {
    transform: rotate(0deg);
    background-position: 50% 36px;
  }
  51%,
  98% {
    transform: rotate(180deg);
    background-position: 50% 4px;
  }
  100% {
    transform: rotate(360deg);
    background-position: 50% 36px;
  }
}
