:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1e222b;
  --surface-3: #262b36;
  --border: #2d3340;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --accent: #4c8dff;
  --accent-dim: #2a3550;
  --danger: #ff6b6b;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

a { color: var(--accent); }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, #14171e, #0f1115);
  border-bottom: 1px solid var(--border);
}
.app-header-inner {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 14px 20px 6px;
}
.app-header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.app-meta { color: var(--text-dim); font-size: 12px; }
.mount-warning {
  margin: 0 20px 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #3a2418;
  border: 1px solid #8a5a2b;
  color: #f5d7a8;
  font-size: 13px;
}
.mount-warning code { font-size: 12px; }
.tabs { display: flex; gap: 4px; padding: 0 16px; }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 18px 20px 60px; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.filter-card { margin-bottom: 18px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.filter-row + .filter-row { margin-top: 12px; }
.filter-field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.filter-field.grow { flex: 1 1 320px; }
.filter-field.push-right { margin-left: auto; min-width: 0; }
.filter-field label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.filter-field .hint { font-size: 11px; color: var(--text-dim); }
input[type="text"], input[type="date"], select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input[type="date"] { color-scheme: dark; }
.filter-status { margin-top: 12px; font-size: 12px; color: var(--text-dim); }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.small { padding: 4px 10px; font-size: 11px; }

.tree-node { margin: 2px 0; }
.tree-children { margin-left: 18px; border-left: 1px solid var(--border); padding-left: 8px; }
.folder-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; user-select: none;
}
.folder-row:hover { background: var(--surface-2); }
.folder-caret { width: 14px; display: inline-block; transition: transform 0.12s ease; color: var(--text-dim); }
.tree-node.is-open > .folder-row > .folder-caret { transform: rotate(90deg); }
.folder-name { font-weight: 500; }
.folder-count { margin-left: auto; font-size: 12px; color: var(--text-dim); background: var(--surface-3); border-radius: 999px; padding: 1px 9px; }
.folder-body { display: none; padding: 8px 0 6px; }
.tree-node.is-open > .folder-body { display: block; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
table.img-table { border-collapse: collapse; width: 100%; min-width: 980px; }
.img-table th, .img-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.img-table thead th {
  position: sticky; top: 0; background: var(--surface-3); font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); cursor: pointer; white-space: nowrap; z-index: 1;
}
.img-table thead th.no-sort { cursor: default; }
.img-table tbody tr { cursor: pointer; }
.img-table tbody tr:hover { background: var(--surface-2); }
.thumb-cell { width: 80px; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; background: var(--surface-3); display: block; }
.thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 10px; text-align: center; }
.thumb.file-type-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.1;
  text-align: center;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.thumb.file-type-icon.type-pdf { background: #3d1515; color: #ffb4b4; }
.thumb.file-type-icon.type-doc { background: #15284d; color: #b4d4ff; }
.thumb.file-type-icon.type-sheet { background: #143d24; color: #b4ffcf; }
.thumb.file-type-icon.type-slide { background: #4d3015; color: #ffd4a8; }
.thumb.file-type-icon.type-video { background: #2d154d; color: #d4b4ff; }
.thumb.file-type-icon.type-archive { background: #3d3d15; color: #fff3b4; }
.thumb.file-type-icon.type-web { background: #153d3d; color: #b4ffff; }
.thumb.file-type-icon.type-image { background: #1f2a3d; color: #c8d9f0; }
.thumb.file-type-icon.type-other { background: var(--surface-3); color: var(--text-dim); }
.cell-path, .cell-desc { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.kw-chip { display: inline-block; background: var(--accent-dim); color: #cdd9f5; border-radius: 999px; padding: 1px 8px; margin: 1px 2px; font-size: 11px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty-state { padding: 40px; text-align: center; color: var(--text-dim); }
.results-summary { margin: 0 0 12px; color: var(--text-dim); font-size: 13px; }
.match-reason { font-size: 11px; color: var(--text-dim); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.72); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100; }
.modal-overlay[hidden] { display: none; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); max-width: 1100px; width: 100%; max-height: 90vh; overflow: hidden; position: relative; }
.modal-close { position: absolute; top: 8px; right: 12px; background: transparent; border: none; color: var(--text-dim); font-size: 28px; cursor: pointer; z-index: 2; }
.modal-body { display: grid; grid-template-columns: 1.4fr 1fr; max-height: 90vh; }
.modal-image-wrap { background: #0b0d11; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.modal-image-stage { position: relative; display: inline-block; max-width: 100%; max-height: calc(90vh - 32px); }
.modal-image-stage img { display: block; max-width: 100%; max-height: calc(90vh - 32px); width: auto; height: auto; object-fit: contain; border-radius: 6px; }
.face-overlay { position: absolute; inset: 0; pointer-events: none; }
.face-overlay:not([hidden]) { pointer-events: auto; }
.face-box {
  position: absolute;
  border: 2px solid rgba(96, 165, 250, 0.9);
  border-radius: 4px;
  background: rgba(96, 165, 250, 0.12);
  cursor: pointer;
  box-sizing: border-box;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.face-box.is-identified { border-color: rgba(74, 222, 128, 0.95); background: rgba(74, 222, 128, 0.14); }
.face-box:hover, .face-box.is-active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35); }
.face-box-index {
  position: absolute;
  top: -1px;
  left: -1px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 4px 0 4px 0;
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}
.face-box-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 4px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.face-tag-popover {
  position: fixed;
  z-index: 120;
  width: min(280px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.face-tag-popover[hidden] { display: none; }
.face-tag-popover-title { margin: 0 0 10px; font-size: 13px; font-weight: 600; }
.face-tag-label { display: block; margin-bottom: 4px; font-size: 11px; color: var(--text-dim); }
.face-tag-select, .face-tag-input {
  width: 100%;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
}
.face-tag-popover-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.face-tag-new-row { margin-bottom: 4px; }
.face-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 12px; }
.face-row.is-active { background: var(--surface-3); border-radius: 6px; padding: 4px 6px; margin-left: -6px; margin-right: -6px; }
.face-index-badge {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}
.face-row-label { flex: 1 1 auto; min-width: 0; }
.modal-info { padding: 20px 22px; overflow-y: auto; }
.modal-info h2 { margin: 0 0 8px; font-size: 16px; word-break: break-word; }
.modal-toolbar { margin-bottom: 12px; }
.modal-edit-panel {
  margin: 16px 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.edit-section-title { margin: 0 0 12px; font-size: 14px; }
.edit-inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.edit-tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 28px; }
.edit-tag-list .kw-chip { display: inline-flex; align-items: center; gap: 6px; }
.edit-tag-list button {
  border: none;
  background: transparent;
  color: #cdd9f5;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.tag-source {
  font-size: 10px;
  opacity: 0.7;
  text-transform: uppercase;
}
.edit-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.face-edit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 6px 0;
  font-size: 12px;
}
.face-edit-row select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  min-width: 160px;
}
.meta-grid { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; margin: 0 0 18px; }
.meta-grid dt { color: var(--text-dim); font-size: 12px; text-transform: uppercase; }
.meta-grid dd { margin: 0; word-break: break-word; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.modal-links-heading { font-size: 13px; margin: 12px 0 6px; color: var(--text); }
.modal-links-list { margin: 0 0 8px; padding-left: 18px; font-size: 13px; }
.modal-links-list a { color: var(--accent); text-decoration: none; }
.modal-links-list a:hover { text-decoration: underline; }
.modal-links-meta { color: var(--text-dim); font-size: 12px; }
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  outline: none;
  resize: vertical;
  font-family: inherit;
}
textarea:focus { border-color: var(--accent); }

.people-card { padding: 16px 18px; }
.people-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  margin-bottom: 18px;
}
.people-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.people-grid.empty-state {
  display: block;
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}
.person-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  width: 100%;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.person-tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.person-tile-photo {
  aspect-ratio: 1;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.person-tile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.person-tile-photo .placeholder {
  color: var(--text-dim);
  font-size: 28px;
  font-weight: 600;
}
.person-tile-info { padding: 10px 12px 12px; }
.person-tile-name {
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
  margin-bottom: 4px;
}
.person-tile-meta {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.35;
}

.enroll-modal { max-width: 720px; }
.enroll-modal-body { padding: 22px 24px 24px; overflow-y: auto; max-height: 90vh; }
.enroll-modal-body h2 { margin: 0 0 8px; font-size: 18px; }
.enroll-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.drop-zone {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 22px 16px;
  text-align: center;
  background: var(--surface-2);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.drop-zone.is-dragover {
  border-color: var(--accent);
  background: #1a2438;
}
.drop-zone p { margin: 0 0 6px; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
}
.enroll-photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.enroll-photo-chip {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-3);
}
.enroll-photo-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.enroll-photo-chip button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

@media (max-width: 820px) {
  .modal-body { grid-template-columns: 1fr; }
}
