:root {
  --bg: linear-gradient(135deg, #f5f7fb 0%, #eaf3ff 100%);
  --panel: #ffffff;
  --border: #d9e1ec;
  --accent: #ff7a59;
  --accent-strong: #e85b37;
  --text: #0c1c3f;
  --muted: #54627a;
  --pill: #0fb9b1;
  --shadow: 0 14px 45px rgba(12, 28, 63, 0.10);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Generic hidden class for JavaScript visibility toggling */
.hidden {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Manrope", "Space Grotesk", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px;
  border-radius: 18px;
  background: #0c1c3f;
  color: #f7fbff;
  box-shadow: 0 18px 48px rgba(12, 28, 63, 0.35);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  margin: 0 0 4px;
  color: #9dc5ff;
}

h1 {
  margin: 0 0 8px;
  font-family: "Space Grotesk", "Manrope", system-ui, sans-serif;
  font-weight: 600;
  font-size: clamp(28px, 4vw, 36px);
}

.lede {
  margin: 0;
  color: #dbe7ff;
  max-width: 640px;
}

.meta {
  display: flex;
  gap: 10px;
  align-items: center;
}

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pill img {
  height: 24px;
  width: auto;
  display: block;
}

.pill.alt {
  background: #ffe8d9;
  color: #a4481c;
}

main {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

h2 {
  margin: 4px 0 0;
  font-family: "Space Grotesk", "Manrope", system-ui, sans-serif;
  font-size: 22px;
}

.label {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 10px;
}

button {
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(232, 91, 55, 0.3);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(232, 91, 55, 0.35);
}

button:active {
  transform: translateY(0);
}

button.ghost {
  background: #ecf3ff;
  color: #0c1c3f;
  box-shadow: none;
  border: 1px solid #d5e2ff;
}

button.danger {
  background: #b00020;
  border: 1px solid #b00020;
  color: #fff;
  box-shadow: none;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.icon-btn {
  padding: 8px 10px;
  font-size: 16px;
  line-height: 1;
  background: #ecf3ff;
  color: #0c1c3f;
  box-shadow: none;
  border: 1px solid #d5e2ff;
}

button.icon-btn:hover {
  background: #dbe7ff;
  box-shadow: none;
}

button.icon-btn.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tree {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 14px;
  max-height: 320px;
  overflow: auto;
  background: #f7fbff;
}

.tree ul {
  list-style: none;
  padding-left: 16px;
  margin: 6px 0;
}

.tree li {
  margin: 6px 0;
  color: var(--text);
}

.tree label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.tree .name {
  font-weight: 600;
}

.hint {
  margin: 10px 0 0;
  color: var(--muted);
}

.results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.progress {
  display: none;
  height: 8px;
  background: #ecf3ff;
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 16px;
}

.progress.active {
  display: block;
}

.progress .bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  transition: width 0.2s ease;
}

.card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #e6f0ff;
}

/* Collapsible card content */
.card-body {
  display: none;
}

.card.expanded .card-body {
  display: block;
}

/* Always show card body when modal is open (active card) */
.card.active .card-body {
  display: block;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  user-select: none;
}

.card-header:hover {
  background: #f7fbff;
  border-radius: 8px;
  margin: -4px;
  padding: 4px;
  margin-bottom: 4px;
}

.card-title {
  margin: 0;
  font-family: "Space Grotesk", "Manrope", system-ui, sans-serif;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.card .top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.tag {
  padding: 6px 10px;
  border-radius: 10px;
  background: #ecf3ff;
  color: #1a3f7c;
  font-weight: 600;
  font-size: 13px;
}

.path {
  color: var(--muted);
  font-size: 13px;
  margin: 2px 0 8px;
}

.fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.field {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  background: #f3f6fb;
  color: var(--text);
}

.field span {
  font-weight: 600;
  flex-shrink: 0;
  padding-top: 4px; /* Align with first line of textarea */
}

.field-input {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  text-align: right;
  transition: border-color 0.15s ease, background 0.15s ease;
  cursor: default;
  resize: none; /* Disable manual resize */
  overflow: hidden; /* Hide scrollbar */
  line-height: 1.4;
}

/* Read-only state (default) */
.field-input:read-only {
  pointer-events: none;
}

.field-input:read-only::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

/* Editable state (when card is active) */
.card.active .field-input {
  cursor: text;
  pointer-events: auto;
}

.card.active .field-input:hover {
  border-color: var(--border);
  background: #fff;
}

.card.active .field-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.field-input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.save-btn {
  padding: 10px 20px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0fb9b1 0%, #0a9e97 100%);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(15, 185, 177, 0.3);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.save-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(15, 185, 177, 0.35);
}

.save-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Card buttons container */
.card-buttons {
  display: none;
  margin-top: 12px;
  gap: 10px;
  justify-content: flex-end;
}

/* Show buttons only when modal is open (editing mode) */
body.modal-open .card-buttons {
  display: flex;
}

/* De-merge button */
.demerge-btn {
  padding: 10px 20px;
  border-radius: 10px;
  background: linear-gradient(135deg, #9e9e9e 0%, #757575 100%);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(117, 117, 117, 0.3);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.demerge-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(117, 117, 117, 0.35);
}

.demerge-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Confirmation dialog */
.confirm-dialog {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(12, 28, 63, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.confirm-dialog.visible {
  opacity: 1;
  visibility: visible;
}

.confirm-dialog-box {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(12, 28, 63, 0.3);
  text-align: center;
}

.confirm-dialog-box h4 {
  margin: 0 0 12px;
  font-family: "Space Grotesk", "Manrope", system-ui, sans-serif;
  font-size: 18px;
  color: var(--text);
}

.confirm-dialog-box p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.confirm-dialog-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.confirm-dialog-buttons button {
  padding: 10px 24px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.confirm-dialog-buttons button:hover {
  transform: translateY(-1px);
}

.confirm-btn-yes {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  border: none;
  box-shadow: 0 6px 20px rgba(232, 91, 55, 0.3);
}

.confirm-btn-no {
  background: #ecf3ff;
  color: #0c1c3f;
  border: 1px solid #d5e2ff;
  box-shadow: none;
}

.preview {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.thumbs-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thumb-box {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 180px;
  padding: 6px;
  border-radius: 12px;
  background: #f3f6fb;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview img,
.preview iframe,
.preview object {
  width: auto;
  max-width: 100%;
  max-height: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}

.file-link {
  cursor: pointer;
  color: #0c1c3f;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #ecf3ff;
  border: 1px solid #d5e2ff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.file-link:hover {
  text-decoration: underline;
}

/* File link in card header - truncate long filenames */
.card-header .file-link {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}


.status {
  font-weight: 600;
  color: #0b7c6c;
  display: none;
}

/* Side panel viewer - true 50-50 split */
.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50vw;
  background: #ffffff;
  box-shadow: -8px 0 40px rgba(12, 28, 63, 0.25);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.25s ease;
}

.modal.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: #f7fbff;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text);
  font-family: "Space Grotesk", "Manrope", system-ui, sans-serif;
}

.modal-content {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f6fb;
}

.close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ecf3ff;
  color: #0c1c3f;
  border: 1px solid #d5e2ff;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.close:hover {
  background: #dbe7ff;
}

.modal-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ecf3ff;
  color: #0c1c3f;
  border: 1px solid #d5e2ff;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  box-shadow: none;
  padding: 0;
}

.nav-btn:hover:not(:disabled) {
  background: #dbe7ff;
}

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

#modal-body {
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

#modal-body img,
#modal-body iframe,
#modal-body object {
  display: block;
}

#modal-body > img,
#modal-body > iframe,
#modal-body > object,
#modal-body > div {
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(12, 28, 63, 0.15);
}

/* Magnifier lens for document preview */
.magnifier-container {
  position: relative;
  cursor: zoom-in;
}

.magnifier-lens {
  position: absolute;
  width: 225px;
  height: 225px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
  background-repeat: no-repeat;
  background-color: #fff;
}

.magnifier-container:hover .magnifier-lens {
  opacity: 1;
}

.magnifier-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.magnifier-container:not(:hover) .magnifier-hint {
  opacity: 0.7;
}

/* Card highlight when its modal is open */
.card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 122, 89, 0.25), var(--shadow);
}

/* Hide non-active cards when modal is open */
body.modal-open .card:not(.active) {
  display: none;
}

/* Hide hero and first panel (folder tree) when modal is open */
body.modal-open .hero,
body.modal-open main > .panel:first-child,
body.modal-open #admin-panel {
  display: none;
}

/* Hide panel header and merge bar when modal is open */
body.modal-open .panel-head,
body.modal-open .merge-bar {
  display: none !important;
}

/* Make the active card take full width when modal is open */
body.modal-open .results {
  grid-template-columns: 1fr;
}

/* Adjust page layout when modal is open - true 50-50 split */
body.modal-open .page {
  max-width: calc(50vw - 48px);
  margin-left: 24px;
  margin-right: 24px;
  transition: max-width 0.25s ease, margin 0.25s ease;
}

code {
  background: #2c71e0;
  padding: 2px 6px;
  border-radius: 6px;
}

@media (max-width: 1200px) {
  /* Keep 50-50 but reduce padding on medium screens */
  body.modal-open .page {
    max-width: calc(50vw - 32px);
    margin-left: 16px;
    margin-right: 16px;
  }
}

@media (max-width: 900px) {
  /* On smaller screens, modal takes full width and overlays */
  .modal {
    width: 100vw;
    max-width: none;
    min-width: 0;
  }

  body.modal-open .page {
    max-width: none;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 720px) {
  .hero {
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  button {
    width: auto;
  }

  .results {
    grid-template-columns: 1fr;
  }
}

/* Merge bar for driving license documents */
.merge-bar {
  display: none;  /* Hidden by default, shown via JS when there are 2+ driving licenses */
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #f0f7ff 0%, #e6f0ff 100%);
  border: 1px solid #c5d9f7;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(12, 28, 63, 0.08);
}

.merge-info {
  color: #1a4a8c;
  font-weight: 500;
  font-size: 14px;
}

.merge-btn {
  background: linear-gradient(135deg, #4a90d9 0%, #2e6bb8 100%);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(46, 107, 184, 0.3);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.merge-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(46, 107, 184, 0.35);
}

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

/* Merge checkbox in card header */
.merge-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #4a90d9;
  flex-shrink: 0;
}

.merge-checkbox:hover {
  transform: scale(1.1);
}

/* Categories table for driving license */
.categories-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 4px;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.categories-table th,
.categories-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.categories-table th {
  background: #ecf3ff;
  font-weight: 600;
  color: #1a3f7c;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.categories-table td {
  color: var(--text);
  padding: 2px 4px;
}

.categories-table tr:last-child td {
  border-bottom: none;
}

.categories-table tr:hover td {
  background: #f7fbff;
}

/* Editable inputs inside category table cells */
.categories-table input.category-cell {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 6px;
  font-size: 12px;
  color: var(--text);
  border-radius: 4px;
  box-sizing: border-box;
}

.categories-table input.category-cell:read-only {
  cursor: default;
  pointer-events: none;
  user-select: none;
}

/* Re-enable interaction when modal is open (edit mode) */
body.modal-open .categories-table input.category-cell:read-only {
  pointer-events: auto;
  user-select: auto;
}

.categories-table input.category-cell:not(:read-only) {
  border-color: var(--border);
  background: #fff;
  cursor: text;
}

.categories-table input.category-cell:not(:read-only):focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(11, 124, 108, 0.15);
}

.categories-table input.category-cell::placeholder {
  color: #aaa;
}

/* =============================================================================
   Watched Folders & File Browser
   ============================================================================= */

/* Sub-header within panel */
.panel-head.sub-head {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.panel-head.sub-head h2 {
  font-size: 18px;
}

/* Folder List */
.folder-list {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: 180px;
  overflow: auto;
  background: #f7fbff;
}

.folder-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
  border: 1px solid var(--border);
  transition: background 0.15s ease;
}

.folder-row:last-child {
  margin-bottom: 0;
}

.folder-row:hover {
  background: #f0f5ff;
}

.folder-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.folder-name {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.folder-path {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-count {
  font-size: 11px;
  color: var(--pill);
  font-weight: 500;
}

.folder-remove-btn {
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 14px;
  box-shadow: none;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}

.folder-row:hover .folder-remove-btn {
  opacity: 1;
}

.folder-remove-btn:hover {
  color: #b00020;
  background: rgba(176, 0, 32, 0.08);
}

/* File Browser */
.file-browser {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: 300px;
  overflow: auto;
  background: #f7fbff;
}

.browser-folder {
  margin-bottom: 8px;
}

.browser-folder:last-child {
  margin-bottom: 0;
}

.browser-folder-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.browser-folder-header:hover {
  background: #f0f5ff;
}

.browser-folder-header .folder-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.expand-icon {
  font-size: 10px;
  color: var(--muted);
  width: 12px;
  transition: transform 0.15s ease;
}

.browser-folder-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  flex: 1;
}

.stats-badges {
  display: flex;
  gap: 6px;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.stat-badge.stat-new {
  background: #e5e7eb;
  color: #4b5563;
}

.stat-badge.stat-extracted {
  background: #d1fae5;
  color: #059669;
}

.stat-badge.stat-modified {
  background: #fef3c7;
  color: #d97706;
}

/* File list (hidden by default) */
.browser-file-list {
  display: none;
  margin-top: 4px;
  margin-left: 24px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}

.browser-folder.expanded .browser-file-list {
  display: block;
}

.browser-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.15s ease;
}

.browser-file-row:hover {
  background: rgba(255, 255, 255, 0.8);
}

.browser-file-row .file-checkbox {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.status-icon {
  font-size: 12px;
  width: 16px;
  text-align: center;
}

.status-icon.status-new { color: #6b7280; }
.status-icon.status-extracted { color: #059669; }
.status-icon.status-modified { color: #d97706; }
.status-icon.status-deleted { color: #dc2626; }

.browser-file-name {
  flex: 1;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browser-doc-type {
  font-size: 11px;
  color: var(--pill);
  background: rgba(15, 185, 177, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Status row styling */
.browser-file-row.status-new { opacity: 0.8; }
.browser-file-row.status-deleted .browser-file-name {
  opacity: 0.5;
  text-decoration: line-through;
}
.browser-file-row.status-deleted .browser-doc-type {
  opacity: 0.5;
}

/* Browser footer */
.browser-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.status-legend {
  display: flex;
  gap: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.status-new { background: #6b7280 !important; }
.status-dot.status-extracted { background: #059669 !important; }
.status-dot.status-modified { background: #d97706 !important; }
.status-dot.status-deleted { background: #dc2626 !important; }

/* Panel footer actions */
.panel-footer-actions {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

button.small {
  padding: 8px 12px;
  font-size: 13px;
}

/* Empty hints */
.empty-hint {
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

/* =============================================================================
   Add Folder Modal
   ============================================================================= */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(12, 28, 63, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-dialog {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 64px rgba(12, 28, 63, 0.3);
}

.modal-dialog h3 {
  margin: 0 0 8px;
  font-family: "Space Grotesk", "Manrope", system-ui, sans-serif;
  font-size: 20px;
}

.modal-hint {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.modal-dialog input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f7fbff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal-dialog input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 122, 89, 0.15);
}

.validation-msg {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 20px;
}

.validation-msg.error {
  color: #b00020;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

button.secondary {
  background: #ecf3ff;
  color: #0c1c3f;
  box-shadow: none;
  border: 1px solid #d5e2ff;
}

button.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
}

/* =============================================================================
   Folder Browser Dialog
   ============================================================================= */

.browser-dialog {
  max-width: 560px;
}

.browser-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.browser-nav input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  font-size: 13px;
  font-family: monospace;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7fbff;
  color: var(--text);
}

.browser-nav input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.browser-nav-btn {
  padding: 10px 14px;
  font-size: 14px;
  background: #ecf3ff;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
  min-width: 42px;
}

.browser-nav-btn:hover:not(:disabled) {
  background: #dce8ff;
}

.browser-nav-btn:disabled {
  opacity: 0.4;
}

.folder-browser-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f7fbff;
  max-height: 300px;
  min-height: 200px;
  overflow: auto;
  padding: 6px;
}

.folder-browser-list .hint {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.browser-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  user-select: none;
}

.browser-item:hover {
  background: #e8f0ff;
}

.browser-item.selected {
  background: #d0e3ff;
  border: 1px solid #a0c4ff;
}

.browser-item-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.browser-item-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.browser-item-count {
  font-size: 12px;
  color: var(--pill);
  background: rgba(15, 185, 177, 0.1);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

/* =============================================================================
   Authentication Styles
   ============================================================================= */

/* Login dialog */
.login-dialog {
  max-width: 380px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select {
  width: 100%;
  padding: 12px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f7fbff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 122, 89, 0.15);
}

.form-group input:disabled {
  background: #e8eef5;
  color: var(--muted);
  cursor: not-allowed;
}

.form-group.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}

.form-group.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

button.full-width {
  width: 100%;
}

/* User menu in header */
.user-menu {
  position: relative;
}

.user-menu-btn {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease;
  box-shadow: none;
}

.user-menu-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: none;
}

.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  min-width: 180px;
  box-shadow: 0 12px 36px rgba(12, 28, 63, 0.2);
  z-index: 100;
}

.dropdown.hidden {
  display: none;
}

.dropdown button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.15s ease;
}

.dropdown button:hover {
  background: #f0f5ff;
  transform: none;
}

.dropdown button.logout {
  color: #b00020;
}

.dropdown button.logout:hover {
  background: #fff0f0;
}

.dropdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* =============================================================================
   Admin Panel Styles
   ============================================================================= */

/* Users list */
.users-list {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: 400px;
  overflow: auto;
  background: #f7fbff;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: #fff;
  border: 1px solid var(--border);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.user-row:last-child {
  margin-bottom: 0;
}

.user-row:hover {
  background: #f8fbff;
  box-shadow: 0 2px 8px rgba(12, 28, 63, 0.08);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.user-username {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.user-email {
  font-size: 13px;
  color: var(--muted);
}

.user-badges {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.user-badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.user-badge.admin {
  background: #e3f2fd;
  color: #1565c0;
}

.user-badge.user {
  background: #f3e5f5;
  color: #7b1fa2;
}

.user-badge.inactive {
  background: #fafafa;
  color: #757575;
}

.user-badge.locked {
  background: #ffebee;
  color: #c62828;
}

.user-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Audit filters */
.audit-filters {
  display: flex;
  gap: 12px;
  align-items: center;
}

.audit-filters select {
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7fbff;
  color: var(--text);
  cursor: pointer;
}

.audit-filters select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Audit log list */
.audit-log-list {
  margin-top: 12px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 10px;
  max-height: 400px;
  overflow: auto;
  background: #f7fbff;
}

.audit-entry {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 13px;
  transition: background 0.15s ease;
}

.audit-entry:last-child {
  margin-bottom: 0;
}

.audit-entry:hover {
  background: #f8fbff;
}

.audit-entry.failed {
  background: #fff8f8;
  border-color: #ffcdd2;
}

.audit-entry .timestamp {
  color: var(--muted);
  font-size: 12px;
  min-width: 140px;
}

.audit-entry .event-type {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.audit-entry .event-type.auth {
  background: #e8f5e9;
  color: #2e7d32;
}

.audit-entry .event-type.data {
  background: #e3f2fd;
  color: #1565c0;
}

.audit-entry .event-type.admin {
  background: #fff3e0;
  color: #ef6c00;
}

.audit-entry .action {
  font-weight: 600;
  color: var(--text);
}

.audit-entry .user {
  color: #1565c0;
  font-weight: 500;
}

.audit-entry .details {
  color: var(--muted);
  flex: 1;
  text-align: right;
}

.audit-entry .error-message {
  color: #c62828;
  font-size: 12px;
  display: block;
  width: 100%;
  margin-top: 4px;
}

/* Usage Stats Table - using separate tables for fixed header/footer */
.usage-stats {
  padding: 0 20px 20px;
  overflow: visible;
}

.usage-table-container {
  display: flex;
  flex-direction: column;
  max-height: 400px;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

/* Column widths - must match across all three tables */
.usage-table th:nth-child(1),
.usage-table td:nth-child(1) { width: 15%; } /* Data/Ora */
.usage-table th:nth-child(2),
.usage-table td:nth-child(2) { width: 12%; } /* Utilizator */
.usage-table th:nth-child(3),
.usage-table td:nth-child(3) { width: 25%; } /* Fișier */
.usage-table th:nth-child(4),
.usage-table td:nth-child(4) { width: 15%; } /* Tip document */
.usage-table th:nth-child(5),
.usage-table td:nth-child(5) { width: 11%; } /* Tokeni in */
.usage-table th:nth-child(6),
.usage-table td:nth-child(6) { width: 11%; } /* Tokeni out */
.usage-table th:nth-child(7),
.usage-table td:nth-child(7) { width: 11%; } /* Cost */

.usage-table-header {
  flex-shrink: 0;
}

.usage-table-body-wrapper {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.usage-table-footer {
  flex-shrink: 0;
}

.usage-table th,
.usage-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.usage-table th {
  background: var(--bg-muted);
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.usage-table td {
  color: var(--text);
}

.usage-table td.total {
  font-weight: 600;
  color: var(--accent);
}

.usage-table-body tbody tr:hover {
  background: var(--bg-muted);
}

.usage-table-footer tfoot td {
  background: #f0f7f5;
  border-top: 2px solid var(--accent);
  border-bottom: none;
  font-weight: 500;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.pagination .page-info {
  font-size: 13px;
  color: var(--muted);
}

/* Error text in forms */
.validation-msg.error {
  color: #b00020;
}

.validation-msg.error.hidden {
  display: none;
}

/* Responsive adjustments for admin panel */
@media (max-width: 720px) {
  .user-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .user-actions {
    width: 100%;
    justify-content: flex-start;
    margin-top: 8px;
  }

  .audit-entry {
    flex-direction: column;
    align-items: flex-start;
  }

  .audit-entry .details {
    text-align: left;
  }
}
