/* =========================================================================
   Schichtplaner - mobile first
   Regel: nichts darf breiter werden als der Viewport. Tabellen werden auf
   schmalen Bildschirmen zu Karten, Formularfelder immer fluid.
   ========================================================================= */

:root {
  --bg:        #f1f4f8;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --ink:       #101828;
  --ink-2:     #475467;
  --muted:     #667085;
  --line:      #e4e9f0;
  --line-2:    #d0d7e2;

  --brand:      #2563eb;
  --brand-ink:  #1d4ed8;
  --brand-soft: #eff5ff;

  --ok: #067647;      --ok-bg: #ecfdf3;   --ok-line: #a9e5c3;
  --warn: #b54708;    --warn-bg: #fffaeb; --warn-line: #fedf89;
  --bad: #b42318;     --bad-bg: #fef3f2;  --bad-line: #fecdca;

  --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-full: 999px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --shadow-lg: 0 4px 12px rgba(16,24,40,.08);
  --tap: 44px;                       /* Mindestgröße für Touch-Ziele */
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;   --surface: #161b22;  --surface-2: #1c232c;
    --ink: #e6edf3;  --ink-2: #b0bac6;    --muted: #8b949e;
    --line: #262d36; --line-2: #333c47;
    --brand: #4c8dff; --brand-ink: #6ba3ff; --brand-soft: #16233a;
    --ok: #52d68a;   --ok-bg: #10261a;    --ok-line: #1f5136;
    --warn: #f0b64b; --warn-bg: #2a2011;  --warn-line: #5a441a;
    --bad: #ff8078;  --bad-bg: #2b1512;   --bad-line: #5e2621;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --shadow-lg: 0 4px 14px rgba(0,0,0,.5);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden;               /* Sicherheitsnetz gegen Querscrollen */
  -webkit-font-smoothing: antialiased;
}

/* Lange Wörter (E-Mails, Benutzernamen) dürfen nie herausragen */
body, td, th, li, p, h1, h2, h3, span, a { overflow-wrap: anywhere; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg, table { max-width: 100%; }

/* ---------------------------------------------------------------- Kopfzeile */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 1rem;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  min-height: 56px;
  display: flex; align-items: center; gap: .75rem;
}
.brand {
  font-weight: 700; font-size: 1.02rem; color: var(--ink);
  display: flex; align-items: center; gap: .45rem; flex: 1; min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand .dot { width: 26px; height: 26px; flex: none; }

.nav-desktop { display: none; }

.who {
  display: flex; align-items: center; gap: .5rem;
  font-size: .85rem; color: var(--muted); flex: none;
}
.who .avatar {
  width: 34px; height: 34px; border-radius: var(--r-full);
  background: var(--brand-soft); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; font-size: .8rem;
  flex: none;
}
.who .name { display: none; }

.badge-count {
  background: var(--bad); color: #fff; border-radius: var(--r-full);
  min-width: 18px; height: 18px; padding: 0 5px;
  font-size: .68rem; font-weight: 700; line-height: 18px;
  display: inline-block; text-align: center;
}

/* ------------------------------------------------- Untere Leiste (nur mobil) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -1px 8px rgba(16,24,40,.06);
}
.tabbar a {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: .4rem .1rem .3rem;
  min-height: var(--tabbar-h);
  color: var(--muted); font-size: .68rem; font-weight: 600;
  text-decoration: none; position: relative;
}
.tabbar a.active { color: var(--brand); }
.tabbar a svg { width: 22px; height: 22px; flex: none; }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar .badge-count {
  position: absolute; top: 4px; left: 52%; transform: translateX(2px);
}

/* ---------------------------------------------------------------- Grundraster */
main {
  max-width: 1200px; margin: 0 auto;
  padding: 1rem .9rem calc(var(--tabbar-h) + 1.5rem);
}

h1 { font-size: 1.4rem; line-height: 1.25; margin: 0 0 .25rem; letter-spacing: -.02em; }
h2 { font-size: 1.08rem; margin: 1.5rem 0 .6rem; letter-spacing: -.01em; }
h3 { font-size: .98rem; margin: 0 0 .6rem; }
.sub { color: var(--muted); font-size: .89rem; margin: 0 0 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .9rem;
  margin-bottom: .8rem;
  box-shadow: var(--shadow);
}
.grid { display: grid; gap: .8rem; }

/* --------------------------------------------------------- Wochennavigation */
.weeknav {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center; gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .4rem;
  margin-bottom: .9rem;
  box-shadow: var(--shadow);
}
.weeknav .arrow {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border-radius: var(--r-sm); color: var(--ink-2);
  font-size: 1.2rem; text-decoration: none;
}
.weeknav .arrow:hover { background: var(--surface-2); text-decoration: none; }
.weeknav .middle { text-align: center; min-width: 0; }
.weeknav .kw { font-weight: 700; font-size: 1rem; display: block; }
.weeknav .range { color: var(--muted); font-size: .78rem; display: block; }
.weeknav .today-link {
  grid-column: 1 / -1; text-align: center; font-size: .8rem;
  padding: .3rem; border-top: 1px solid var(--line); margin-top: .2rem;
}

/* ------------------------------------------------------------- Tageskarten */
.days { display: grid; gap: .7rem; }

.day {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow);
}
.day > .head {
  padding: .55rem .85rem; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: baseline; gap: .5rem;
}
.day > .head .wd { font-weight: 700; font-size: .95rem; }
.day > .head .dt { color: var(--muted); font-size: .8rem; flex: none; }
.day.today { border-color: var(--brand); }
.day.today > .head { background: var(--brand-soft); }
.day.today > .head .wd { color: var(--brand-ink); }
.day > .body { padding: .7rem .85rem; display: grid; gap: .6rem; }

.shift {
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: .6rem .7rem; background: var(--surface);
}
.shift.mine { background: var(--brand-soft); border-color: var(--brand); }
.shift.empty { border-style: dashed; }
.shift .time { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.shift .name { color: var(--muted); font-size: .8rem; }
.shift ul { list-style: none; margin: .5rem 0 0; padding: 0; font-size: .88rem; }
.shift ul li { padding: .1rem 0; }
.shift ul li.me { font-weight: 700; color: var(--brand-ink); }
.nobody { color: var(--bad); font-size: .84rem; font-style: italic; margin-top: .4rem; }
.empty-day { color: var(--muted); font-size: .86rem; font-style: italic; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .55rem 1rem;
  border-radius: var(--r-sm); border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink);
  font-size: .9rem; font-weight: 600; font-family: inherit;
  cursor: pointer; text-decoration: none; text-align: center;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btnrow { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btnrow > form { display: contents; }
/* Auf schmalen Displays stapeln sich Aktionsknöpfe statt zu überlaufen */
@media (max-width: 480px) {
  .btnrow.stack { display: grid; grid-template-columns: 1fr; }
  .btnrow.stack > form { display: block; }
  .btnrow.stack .btn { width: 100%; }
}

/* -------------------------------------------------------------- Formulare */
label { display: block; font-size: .84rem; font-weight: 600; margin: .8rem 0 .25rem; color: var(--ink-2); }

input[type=text], input[type=password], input[type=email], input[type=tel],
input[type=time], input[type=date], input[type=number], select, textarea {
  display: block; width: 100%; max-width: 100%; min-width: 0;
  padding: .6rem .7rem; min-height: var(--tap);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  font-size: 16px;               /* verhindert Auto-Zoom auf iOS */
  font-family: inherit; background: var(--surface); color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand);
}
textarea { min-height: 84px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 4.5 6 8.5 10 4.5' fill='none' stroke='%23667085' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .65rem center;
  background-size: 12px; padding-right: 2rem;
}

/* Feldgruppen: mobil untereinander, ab Tablet nebeneinander */
.field-row { display: grid; gap: .2rem; }
.form-inline { display: grid; gap: .5rem; align-items: end; }
.form-inline .grow { min-width: 0; }
@media (min-width: 620px) {
  .field-row.two { grid-template-columns: 1fr 1fr; gap: .2rem 1rem; }
  .form-inline { grid-template-columns: 1fr auto auto auto; }
  .form-inline.times { grid-template-columns: minmax(0,1fr) 7rem 7rem auto; }
}

.hint { font-size: .79rem; color: var(--muted); margin-top: .3rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-sm); padding: .5rem .8rem .9rem; margin: 0; }
legend { font-size: .82rem; font-weight: 700; padding: 0 .35rem; color: var(--ink-2); }
.choice {
  display: flex; gap: .6rem; align-items: flex-start;
  font-weight: 400; margin-top: .5rem; padding: .5rem;
  border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer;
}
.choice input { width: auto; min-height: 0; margin-top: .3rem; flex: none; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

/* --------------------------------------------------------------- Meldungen */
.alert {
  padding: .75rem .9rem; border-radius: var(--r-sm);
  margin-bottom: .9rem; font-size: .88rem; border: 1px solid;
}
.alert strong { display: block; margin-bottom: .15rem; }
.alert.info { background: var(--brand-soft); border-color: var(--line-2); color: var(--brand-ink); }
.alert.ok   { background: var(--ok-bg);   border-color: var(--ok-line);   color: var(--ok); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.alert.bad  { background: var(--bad-bg);  border-color: var(--bad-line);  color: var(--bad); }

.phone-notice {
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn);
  border-radius: var(--r); padding: .8rem .9rem; margin-bottom: .9rem; font-size: .87rem;
}
.phone-notice strong { display: block; font-size: .93rem; margin-bottom: .2rem; }

/* ------------------------------------------------ Tabellen -> Karten (mobil) */
.table-wrap { margin: 0 -.15rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.data th, table.data td { text-align: left; vertical-align: top; }

/* Mobil: jede Zeile wird zur Karte, Spaltenname kommt aus data-label */
@media (max-width: 760px) {
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead { display: none; }
  table.data tr {
    border: 1px solid var(--line); border-radius: var(--r-sm);
    padding: .6rem .7rem; margin-bottom: .55rem; background: var(--surface);
  }
  table.data tr:last-child { margin-bottom: 0; }
  table.data td {
    border: none; padding: .18rem 0;
    display: grid; grid-template-columns: 8.5rem minmax(0, 1fr); gap: .6rem;
  }
  table.data td::before {
    content: attr(data-label);
    font-size: .78rem; font-weight: 600; color: var(--muted);
  }
  table.data td[data-label=""]::before, table.data td:not([data-label])::before { content: none; }
  table.data td[data-label=""], table.data td:not([data-label]) { display: block; }
  table.data td.actions { margin-top: .5rem; }
  table.data td.actions .btn { width: 100%; }
}

/* Ab Tablet klassische Tabelle */
@media (min-width: 761px) {
  table.data th, table.data td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); }
  table.data th {
    background: var(--surface-2); font-size: .76rem; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); font-weight: 700;
  }
  table.data tr:last-child td { border-bottom: none; }
}

/* Schlüssel-Wert-Tabellen (Profil, Anfragedetails) */
table.kv { width: 100%; border-collapse: collapse; font-size: .89rem; }
table.kv th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem;
  padding: .35rem .6rem .1rem 0; vertical-align: top; width: 40%;
}
table.kv td { padding: .35rem 0 .1rem; vertical-align: top; }
@media (max-width: 560px) {
  table.kv, table.kv tbody, table.kv tr, table.kv th, table.kv td { display: block; width: 100%; }
  table.kv tr { padding: .4rem 0; border-bottom: 1px solid var(--line); }
  table.kv tr:last-child { border-bottom: none; }
  table.kv th { padding: 0; }
  table.kv td { padding: 0; }
}

/* ------------------------------------------------------------------- Chips */
.tag {
  display: inline-block; padding: .12rem .5rem; border-radius: var(--r-full);
  font-size: .73rem; font-weight: 700; white-space: nowrap; border: 1px solid transparent;
}
.tag.grey  { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.tag.blue  { background: var(--brand-soft); color: var(--brand-ink); }
.tag.green { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok-line); }
.tag.amber { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.tag.red   { background: var(--bad-bg);  color: var(--bad);  border-color: var(--bad-line); }

.person-chip {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-full); padding: .25rem .3rem .25rem .7rem;
  font-size: .84rem; margin: .15rem .15rem .15rem 0; max-width: 100%;
}
.person-chip form { display: inline-flex; }
.person-chip button {
  border: none; background: var(--line-2); color: var(--ink-2);
  border-radius: var(--r-full); width: 22px; height: 22px;
  font-size: .8rem; line-height: 1; cursor: pointer; padding: 0; flex: none;
}
.person-chip button:hover { background: var(--bad); color: #fff; }
.person-chip.inactive { background: var(--bad-bg); border-color: var(--bad-line); opacity: .8; }
.person-chip.inactive > :first-child { text-decoration: line-through; }

.note-chip {
  display: inline-block; background: var(--warn-bg); color: var(--warn);
  border: 1px solid var(--warn-line); border-radius: var(--r-sm);
  padding: 0 .35rem; font-size: .74rem; font-weight: 600;
  margin-left: .3rem; text-decoration: none;
}

.pw-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.15rem; letter-spacing: .08em;
  background: var(--ink); color: #4ade80;
  padding: .6rem .9rem; border-radius: var(--r-sm);
  display: inline-block; user-select: all; word-break: break-all; max-width: 100%;
}

/* -------------------------------------------------------------- Kachelmenü */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.tile {
  display: flex; flex-direction: column; gap: .3rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: .85rem; box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; min-height: 84px;
}
.tile:hover { border-color: var(--brand); text-decoration: none; box-shadow: var(--shadow-lg); }
.tile .t-title { font-weight: 700; font-size: .92rem; display: flex; align-items: center; gap: .35rem; }
.tile .t-sub { font-size: .76rem; color: var(--muted); }
.tile svg { width: 18px; height: 18px; flex: none; color: var(--brand); }
@media (min-width: 620px) { .tiles { grid-template-columns: repeat(3, 1fr); } }

/* ---------------------------------------------------------------- Aufklapp */
details.inline > summary {
  cursor: pointer; font-size: .85rem; color: var(--brand);
  padding: .5rem 0; list-style: none; font-weight: 600;
  min-height: var(--tap); display: flex; align-items: center; gap: .3rem;
}
details.inline > summary::-webkit-details-marker { display: none; }
details.inline > summary::before { content: "›"; display: inline-block; transition: transform .15s; font-size: 1.1rem; }
details.inline[open] > summary::before { transform: rotate(90deg); }
details.inline > div { padding: .3rem 0 .5rem; }

/* ------------------------------------------------------------------- Login */
.login-wrap { max-width: 400px; margin: 6vh auto 0; padding: 0 .2rem; }
.login-wrap .logo { text-align: center; font-size: 2.4rem; line-height: 1; margin-bottom: .5rem; }
.login-wrap h1, .login-wrap .sub { text-align: center; }

/* ---------------------------------------------------------------- Diverses */
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.stack-list { display: grid; gap: .5rem; }
.spacer { flex: 1; }
.mt { margin-top: .8rem; }

/* ------------------------------------------------------- Ab Tablet/Desktop */
@media (min-width: 900px) {
  main { padding: 1.4rem 1.2rem 3rem; }
  .tabbar { display: none; }
  .nav-desktop {
    display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; justify-content: center;
  }
  .nav-desktop a {
    color: var(--ink-2); padding: .45rem .7rem; border-radius: var(--r-sm);
    font-size: .87rem; font-weight: 600; white-space: nowrap;
  }
  .nav-desktop a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
  .nav-desktop a.active { background: var(--brand-soft); color: var(--brand-ink); }
  .brand { flex: none; }
  .who .name { display: inline; }
  .grid.two { grid-template-columns: 1fr 1fr; }
  .days { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 1.65rem; }
  .weeknav { display: flex; justify-content: center; gap: .8rem; padding: .5rem .8rem; }
  .weeknav .middle { display: flex; align-items: baseline; gap: .7rem; }
  .weeknav .kw, .weeknav .range { display: inline; }
  .weeknav .today-link { grid-column: auto; border: none; margin: 0; padding: 0; }
}
@media (min-width: 1180px) {
  .days { grid-template-columns: repeat(4, 1fr); }
}

@media print {
  .topbar, .tabbar, .btn, details.inline { display: none !important; }
  main { padding: 0; max-width: none; }
  .card, .day { break-inside: avoid; box-shadow: none; }
}

/* ------------------------------------------------- Touch-Trefferflächen
   Auf Touchgeräten müssen Bedienelemente sicher treffbar sein. Die kleinen
   Elemente behalten ihre Optik, bekommen aber eine unsichtbar vergrößerte
   Klickfläche über ein Pseudoelement. */
@media (pointer: coarse), (max-width: 760px) {
  .btn.small { min-height: 42px; padding: .4rem .8rem; }

  .person-chip { padding: .35rem .4rem .35rem .75rem; }
  .person-chip button {
    position: relative; width: 30px; height: 30px; font-size: 1rem;
  }
  .person-chip button::after {
    content: ""; position: absolute; top: -7px; right: -7px; bottom: -7px; left: -7px;
  }

  .weeknav .arrow { font-size: 1.4rem; }
  details.inline > summary { padding: .65rem 0; }
}

/* Abmelden: auf dem Handy nur auf der Profilseite (Platz in der Kopfzeile fehlt),
   ab Desktop zusätzlich direkt in der Kopfzeile. */
.who-link { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; }
.who-link:hover { text-decoration: none; }
.logout-form { display: none; }
@media (min-width: 900px) {
  .logout-form { display: block; }
}
