:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #ede9df;
  --text: #22261e;
  --muted: #666c5f;
  --primary: #3b5e3c;
  --primary-hover: #2d492e;
  --accent: #9c6631;
  --danger: #b43c32;
  --border: #dcd6c8;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(34, 38, 30, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

.topbar {
  background: #273826;
  color: #f8f6f0;
  padding: 0.75rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 1100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.18);
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-icon { font-size: 1.9rem; }
.brand h1 { margin: 0; font-size: 1.2rem; font-weight: 650; }
.subtitle { margin: 0; font-size: 0.78rem; color: #c7d1c3; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tab-btn {
  background: rgba(255,255,255,0.1);
  color: #f0eee8;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s;
}
.tab-btn:hover { background: rgba(255,255,255,0.2); }
.tab-btn.active { background: #e8e2d2; color: #1f2d1e; font-weight: 650; }

.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

.topbar-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.user-menu {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.user-btn {
  background: rgba(255,255,255,0.13);
  color: #f4f1ea;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 0.34rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.user-btn:hover { background: rgba(255,255,255,0.22); }

.lang-switcher {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0.15rem;
  gap: 0.15rem;
}

.lang-btn {
  background: transparent;
  color: #d8dfd4;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.52rem;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s;
}
.lang-btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.lang-btn.active { background: #e8e2d2; color: #1f2d1e; }

.container { max-width: 1460px; margin: 1.1rem auto; padding: 0 1.2rem 2.5rem; }

/* Auth Screen */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at top, #e7e2d5 0%, var(--bg) 55%);
}
.auth-topbar {
  position: fixed;
  top: 1rem;
  right: 1.25rem;
  background: #273826;
  padding: 0.3rem;
  border-radius: 10px;
}
.auth-card {
  width: min(440px, 100%);
  padding: 1.6rem 1.7rem;
}
.auth-header {
  text-align: center;
  margin-bottom: 1.2rem;
}
.auth-header h1 { margin: 0.25rem 0 0.2rem; font-size: 1.45rem; }
.auth-error {
  background: #f9e2e0;
  color: #8c231c;
  border: 1px solid #e6b7b3;
  border-radius: 7px;
  padding: 0.5rem 0.75rem;
  font-size: 0.86rem;
  margin-top: 0.5rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
}
.kpi-label { display: block; font-size: 0.78rem; color: var(--muted); }
.kpi-value { font-size: 1.45rem; color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.filter-bar input[type="search"] { flex: 2 1 220px; }
.filter-bar select { flex: 1 1 130px; }

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.65rem;
  background: #edf3ec;
  border-color: #b7ceb5;
  padding: 0.65rem 1rem;
}

input, select, textarea {
  font: inherit;
  padding: 0.48rem 0.68rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}
input:disabled, select:disabled, textarea:disabled {
  background: #f3f1eb;
  color: #555b50;
}
input[type="checkbox"] { width: auto; padding: 0; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(59, 94, 60, 0.35);
  border-color: var(--primary);
}

.btn {
  font: inherit;
  padding: 0.48rem 0.9rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.84rem; }

.view-toggle { display: flex; gap: 0.3rem; }
.results-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.5rem 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.pager { display: flex; align-items: center; gap: 0.5rem; }

.table-wrap { padding: 0; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.89rem; }
.data-table th, .data-table td {
  padding: 0.58rem 0.72rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.data-table th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.data-table tbody tr { cursor: pointer; transition: background 0.12s; }
.data-table tbody tr:hover { background: #f2efe7; }

.thumb-mini {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
  display: block;
}
.thumb-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1.1rem;
}

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}
.st-sequenziert { background: #d5ebd8; color: #1d5727; }
.st-mikroskopiert { background: #dce8f5; color: #1e4b7a; }
.st-vorläufig { background: #f4ead2; color: #7a5713; }
.st-unreif { background: #ece6dc; color: #5b5449; }
.st-unbestimmt { background: #e8e6e1; color: #555; }
.st-fehlgeschlagen { background: #f6d8d6; color: #8c231c; }

.access-pill {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  background: #e9e4d7;
  color: #4b473d;
}
.access-owner { background: #dce9db; color: #244b26; }
.access-edit { background: #dce8f5; color: #1e4b7a; }
.access-read { background: #f3ead3; color: #7a5713; }

.code-pill {
  font-family: Consolas, monospace;
  font-size: 0.82rem;
  background: var(--surface-2);
  padding: 0.12rem 0.42rem;
  border-radius: 5px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.9rem;
}
.find-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s;
}
.find-card:hover { transform: translateY(-2px); }
.find-card-img { width: 100%; height: 170px; object-fit: cover; background: var(--surface-2); display: block; }
.find-card-body { padding: 0.75rem; }
.find-card-body h3 { margin: 0.3rem 0; font-size: 1rem; font-style: italic; }

.map-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}
.legend { display: flex; gap: 1rem; font-size: 0.85rem; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 0.25rem; }
.dot-seq { background: #2d8a43; }
.dot-mikro { background: #2b6cb0; }
.dot-vorl { background: #c58429; }
.map-box { height: 68vh; min-height: 460px; padding: 0; overflow: hidden; position: relative; z-index: 1; isolation: isolate; }
.mini-map { height: 240px; border: 1px solid var(--border); border-radius: 8px; position: relative; z-index: 1; isolation: isolate; }

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.85rem;
}
.section-header h2 { margin: 0; font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: 0.83rem; }
.actions-row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}
.full-span { grid-column: 1 / -1; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 0.25rem; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; }
.field input[type="checkbox"] { width: auto; }
.checkbox-row label { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; cursor: pointer; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1rem; }
.sync-buttons { display: flex; flex-direction: column; gap: 0.5rem; margin: 0.85rem 0; }
.sync-status-box { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.85rem; }
.progress-header { display: flex; justify-content: space-between; margin-bottom: 0.4rem; }
.progress-bar { height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.3s; }
.sync-log {
  background: #1d221c;
  color: #d6e2d3;
  padding: 0.6rem;
  border-radius: 6px;
  font-size: 0.76rem;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
}

.export-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.85rem; }
.export-card {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
}
.export-card:hover { border-color: var(--primary); background: #eef3ec; }
.export-card span { font-size: 0.83rem; color: var(--muted); }

.inbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 0.85rem;
}
.inbox-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.inbox-card img { width: 100%; height: 150px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }

/* Sharing, Comments, History */
.sub-card {
  margin-top: 1rem;
  background: #f8f6f0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem;
}
.share-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.45rem 0;
}
.share-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
}
.share-chip button {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}
.comment-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.55rem 0.75rem;
  margin-bottom: 0.45rem;
}
.comment-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.history-item {
  font-size: 0.79rem;
  padding: 0.32rem 0;
  border-bottom: 1px dashed var(--border);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.48); }
.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1;
}

/* Drawer */
.drawer { position: fixed; inset: 0; z-index: 2000; display: flex; justify-content: flex-end; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.42); }
.drawer-panel {
  position: relative;
  width: min(760px, 100vw);
  height: 100%;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.2);
}
.drawer-header {
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
}
.drawer-header h2 { margin: 0.25rem 0 0; font-size: 1.2rem; font-style: italic; }
.drawer-body { padding: 1.1rem 1.2rem; overflow-y: auto; flex: 1; }

.gallery-section { margin-top: 1rem; }
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 0.55rem;
  margin-top: 0.4rem;
}
.gallery-item {
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  background: var(--bg);
  font-size: 0.76rem;
}
.gallery-item img { width: 100%; height: 105px; object-fit: cover; cursor: zoom-in; display: block; }
.gallery-item-meta { padding: 0.35rem 0.45rem; word-break: break-word; }

.media-download-tile {
  height: 105px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  background: var(--surface-2);
  color: var(--primary);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.media-download-tile:hover {
  background: #e1ebde;
  color: var(--primary-hover);
}
.media-download-tile-lg {
  height: 150px;
  border-radius: 6px;
}
.media-download-icon {
  width: 28px;
  height: 28px;
}
.media-ext-badge {
  font-family: Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  padding: 0.08rem 0.42rem;
  border-radius: 4px;
  letter-spacing: 0.04em;
}
.media-size-label {
  font-size: 0.71rem;
  color: var(--muted);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(15, 17, 14, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  color: #fff;
}
.lightbox img { max-width: 92vw; max-height: 82vh; border-radius: 8px; }
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.2rem;
  font-size: 1.4rem;
  background: rgba(255,255,255,0.16);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.hidden { display: none !important; }
