:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --accent: #1a56db;
  --accent-light: #3b82f6;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --border: #334155;
  --ok: #22c55e;
  --warn: #f59e0b;
  --planned: #64748b;

  /* Kraeftige Easing-Kurven (CSS-Defaults sind zu schwach) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --focus-ring: rgba(59, 130, 246, .35);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* Hoehe der Taskbar (ohne Safe-Area; die wird separat aufaddiert) */
:root { --taskbar-h: 60px; }
:root { --bar-total: calc(var(--taskbar-h) + env(safe-area-inset-bottom)); }

#app { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* Login */
.login {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 20px;
  /* Safe-Area in alle Richtungen -> auch im Querformat nicht unter dem Notch */
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 30%, #1e293b, #0f172a 70%);
  overflow-y: auto;
}
.login-card {
  width: 100%; max-width: 340px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 18px; padding: 28px 24px;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .65), 0 2px 8px rgba(0, 0, 0, .3);
  animation: login-card-in 420ms var(--ease-out) both;
}
@keyframes login-card-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.login-brand {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  margin-bottom: 8px;
}
.brand-logo { height: 30px; width: auto; object-fit: contain; display: block; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); }
.field input {
  background: #0f172a; border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-size: 22px; letter-spacing: .1em; padding: 12px 14px;
  text-align: center; outline: none;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
.field input:focus { border-color: var(--accent-light); box-shadow: 0 0 0 3px var(--focus-ring); }
.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  font-size: 17px; font-weight: 600; padding: 14px; cursor: pointer; margin-top: 4px;
  transition: background 150ms var(--ease-out), transform 120ms var(--ease-out);
}
.primary:disabled { opacity: .6; }
.primary:hover:not(:disabled) { background: var(--accent-light); }
.primary:active:not(:disabled) { background: #1746b0; transform: scale(.97); }
.sso-btn {
  background: transparent; color: var(--text); border: 1px solid var(--accent-light);
  border-radius: 10px; font-size: 15px; font-weight: 600; padding: 12px; cursor: pointer;
  transition: background 150ms var(--ease-out), transform 120ms var(--ease-out);
}
.sso-btn:hover { background: rgba(59,130,246,.10); }
.sso-btn:active { background: rgba(59,130,246,.18); transform: scale(.97); }
.login-error:not(:empty) { animation: login-error-in 200ms var(--ease-out) both; }
.login-error { color: #f87171; font-size: 13px; text-align: center; min-height: 18px; }
@keyframes login-error-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* Erzwungenes Update-Overlay: deckt alles ab, blockiert jede Interaktion. */
.update-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 16, 30, .92); padding: 24px;
}
.update-card {
  max-width: 420px; text-align: center; color: var(--text, #e6edf6);
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px; padding: 28px 24px;
}
.update-card h2 { font-size: 18px; margin: 16px 0 8px; }
.update-card p { font-size: 14px; color: var(--text-dim, #9fb0c8); line-height: 1.5; }
.update-spinner {
  width: 40px; height: 40px; margin: 0 auto; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.15); border-top-color: var(--accent, #2563eb);
  animation: update-spin .8s linear infinite;
}
@keyframes update-spin { to { transform: rotate(360deg); } }
.version-hint { font-size: 11px; color: var(--text-dim); text-align: center; }

.brand-mark {
  display: block; flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 8px;
  background: #fff; object-fit: contain; padding: 3px;
}

/* Stage: Container fuer die Modul-iframes (Tabs) */
.stage { position: absolute; inset: 0 0 var(--bar-total) 0; background: #fff; }
.tab-frame {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border: 0; background: #fff; display: none;
}
.tab-frame.active { display: block; }

/* Flexisoft-Menue als Overlay ueber der Stage */
.menu-panel {
  position: absolute; inset: 0 0 var(--bar-total) 0;
  background: var(--bg); display: none; flex-direction: column; z-index: 50;
}
.menu-panel.open { display: flex; }

/* Willkommens-Header im Menue */
.menu-head {
  flex-shrink: 0; text-align: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           4px calc(16px + env(safe-area-inset-left));
}
.welcome { font-size: 20px; font-weight: 700; color: #ffffff; }

/* Menu */
/* Relativer, clippender Wrapper: traegt den Pull-to-Refresh-Indikator,
   der oberhalb der scrollbaren Liste sitzt und beim Ziehen hereinwandert. */
.menu-scroll-wrap { position: relative; flex: 1; min-height: 0; display: flex; overflow: hidden; }
.menu { flex: 1; overflow-y: auto; padding: 16px calc(16px + env(safe-area-inset-right)) 16px calc(16px + env(safe-area-inset-left)); max-width: 920px; width: 100%; margin: 0 auto; }
.loading { color: var(--text-dim); text-align: center; padding: 48px 0; }

/* Pull-to-Refresh */
.ptr {
  position: absolute; top: 0; left: 0; right: 0; height: 64px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--text-dim); font-size: 13px; font-weight: 600;
  transform: translateY(-100%); pointer-events: none; z-index: 2;
}
.ptr-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; font-size: 16px; line-height: 1;
  transition: transform 180ms var(--ease-out);
}
/* Schwelle erreicht: Pfeil dreht sich um, Text wechselt (per JS-Klasse) */
.ptr.ready .ptr-icon { transform: rotate(180deg); }
/* Aktualisierung laeuft: Pfeil wird zum rotierenden Spinner */
.ptr.refreshing .ptr-icon {
  width: 18px; height: 18px; font-size: 0; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.15); border-top-color: var(--accent-light);
  animation: update-spin .8s linear infinite; transition: none;
}

.category { margin-bottom: 28px; animation: category-in 360ms var(--ease-out) both; }
.category:nth-child(1) { animation-delay: 0ms; }
.category:nth-child(2) { animation-delay: 60ms; }
.category:nth-child(3) { animation-delay: 120ms; }
.category:nth-child(4) { animation-delay: 180ms; }
.category:nth-child(n+5) { animation-delay: 220ms; }
@keyframes category-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.category-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: #cbd5e1; font-weight: 600; margin: 0 4px 12px;
}
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.tile {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 16px; cursor: pointer;
  transition: background 150ms var(--ease-out), border-color 150ms var(--ease-out),
              transform 120ms var(--ease-out), box-shadow 150ms var(--ease-out);
  display: flex; flex-direction: column; gap: 10px; min-height: 120px;
  position: relative; text-align: left;
}
.tile:active { transform: scale(.97); }
@media (hover: hover) and (pointer: fine) {
  .tile:hover {
    background: var(--bg-card-hover); border-color: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .6);
  }
}
.tile:focus-visible {
  outline: none; border-color: var(--accent-light);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.tile.disabled { opacity: .5; cursor: default; }
.tile.disabled:active { transform: none; }
@media (hover: hover) and (pointer: fine) {
  .tile.disabled:hover { background: var(--bg-card); border-color: var(--border); transform: none; box-shadow: none; }
}

.tile-icon { font-size: 28px; line-height: 1; }
.tile-icon-img {
  width: 48px; height: 48px;
  object-fit: contain; border-radius: 10px; display: block;
}
.tile-title { font-weight: 700; font-size: 16px; color: #ffffff; }
.tile-sub { font-size: 12px; color: #cbd5e1; }

.badge {
  position: absolute; top: 10px; right: 10px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 2px 7px; border-radius: 999px;
}
.badge.beta { background: var(--warn); color: #1a1a1a; }
.badge.planned { background: var(--planned); color: #e2e8f0; }

.empty { color: var(--text-dim); text-align: center; padding: 48px 16px; }

/* Menue-Fuss: Abmelden + Versions-/Statusinfo (ersetzt die fruehere Topbar) */
.menu-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  border-top: 1px solid var(--border);
}
.menu-logout {
  background: rgba(255,255,255,.08); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer;
  white-space: nowrap; flex: 0 1 auto;   /* Name voll sichtbar, keine Ellipse */
  transition: background 150ms var(--ease-out), transform 120ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .menu-logout:hover { background: rgba(255,255,255,.14); }
}
.menu-logout:active { background: rgba(255,255,255,.18); transform: scale(.97); }
.menu-logout:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.menu-foot-meta { display: flex; flex-direction: column; align-items: flex-end; text-align: right; gap: 2px; font-size: 11px; color: var(--text-dim); flex: 0 0 auto; }

/* Taskbar an der unteren Bildschirmkante */
.taskbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 60;
  height: var(--bar-total); padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: center; gap: 6px;
  padding-left: calc(6px + env(safe-area-inset-left));
  padding-right: calc(6px + env(safe-area-inset-right));
  background-color: #0b1220; border-top: 1px solid var(--border);
  /* Flexisoft-Logo rechtsbuendig als dezentes Hintergrundbild */
  background-image: url('../res/flexisoft-logo.png');
  background-repeat: no-repeat;
  background-position: right calc(12px + env(safe-area-inset-right)) center;
  background-size: auto 30px;
}
.task-list {
  display: flex; align-items: center; gap: 6px; height: 100%;
  flex: 1; overflow-x: auto; padding-left: 6px;
  border-left: 1px solid var(--border);
}
.task {
  position: relative; flex: 0 0 auto;
  width: 48px; height: 48px; border-radius: 12px;
  border: 1px solid transparent; background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; padding: 0;
  transition: background 120ms var(--ease-out), border-color 120ms var(--ease-out),
              transform 100ms var(--ease-out);
}
.task:active { transform: scale(.92); }
@media (hover: hover) and (pointer: fine) {
  .task:hover { background: rgba(255,255,255,.08); }
}
.task:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.task.active { background: rgba(59,130,246,.20); border-color: var(--accent-light); }
.task-menu { background: rgba(255,255,255,.06); }
.task-menu.active { background: rgba(59,130,246,.30); border-color: var(--accent-light); }
.task-icon-img { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; pointer-events: none; }
.task-icon-emoji { font-size: 26px; line-height: 1; pointer-events: none; }
.task-index {
  position: absolute; top: -3px; right: -3px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
  box-shadow: 0 0 0 2px #0b1220;
}

/* Kontextmenue des aktiven Tabs */
.ctxmenu {
  position: fixed; z-index: 200;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px; box-shadow: 0 12px 32px rgba(0,0,0,.55);
  transform-origin: bottom center;        /* schiebt sich aus dem Taskbar-Icon hervor */
  animation: ctx-in 160ms var(--ease-out) both;
}
@keyframes ctx-in {
  from { opacity: 0; transform: translateY(6px) scale(.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.ctxmenu.hidden { display: none; }
.ctx-item {
  display: block; width: 100%; background: transparent; border: none;
  color: var(--text); font-size: 14px; padding: 10px 16px;
  text-align: left; border-radius: 6px; cursor: pointer; white-space: nowrap;
  transition: background 120ms var(--ease-out);
}
.ctx-item:hover, .ctx-item:active { background: var(--bg-card-hover); }

/* Reduzierte Bewegung: Eintritts-/Bewegungs-Animationen aus, Feedback (Farbe,
   Fokus-Ring, Press-Scale) bleibt erhalten. */
@media (prefers-reduced-motion: reduce) {
  .login-card, .login-error:not(:empty), .category, .ctxmenu {
    animation: none;
  }
  .tile:hover { transform: none; }
}
