/* Cockpit Frontend — CSS Grid, themeParams Dark/Light, Ampel-Farben */
/* Variablen werden per JS aus themeParams gesetzt (tg-adapter + app.js) */

:root {
  /* Telegram themeParams — werden per JS überschrieben */
  --tg-bg:        #1c1c1e;
  --tg-text:      #ffffff;
  --tg-hint:      #8e8e93;
  --tg-link:      #0a84ff;
  --tg-btn:       #0a84ff;
  --tg-btn-text:  #ffffff;
  --tg-secondary: #2c2c2e;

  /* Ampel-Farben (Dot + Kachel-BG) */
  --status-green:     #30d158;
  --status-green-bg:  #0d2b17;
  --status-yellow:    #ffd60a;
  --status-yellow-bg: #2b2200;
  --status-red:       #ff453a;
  --status-red-bg:    #2b0a08;
  --status-stale:     #636366;
  --status-stale-bg:  #1c1c1e;

  --radius: 12px;
  --gap: 10px;
}

/* Light-Mode Overrides */
[data-scheme="light"] {
  --status-green-bg:  #d4f5e0;
  --status-yellow-bg: #fff8cc;
  --status-red-bg:    #fde0de;
  --status-stale-bg:  #ebebeb;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

/* Safe-area padding — iOS WKWebView nach expand() */
body {
  padding: env(safe-area-inset-top, 0)
           env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0)
           env(safe-area-inset-left, 0);
}

/* ── Layout ── */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  max-width: 600px;
  margin: 0 auto;
}

/* ── Offline/Stale-Banner ── */

#banner {
  display: none;
  background: var(--status-yellow-bg);
  color: var(--status-yellow);
  border-bottom: 1px solid var(--status-yellow);
  padding: 8px 14px;
  font-size: 13px;
  text-align: center;
}
#banner.visible { display: block; }

/* ── Header ── */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--tg-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

#header h1 {
  font-size: 17px;
  font-weight: 600;
}

#btn-refresh {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
#btn-refresh:active { opacity: 0.7; }

/* ── Grid-Bereich ── */

#grid-container {
  flex: 1;
  padding: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.grid-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tg-hint);
  margin: 14px 0 8px;
}
.grid-section-title:first-child { margin-top: 0; }

/* CSS Grid — 2 Spalten, mobil-first */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
}

/* Kachel */
.card {
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.06);
  transition: opacity 0.15s;
  min-height: 72px;
}
.card.clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card.clickable:active { opacity: 0.75; }
.card:focus-visible { outline: 2px solid var(--tg-link); outline-offset: 2px; }

.card-header {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Ampel-Dot */
.dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.card-label {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-section {
  font-size: 11px;
  color: var(--tg-hint);
  margin-top: 4px;
}

.card-summary {
  font-size: 12px;
  color: var(--tg-hint);
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Loading / Error / Empty */
.loading, .grid-error, .empty {
  grid-column: 1 / -1;
  padding: 32px 0;
  text-align: center;
  color: var(--tg-hint);
  font-size: 14px;
}
.grid-error { color: var(--status-red); }

/* ── Detail-Overlay ── */

#detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 100;
  align-items: flex-end;
}
#detail-overlay.visible { display: flex; }

#detail-sheet {
  background: var(--tg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

#detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

#detail-title {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#detail-close {
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 16px;
  cursor: pointer;
  color: var(--tg-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#detail-close:active { opacity: 0.6; }

#detail-output {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px;
  font-family: 'Menlo', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--tg-text);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Token-Modal ── */

#token-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#token-modal.visible { display: flex; }

#token-box {
  background: var(--tg-secondary);
  border-radius: var(--radius);
  padding: 24px 20px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#token-box h2 { font-size: 16px; font-weight: 600; }
#token-box p  { font-size: 13px; color: var(--tg-hint); }

#token-input {
  background: var(--tg-bg);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--tg-text);
  width: 100%;
  outline: none;
}
#token-input:focus { border-color: var(--tg-link); }

#token-submit {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
}
#token-submit:active { opacity: 0.75; }

/* ── Health-Panel ── */

#health-container {
  padding: 0 14px 8px;
}

#health-panel {
  padding-bottom: 4px;
}

.health-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.health-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--tg-secondary);
  border-radius: 20px;
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.06);
}

.health-item[data-status="green"] .dot  { background: var(--status-green); }
.health-item[data-status="yellow"] .dot { background: var(--status-yellow); }
.health-item[data-status="red"] .dot    { background: var(--status-red); }
.health-item[data-status="stale"] .dot  { background: var(--status-stale); }

.health-label {
  font-size: 12px;
  color: var(--tg-text);
  white-space: nowrap;
}

/* ── Footer ── */

#footer {
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
  border-top: 1px solid rgba(255,255,255,0.08);
  background: var(--tg-secondary);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#btn-hayalet-end {
  background: var(--status-red-bg);
  color: var(--status-red);
  border: 1px solid var(--status-red);
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
#btn-hayalet-end:active { opacity: 0.7; }

/* ── Detail-Actions (task buttons in Detail-View) ── */

#detail-actions {
  padding: 0 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-actions-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tg-hint);
  padding-top: 4px;
}

.task-btn {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  text-align: left;
}
.task-btn:active { opacity: 0.7; }
.task-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Confirm-Modal ── */

#confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 300;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#confirm-overlay.visible { display: flex; }

#confirm-box {
  background: var(--tg-secondary);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#confirm-box h2 {
  font-size: 16px;
  font-weight: 600;
}

#confirm-preview {
  background: var(--tg-bg);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Menlo', 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--tg-text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 120px;
  overflow-y: auto;
  margin: 0;
}

#confirm-fingerprint {
  font-size: 11px;
  color: var(--tg-hint);
  font-family: 'Menlo', 'Courier New', monospace;
  word-break: break-all;
  min-height: 1em;
}

.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

#confirm-cancel {
  background: rgba(255,255,255,0.1);
  color: var(--tg-text);
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
#confirm-cancel:active { opacity: 0.7; }

#confirm-ok {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
#confirm-ok:active { opacity: 0.7; }

/* ── Große Bildschirme ── */
@media (min-width: 480px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
