/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  background: #e8e8e8;
  color: #000;
  min-height: 100vh;
}

/* ── Landing Page ─────────────────────────────────────────────── */
.landing-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px;
  gap: 24px;
}

.landing-header {
  display: flex;
  align-items: center;
  gap: 20px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 16px 24px;
  width: 100%;
  max-width: 700px;
}

.landing-header img { height: 50px; object-fit: contain; }
.landing-header h1 { flex: 1; text-align: center; font-size: 20px; color: #333; }

.create-panel {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 24px;
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.create-panel h2 { font-size: 15px; color: #444; border-bottom: 1px solid #eee; padding-bottom: 8px; }

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 11px; font-weight: bold; color: #666; text-transform: uppercase; letter-spacing: 0.5px; }

select, input[type="date"] {
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
  min-width: 160px;
}

select:focus, input[type="date"]:focus { outline: 2px solid #0078d4; border-color: #0078d4; }

.btn {
  padding: 9px 18px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary { background: #0078d4; color: #fff; }
.btn-primary:hover { background: #006abc; }
.btn-danger { background: #d13438; color: #fff; }
.btn-danger:hover { background: #b02e32; }
.btn-secondary { background: #f0f0f0; color: #333; border: 1px solid #ccc; }
.btn-secondary:hover { background: #e4e4e4; }

.records-panel {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 24px;
  width: 100%;
  max-width: 700px;
}

.records-panel h2 { font-size: 15px; color: #444; border-bottom: 1px solid #eee; padding-bottom: 8px; margin-bottom: 14px; }

.record-list { display: flex; flex-direction: column; gap: 8px; }

.record-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  background: #fafafa;
}

.record-item:hover { background: #f0f4ff; border-color: #0078d4; }

.record-badge {
  background: #0078d4;
  color: #fff;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: bold;
  min-width: 42px;
  text-align: center;
}

.record-date { font-weight: bold; color: #333; min-width: 90px; }
.record-name { flex: 1; color: #555; font-size: 12px; }
.record-actions { display: flex; gap: 6px; }

.empty-msg { color: #999; font-style: italic; padding: 12px 0; text-align: center; }

/* ── Document Page ────────────────────────────────────────────── */
.doc-body { background: #e8e8e8; padding: 0; }

.toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #333;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
}

.toolbar .btn-tool {
  padding: 6px 14px;
  border: 1px solid #555;
  border-radius: 3px;
  background: #444;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.toolbar .btn-tool:hover { background: #555; }
.toolbar .btn-tool.primary { background: #0078d4; border-color: #006abc; }
.toolbar .btn-tool.primary:hover { background: #006abc; }

.toolbar-title { flex: 1; text-align: center; font-size: 13px; color: #ccc; }

/* ── Document Wrapper ─────────────────────────────────────────── */
.document-wrapper {
  padding: 16px;
  min-width: 0;
}

.document {
  background: #fff;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

/* ── Doc Header ───────────────────────────────────────────────── */
.doc-header {
  display: grid;
  grid-template-columns: 140px 1fr 160px;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 2px solid #999;
  gap: 8px;
}

.header-logo-left img {
  height: 60px;
  object-fit: contain;
  display: block;
}

.header-title {
  text-align: center;
  font-size: 24px;
  font-weight: bold;
  color: #222;
  line-height: 1.2;
}

.header-logo-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.header-logo-right img {
  height: 50px;
  object-fit: contain;
}

.header-subtitle {
  font-size: 10px;
  color: #666;
  text-align: right;
  letter-spacing: 0.5px;
}

/* ── Gray Bar ─────────────────────────────────────────────────── */
.gray-bar {
  background: #d0d0d0;
  height: 28px;
  border-bottom: 1px solid #aaa;
}

/* ── Table ────────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  min-width: 1100px;
}

.data-table th {
  background: #e8e8e8;
  border: 1px solid #999;
  padding: 7px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  vertical-align: middle;
  line-height: 1.3;
}

.data-table td {
  border: 1px solid #999;
  padding: 6px 8px;
  vertical-align: top;
  font-size: 12px;
  line-height: 1.4;
  word-wrap: break-word;
  min-height: 50px;
}

/* Column widths */
.col-marke    { width: 7%; }
.col-standort { width: 12%; }
.col-auftr    { width: 9%; }
.col-tor      { width: 7%; }
.col-typ      { width: 8%; }
.col-bj       { width: 5%; }
.col-funktion { width: 18%; }
.col-flucht   { width: 8%; text-align: center; }
.col-handlung { width: 13%; }
.col-festgest { width: 13%; }

.data-table td.col-flucht { text-align: center; }

/* Editable cells */
.editable-cell {
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}

.editable-cell:hover { background: #eef4ff; }
.editable-cell:hover::after {
  content: '✎';
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 11px;
  color: #0078d4;
  opacity: 0.7;
}

.cell-value { white-space: pre-wrap; }
.cell-value.bold { font-weight: bold; }

/* Standort cell image */
.standort-img {
  display: block;
  max-width: 100%;
  max-height: 80px;
  object-fit: contain;
  margin-top: 4px;
  cursor: pointer;
}

.standort-upload-btn {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 6px;
  font-size: 10px;
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 3px;
  cursor: pointer;
  color: #555;
}
.standort-upload-btn:hover { background: #e0e8ff; border-color: #0078d4; color: #0078d4; }

/* Field images (handlungsbedarf/festgestellt) */
.field-images {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.field-img-wrap {
  position: relative;
  display: inline-block;
}

.field-img-wrap img {
  width: 48px;
  height: 40px;
  object-fit: cover;
  border: 1px solid #ccc;
  border-radius: 2px;
  cursor: pointer;
  display: block;
}

.field-img-wrap .del-img {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  background: #d13438;
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}
.field-img-wrap:hover .del-img { display: flex; }

/* ── Edit Overlay ─────────────────────────────────────────────── */
.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.edit-panel {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.edit-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid #eee;
}

.edit-panel-header h3 { font-size: 14px; color: #333; }

.edit-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
  line-height: 1;
  padding: 0 4px;
}
.edit-close:hover { color: #d13438; }

.edit-panel-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-btn {
  padding: 7px 14px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #f5f5f5;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 36px;
}
.quick-btn:hover { background: #e0e8ff; border-color: #0078d4; color: #0078d4; }
.quick-btn.active { background: #0078d4; border-color: #0078d4; color: #fff; font-weight: bold; }

.edit-textarea {
  width: 100%;
  min-height: 80px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
.edit-textarea:focus { outline: 2px solid #0078d4; border-color: #0078d4; }

.img-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: #f5f5f5;
  border: 1px dashed #aaa;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: #555;
  transition: all 0.15s;
}
.img-upload-label:hover { background: #e0e8ff; border-color: #0078d4; color: #0078d4; }

.edit-thumbnails {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.edit-thumb-wrap {
  position: relative;
}

.edit-thumb-wrap img {
  width: 64px;
  height: 52px;
  object-fit: cover;
  border: 1px solid #ddd;
  border-radius: 3px;
  display: block;
  cursor: pointer;
}

.edit-thumb-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  background: #d13438;
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.edit-panel-footer {
  padding: 10px 16px 14px;
  display: flex;
  gap: 8px;
  border-top: 1px solid #eee;
}

/* ── Doc Footer ───────────────────────────────────────────────── */
.doc-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  border-top: 1px solid #aaa;
  font-size: 11px;
  color: #555;
  background: #f8f8f8;
}

/* ── Image Lightbox ───────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 4px; }

/* ── Utility ──────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: #999; font-style: italic; }
.saving-indicator {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: #333;
  color: #fff;
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 12px;
  z-index: 400;
  transition: opacity 0.3s;
}
.saving-indicator.hidden { display: none; }

/* ── iPad / Touch adjustments ─────────────────────────────────── */
@media (max-width: 768px) {
  .doc-header { grid-template-columns: 90px 1fr 100px; }
  .header-title { font-size: 16px; }
  .header-logo-left img { height: 42px; }
  .header-logo-right img { height: 36px; }
  .quick-btn { min-height: 44px; padding: 10px 14px; }
  .edit-panel { max-width: 100%; }
  .toolbar .btn-tool { padding: 8px 12px; min-height: 40px; }
}
