/* ─── Farben & Grundwerte ─────────────────────────────────── */

:root {
  --cyan: #2ec4eb;
  --sage: #92beb8;
  --gold: #ebb564;
  --gradient: linear-gradient(90deg, var(--cyan), var(--sage) 50%, var(--gold));

  --bg: #0b0c0e;
  --surface: #15171a;
  --surface-2: #1f2226;
  --surface-3: #292d32;
  --border: #2e3238;
  --text: #f2f3f5;
  --text-muted: #9ba2ac;
  --danger: #ef6b73;
  --focus: var(--cyan);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);

  --radius: 12px;
  --radius-sm: 10px;
  --topbar-h: 56px;

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0f3;
    --surface: #e2e5ea;
    --surface-2: #ffffff;
    --surface-3: #f6f7f9;
    --border: #d3d8df;
    --text: #121519;
    --text-muted: #5b636e;
    --danger: #c9383f;
    --focus: #1b9fc4;
    --shadow: 0 1px 2px rgb(16 24 40 / 0.1), 0 1px 3px rgb(16 24 40 / 0.06);
    --shadow-lg: 0 16px 40px rgb(16 24 40 / 0.2);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg circle { fill: currentColor; stroke: none; }

.spacer { flex: 1; }


/* ─── Wortmarke ───────────────────────────────────────────── */

.wordmark {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
}
.wordmark span {
  background: linear-gradient(90deg, var(--sage), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.wordmark.big { font-size: 34px; }


/* ─── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--gradient); border: 0; color: #000; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.block { width: 100%; min-height: 46px; }
.btn.danger-text { background: transparent; border-color: transparent; color: var(--danger); padding: 0 8px; }
.btn.danger-text:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
}
.icon-btn:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 18px; height: 18px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }


/* ─── Ladebildschirm & Login ──────────────────────────────── */

.splash, .login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  padding: 24px;
  background: #000;
  color: #fff;
}
.splash-msg { max-width: 360px; margin: 0; text-align: center; color: #b8bec6; }

.login { background: var(--bg); color: var(--text); }
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 4px;
}
.login-card .wordmark { text-align: center; margin-bottom: 24px; }
.login-card .btn { margin-top: 8px; }


/* ─── App-Grundgerüst ─────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  padding: 8px 12px 8px 18px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: #000;
  color: #fff;
  flex: none;
}
.topbar .wordmark { margin-right: 6px; }

/* Sync-Anzeige */
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #b8bec6; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.sync[data-state="ok"] i { background: #5fcf8f; }
.sync[data-state="pending"] i { background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
.sync[data-state="local"] i { background: var(--gold); }
@keyframes pulse { 50% { opacity: 0.35; } }

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 18px;
  font-size: 13px;
  background: color-mix(in srgb, var(--gold) 16%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  flex: none;
}
.banner span { flex: 1; }


/* ─── Board (Spalten) ─────────────────────────────────────── */

.board-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

.ruler { display: none; }

.board {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  gap: 12px;
  padding: 16px;
  overflow-x: auto;
  overflow-y: hidden;
}

.column {
  flex: 1 1 0;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border-top: 3px solid var(--phase);
}

.column-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
}
.column-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--phase);
  flex: none;
}

.count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.cards {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 10px 14px;
}
.cards:empty::before {
  content: attr(data-empty);
  display: block;
  padding: 18px 10px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}


/* ─── Karten ──────────────────────────────────────────────── */

.card {
  flex: none;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.card:hover { background: var(--surface-3); }

/* Zeile 1: Titel + Kunde, Zeile 2: Notizen + Datum. Zu langer Text endet mit «…». */
.card-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.card-head .dot, .card-head .pause { align-self: center; }

/* Status «Warten»: Pause-Symbol statt Punkt, Karte blasser */
.pause {
  flex: none;
  width: 9px;
  height: 10px;
  background: linear-gradient(90deg, currentColor 0 3px, transparent 3px 6px, currentColor 6px);
}
.card .pause { color: var(--phase); }
.card.waiting { opacity: 0.55; }
.chip-waiting { --phase: #8b929c; }
.card-title, .card-customer, .card-notes {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-title {
  flex: 0 1 auto;
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
}
.card-title.untitled { color: var(--text-muted); font-style: italic; }
.card-customer {
  flex: 0 0 auto;
  max-width: 45%;
  font-size: 13px;
  color: var(--text-muted);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.card-notes { flex: 1; }
.card-date { flex: none; font-variant-numeric: tabular-nums; }

/* Zustände beim Ziehen */
.card-ghost { opacity: 0.35; }
.card-chosen { box-shadow: 0 0 0 2px var(--phase); }
.sortable-fallback { box-shadow: var(--shadow-lg) !important; transform: rotate(1.5deg); opacity: 1 !important; cursor: grabbing; }

.card.flash { animation: flash 1.4s ease-out; }
@keyframes flash {
  0%, 30% { box-shadow: 0 0 0 3px var(--phase), var(--shadow); }
  100% { box-shadow: var(--shadow); }
}


/* ─── Ablageflächen (Abschliessen / Cancel) ───────────────── */

.dropzones {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: none;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  pointer-events: none;
}
body.is-dragging .dropzones { display: flex; }

.dropzone {
  pointer-events: auto;
  flex: 1;
  max-width: 280px;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--phase);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--phase) 14%, var(--surface));
  box-shadow: var(--shadow-lg);
  font-weight: 700;
  transition: background 0.15s, transform 0.15s;
}
.dropzone.over {
  border-style: solid;
  background: color-mix(in srgb, var(--phase) 38%, var(--surface));
  transform: scale(1.04);
}
.dropzone .card { display: none; }


/* ─── Neu-Knopf (Handy) ───────────────────────────────────── */

.fab {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--gradient);
  color: #000;
  box-shadow: var(--shadow-lg);
  place-items: center;
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }
body.is-dragging .fab { display: none !important; }


/* ─── Menü ────────────────────────────────────────────────── */

.menu {
  position: fixed;
  inset: auto;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) - 4px);
  right: 12px;
  margin: 0;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.menu button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-size: 14px;
}
.menu button:hover { background: var(--surface-3); }
.menu-info {
  margin: 0 0 4px;
  padding: 8px 12px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}


/* ─── Dialoge (Projekt, Archiv) ───────────────────────────── */

dialog.sheet {
  width: min(560px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  border: 1px solid var(--border);
  border-top: 3px solid var(--phase, var(--border));
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.55); }

.sheet-inner {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 780px);
  max-height: min(88dvh, 780px);
}
.sheet-tall .sheet-inner { height: min(88dvh, 780px); }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 10px 6px 20px;
}
.sheet-head h2 {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 20px 16px;
}

.sheet-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.field { display: block; margin: 0 0 14px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

input, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 16px; /* verhindert Auto-Zoom auf dem iPhone */
}
input:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.field-date input { width: auto; min-width: 170px; }

.form-error { margin: 4px 0 0; color: var(--danger); font-size: 13.5px; }
.meta { margin: 4px 0 0; font-size: 12.5px; color: var(--text-muted); }

/* Phasen-Auswahl */
.phase-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.phase-picker .break { flex-basis: 100%; height: 2px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  font-size: 13.5px;
  font-weight: 600;
}
.chip:hover { background: var(--surface-3); }
.chip[aria-pressed="true"] {
  border-color: var(--phase);
  background: color-mix(in srgb, var(--phase) 24%, transparent);
}

/* Archiv */
.archive-controls {
  display: grid;
  gap: 10px;
  padding: 6px 20px 10px;
  border-bottom: 1px solid var(--border);
}
.segmented {
  display: flex;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}
.segmented button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.segmented button[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow); }

.archive-list { padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.archive-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--phase);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
}
.archive-item:hover { background: var(--surface-3); }
.archive-item .main { flex: 1; min-width: 0; }
.archive-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.archive-item .sub { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.archive-item .date { flex: none; font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.empty { padding: 32px 12px; text-align: center; color: var(--text-muted); }


/* ─── Toast ───────────────────────────────────────────────── */

.toast {
  position: fixed;
  inset: auto 16px calc(24px + env(safe-area-inset-bottom)) 16px;
  z-index: 50;
  width: fit-content;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 10px 10px 16px;
  border: 1px solid #33373d;
  border-radius: var(--radius);
  background: #111315;
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
}
.toast:not(:popover-open):not(.show) { display: none; }
.toast-action {
  flex: none;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--cyan);
  font-weight: 700;
}
.toast-action:hover { background: rgb(255 255 255 / 0.08); }
.toast-action:empty { display: none; }


/* ─── Handy ───────────────────────────────────────────────── */

@media (max-width: 700px) {
  .hide-mobile { display: none !important; }
  .topbar { padding-left: 16px; }

  /* Alle Phasen untereinander, jede Phase als Kasten wie am PC */
  .board {
    flex-direction: column;
    gap: 14px;
    padding: 12px 16px calc(100px + env(safe-area-inset-bottom)) 26px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Massband am linken Rand, wie oben auf wengerwerk.ch */
  .ruler {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 5;
    width: 11px;
    padding-bottom: env(safe-area-inset-bottom);  /* Marker nicht unter den iPhone-Wischbalken */
    pointer-events: none;
    background-color: #000;
    background-image:
      repeating-linear-gradient(180deg, rgb(255 255 255 / 0.5) 0 1.5px, transparent 1.5px 9px),
      repeating-linear-gradient(180deg, rgb(255 255 255 / 0.65) 0 2px, transparent 2px 45px);
    background-size: 55% 9px, 100% 45px;
    background-repeat: repeat-y;
  }
  .ruler-marker {
    position: absolute;
    left: 0;
    top: 0;
    width: 16px;
    height: 11px;
    background: var(--marker-color, var(--cyan));
    clip-path: polygon(0 0, 66% 0, 100% 50%, 66% 100%, 0 100%);
    /* gleiche Gleitbewegung wie der Marker auf wengerwerk.ch */
    transition: transform 0.4s cubic-bezier(0.65, 0, 0.35, 1), background-color 0.3s;
    will-change: transform;
  }
  .ruler-marker.instant { transition: background-color 0.3s; }

  .column {
    flex: none;
    display: grid;
    grid-template-columns: 100%;
    min-width: 0;
  }
  .column-head { grid-row: 1; grid-column: 1; padding: 12px 14px 10px; }
  .column-head h2 { font-size: 15px; }
  .column-head .count { font-size: 13px; }

  .cards { grid-row: 2; grid-column: 1; overflow: visible; padding: 0 10px 10px; gap: 8px; }
  /* Leere Phase: nur die Titelzeile. Die leere Liste liegt unsichtbar darüber,
     damit man eine Karte auf die Titelzeile ziehen kann. */
  .cards:empty { grid-row: 1; z-index: 1; padding: 0; }
  .cards:empty::before { display: none; }

  .card { padding: 12px 14px; scroll-margin-top: 56px; }  /* Phasen-Titel bleibt beim Hinscrollen sichtbar */
  .card-title { font-size: 15.5px; }
  .card-customer { font-size: 14px; }
  .card-meta { font-size: 13px; }

  .fab { display: grid; }

  /* Popup so breit wie die Phasen-Kästen, oben und unten gleicher Abstand wie der oberste Kasten.
     Das Massband bleibt sichtbar, die Liste dahinter wird ausgeblendet. */
  dialog.sheet {
    position: fixed;
    inset: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px) 16px calc(12px + env(safe-area-inset-bottom)) 26px;
    width: auto;
    height: auto;
    max-height: none;
    margin: 0;
    border-radius: var(--radius);
  }
  dialog.sheet::backdrop { background: transparent; }
  body:has(dialog.sheet[open]) .board,
  body:has(dialog.sheet[open]) .fab { visibility: hidden; }
  .sheet-inner, .sheet-tall .sheet-inner { height: 100%; max-height: none; }
  .sheet-foot { padding-bottom: 12px; }
  .sheet-head { padding-left: 16px; }
  .sheet-body, .archive-controls { padding-left: 16px; padding-right: 16px; }

  .dropzone { min-height: 72px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom)); }
}
