/* ============================================================
   GeoScan Analyzer – Main Stylesheet
   Designed for readability (elderly-friendly, large fonts/buttons)
   ============================================================ */

:root {
  --primary:      #1d4ed8;
  --primary-dark: #1e3a8a;
  --primary-light:#dbeafe;
  --success:      #16a34a;
  --warning:      #d97706;
  --error:        #dc2626;
  --bg:           #f1f5f9;
  --card:         #ffffff;
  --border:       #cbd5e1;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --header-bg:    #0f172a;
  --radius:       10px;
  --shadow:       0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.18);

  /* Signal intensity colours */
  --sig-very-high: #dc2626;
  --sig-high:      #ea580c;
  --sig-medium:    #ca8a04;
  --sig-low:       #16a34a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

/* ---- Typography ---- */
h1 { font-size: 2rem;   font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 600; }
h3 { font-size: 1.2rem; font-weight: 600; }
p  { margin-bottom: .5rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.2rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover  { background: var(--primary-dark); }

.btn-secondary { background: #e2e8f0; color: var(--text); border-color: #e2e8f0; }
.btn-secondary:hover { background: #cbd5e1; }

.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }

.btn-large { padding: .8rem 1.8rem; font-size: 1.1rem; min-height: 52px; }
.btn-sm    { padding: .35rem .9rem; font-size: .9rem; }

/* ---- Forms ---- */
.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: .3rem;
  font-size: 1rem;
}
.field-input {
  width: 100%;
  padding: .75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.1rem;
  margin-bottom: 1rem;
  transition: border-color .15s;
}
.field-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---- Alerts ---- */
.alert {
  padding: .8rem 1.2rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-weight: 500;
}
.alert-error   { background: #fef2f2; color: var(--error);   border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
.alert-warn    { background: #fffbeb; color: var(--warning); border: 1px solid #fde68a; }

/* ---- Language buttons ---- */
.lang-btn {
  padding: .3rem .8rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: transparent;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-muted);
  transition: all .15s;
}
.lang-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ---- KI Status Badge ---- */
.ki-status {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .8rem;
  border-radius: 20px;
  background: #1e293b;
  border: 1px solid #334155;
  cursor: default;
}
.ki-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #475569;
  flex-shrink: 0;
  transition: background .3s;
}
.ki-dot.available   { background: #22c55e; box-shadow: 0 0 6px #22c55e88; }
.ki-dot.unavailable { background: #ef4444; }
.ki-label { font-size: .85rem; color: #94a3b8; white-space: nowrap; }

/* ---- Anomaly Summary Table ---- */
.summary-panel { margin-bottom: 1.2rem; }
.table-wrap { overflow-x: auto; }

.anomaly-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}
.anomaly-table th {
  background: var(--primary-dark);
  color: #e2e8f0;
  padding: .7rem 1rem;
  text-align: left;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.anomaly-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 1rem;
}
.anomaly-table tr:last-child td { border-bottom: none; }
.anomaly-table tr:hover td { background: #f8fafc; }

.anomaly-table .num-cell {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
  width: 40px;
}
.anomaly-table .metric {
  font-weight: 700;
  font-size: 1.05rem;
}
.anomaly-table .unit {
  font-size: .8rem;
  color: var(--text-muted);
  margin-left: .2rem;
}
.anomaly-table .ai-btn-sm {
  padding: .3rem .7rem;
  font-size: .85rem;
  white-space: nowrap;
}
.anomaly-table .ai-result-cell {
  font-size: .88rem;
  max-width: 180px;
}
.ai-cell-type   { font-weight: 700; }
.ai-cell-conf   { font-size: .78rem; color: var(--text-muted); }
.ai-table-result {
  font-weight: 600;
  font-size: .9rem;
  color: var(--primary);
}
.anomaly-card.highlighted {
  outline: 2px solid var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

/* ============================
   LOGIN PAGE
   ============================ */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}

.login-card {
  background: var(--card);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}

.lang-bar {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-bottom: 1.5rem;
}

.login-logo { text-align: center; margin-bottom: 2rem; }
.logo-icon  { font-size: 3rem; }
.login-title   { margin: .5rem 0 .2rem; color: var(--primary-dark); }
.login-subtitle { color: var(--text-muted); font-size: 1rem; }

.login-form  { margin-top: 1.5rem; }
.login-btn   { width: 100%; justify-content: center; margin-top: .5rem; }
.login-hint  { text-align: center; color: var(--text-muted); font-size: .9rem; margin-top: 1rem; }

/* ============================
   APP HEADER
   ============================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.header-left  { display: flex; align-items: center; gap: .7rem; }
.header-logo  { font-size: 1.6rem; }
.header-title   { font-size: 1.2rem; font-weight: 700; color: #fff; }
.header-version { font-size: .75rem; font-weight: 600; color: #64748b;
                  background: #1e293b; border: 1px solid #334155;
                  padding: .15rem .5rem; border-radius: 999px; letter-spacing: .03em; }

.header-right { display: flex; align-items: center; gap: .6rem; }
.header-right .lang-btn { border-color: #475569; color: #94a3b8; }
.header-right .lang-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.header-right .btn-outline { color: #94a3b8; border-color: #475569; }
.header-right .btn-outline:hover { background: #1e293b; }
.header-right .btn-secondary { background: #334155; color: #e2e8f0; border-color: #334155; }
.header-right .btn-secondary:hover { background: #475569; }

/* ---- Warning banner ---- */
.banner-warn {
  background: #78350f;
  color: #fef3c7;
  text-align: center;
  padding: .6rem 1rem;
  font-size: .95rem;
  font-weight: 500;
}

/* ============================
   MAIN LAYOUT
   ============================ */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1.2rem;
  color: var(--primary-dark);
}

/* ============================
   UPLOAD / DROPZONE
   ============================ */
/* Versteckter File-Input — zugänglich aber unsichtbar (wichtig für mobile Label-Trigger) */
.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.upload-panel { max-width: 700px; margin: 2rem auto; }

.dropzone {
  display: block;
  border: 3px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 1.5rem;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.drop-icon  { font-size: 3rem; margin-bottom: .5rem; }
.drop-text  { font-size: 1.1rem; font-weight: 500; color: var(--text); }
.drop-hint  { font-size: .9rem; color: var(--text-muted); margin-top: .3rem; }

.upload-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---- Progress overlay ---- */
.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.progress-card {
  background: var(--card);
  border-radius: 16px;
  padding: 2.5rem 3rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  min-width: 260px;
}
.progress-text { margin-top: 1rem; font-size: 1.2rem; font-weight: 500; }

.progress-bar-wrap {
  margin-top: 1rem;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .3s ease;
  width: 0%;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 5px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================
   SCAN INFO BAR
   ============================ */
.scan-info-bar {
  background: var(--primary-dark);
  color: #e2e8f0;
  border-radius: var(--radius);
  padding: .8rem 1.2rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 1.2rem;
  font-size: .95rem;
}
.info-item { display: flex; flex-direction: column; gap: .1rem; }
.info-label { font-size: .8rem; color: #94a3b8; text-transform: uppercase; letter-spacing: .05em; }
.info-value { font-weight: 700; font-size: 1.1rem; color: #fff; }

/* ============================
   RESULTS GRID
   ============================ */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.2rem;
  align-items: start;
}

@media (max-width: 900px) {
  .results-grid { grid-template-columns: 1fr; }
}

/* ---- Viewer ---- */
.viewer-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: #f8fafc;
}
.tab-btn {
  flex: 1;
  padding: .8rem;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom: 3px solid var(--primary);
  margin-bottom: -2px;
  background: var(--card);
}
.tab-btn:hover:not(.active) { background: #f1f5f9; }

.plotly-container {
  width: 100%;
  min-height: 480px;
}

.slice-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.depth-slider {
  flex: 1;
  height: 6px;
  accent-color: var(--primary);
}
.depth-value { font-weight: 700; min-width: 50px; color: var(--primary); }

/* ---- Anomaly Panel ---- */
.anomaly-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1rem 1.5rem;
  max-height: 600px;
  overflow-y: auto;
}
.anomaly-panel .panel-title { position: sticky; top: 0; background: var(--card); padding: .5rem 0; z-index: 1; }

.badge {
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  padding: .1rem .6rem;
  font-size: .85rem;
  font-weight: 700;
}

/* ---- Anomaly card ---- */
.anomaly-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  margin-bottom: .8rem;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.anomaly-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(29,78,216,.15); }

.anomaly-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .5rem;
}
.anomaly-num {
  background: var(--primary);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.anomaly-title { font-weight: 600; font-size: 1rem; }

.sig-badge {
  margin-left: auto;
  padding: .15rem .6rem;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
}
.sig-very_high { background: var(--sig-very-high); }
.sig-high      { background: var(--sig-high);      }
.sig-medium    { background: var(--sig-medium);     }
.sig-low       { background: var(--sig-low);        }

.anomaly-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .4rem;
  font-size: .85rem;
}
.stat-item { display: flex; flex-direction: column; }
.stat-label { color: var(--text-muted); font-size: .75rem; }
.stat-value { font-weight: 700; color: var(--text); }

.anomaly-ai-btn {
  width: 100%;
  margin-top: .7rem;
  justify-content: center;
}

/* AI result within card */
.ai-result-inline {
  margin-top: .7rem;
  padding: .7rem;
  background: #f0fdf4;
  border-radius: 8px;
  border: 1px solid #bbf7d0;
  font-size: .88rem;
}
.ai-result-type  { font-weight: 700; font-size: 1rem; margin-bottom: .3rem; }
.ai-confidence   { display: inline-block; padding: .1rem .5rem; border-radius: 12px; font-size: .78rem; font-weight: 700; margin-bottom: .4rem; }
.conf-high   { background: #dcfce7; color: #166534; }
.conf-medium { background: #fef9c3; color: #713f12; }
.conf-low    { background: #fef2f2; color: #7f1d1d; }

.result-actions {
  margin-top: 1.5rem;
  text-align: center;
}

/* ============================
   MODALS
   ============================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 1rem;
}
.modal-card {
  background: var(--card);
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.modal-sm { max-width: 420px; }
.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: #f1f5f9;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-title { margin-bottom: 1rem; color: var(--primary-dark); }

/* AI modal details */
.ai-detail-type  { font-size: 1.4rem; font-weight: 700; margin-bottom: .4rem; }
.ai-detail-meta  { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; }
.ai-detail-label { color: var(--text-muted); font-size: .85rem; }
.ai-detail-section { margin-bottom: 1rem; }
.ai-detail-section h4 { font-size: .9rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: .4rem; }
.ai-steps { padding-left: 1.2rem; }
.ai-steps li { margin-bottom: .3rem; }

.risk-badge { padding: .2rem .7rem; border-radius: 12px; font-size: .82rem; font-weight: 700; }
.risk-none   { background: #dcfce7; color: #166534; }
.risk-low    { background: #dbeafe; color: #1e3a8a; }
.risk-medium { background: #fef3c7; color: #78350f; }
.risk-high   { background: #fef2f2; color: #7f1d1d; }
