:root {
  --accent: #2bb673;
  --accent-weak: #e8f7ef;
  --bg: #f6f7f8;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #6b7280;
  --r: 14px;
  --shadow: 0 10px 24px rgba(0, 0, 0, .08)
}

/* ===== Base ===== */
* {
  box-sizing: border-box
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: clamp(16px, 2vw, 18px)/1.4 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.wrap {
  margin: 0 auto;
  max-width: 1080px;
  padding: 16px
}

.card {
  background: var(--card);
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px
}

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap
}

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr))
}

label {
  color: var(--muted);
  display: block;
  font-size: 14px;
  margin-bottom: 6px
}

input,
select,
button,
textarea {
  font: inherit
}

input,
select,
textarea {
  border: 1px solid #c5c8cf;
  border-radius: 16px;
  padding: 2px 6px;
  width: 100%;
  background: #fff
}

textarea {
  min-height: 80px
}

button {
  background: #fff;
  border: 2px solid #3069dd5c;
  border-radius: 12px;
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 700;
  maring: 5px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff
}

button.icon {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 12px;
  font-size: 18px;
  line-height: 1;
}

.logout-icon {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.1;
}

button:disabled {
  opacity: .6;
  cursor: not-allowed
}

button.primary:disabled {
  background: #cbd5e1;
  border-color: #cbd5e1;
  color: #64748b;
}

button.mobileIcsRow {
  display: none !important;
}

.badge {
  background: var(--accent-weak);
  border: 1px solid #cfeede;
  color: #177a4f;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: clamp(12px, 2vw, 14px);
}

small,
.muted {
  color: var(--muted)
}

table {
  width: 100%;
  border-collapse: collapse
}

th,
td {
  border-bottom: 1px solid #eef0f3;
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 600
}

.note {
  color: #b45309;
  background: #fff7ed;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 8px 10px
}

h1 {
  font-size: clamp(18px, 2vw, 22px);
  margin: 0
}

h2 {
  font-size: 18px;
  margin: 0
}

h3 {
  font-size: 16px;
  margin: 0 0 8px
}

.empMeta {
  font-weight: 700
}

.kicker {
  font-size: clamp(14px, 2vw, 16px);
  color: var(--muted)
}

a.ics {
  white-space: nowrap
}

/* ===== Overlay ===== */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90
}

#overlay .dialog {
  width: min(92vw, 520px);
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25)
}

/* ===== Mobile RO-Toolbar ===== */
#mobileBar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  background: transparent;
  margin-bottom: 8px
}



/* ===== Print (generisch) ===== */
.print-only {
  display: none
}

.no-print-inline {
  display: inline
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm
  }

  body {
    background: #fff
  }

  /* 1) Verhindert „Geisterseite“ durch fixierte Höhe */
  html,
  body {
    height: auto !important;
    overflow: visible !important;
  }

  .no-print {
    display: none !important
  }

  .wrap {
    max-width: none;
    padding: 0
  }

  .card {
    box-shadow: none;
    border: 0;
    padding: 0
  }

  #printHeader {
    display: block !important;
    margin-bottom: 10px;
    border-bottom: 1px solid #ddd;
    padding-bottom: 6px
  }

  #phName {
    font-size: 22px;
    font-weight: 800
  }

  table {
    font-size: 14px
  }

  th,
  td {
    padding: 6px;
    border-bottom: 1px solid #ddd
  }
}

/* Print-Header Typografie */
@media print {
  #phTitle {
    font-size: 20px;
    font-weight: 800;
    line-height: 1.1
  }

  #phName {
    font-size: 14px;
    margin-top: 2px
  }

  #tblVacation,
  #tblPikett {
    width: 180mm !important;
    margin: 0 auto;
  }
}


/* ===== Utilities ===== */
.hidden {
  display: none !important
}

.right {
  margin-left: auto
}

.input-hint {
  font-size: 16px;
  color: #9ca3af;
  margin: 4px;
  font-weight: 700
}

input.invalid {
  border: 2px solid #ef4444;
  outline: 0
}

/* ===== Mobile (SCREEN ≤ 640px): Ferien übersichtlich als Karten ===== */


.row-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-inline input {
  flex: 1 1 auto;
  min-width: 0;
}

.row-inline button {
  flex: 0 0 auto;
  white-space: nowrap;
}

@media screen and (min-width: 641px) {
  #vacationInputs {
    grid-template-columns: repeat(5, minmax(0, 1fr)) 44px;
  }

  #pikettInputs {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 44px;
  }

  .form-save-control {
    display: flex;
    align-items: flex-end;
  }

  .form-save-control .icon {
    width: 44px;
    height: 44px;
  }
}


.row-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-inline input {
  flex: 1 1 auto;
  min-width: 0;
}

.row-inline button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.row-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-inline input {
  flex: 1 1 auto;
  min-width: 0;
}

.row-inline button {
  flex: 0 0 auto;
  white-space: nowrap;
}

input.edit-v-from {
  max-width: 140px;
}

input.edit-v-to {
  max-width: 140px;
}

select.edit-v-half {
  max-width: 140px;
}

label {
  font-size: clamp(15px, 2vw, 17px);
  font-weight: 700;
}

body {
  font-size: clamp(14px, 2vw, 16px);
}

input {
  padding: 4px 10px;
  font-size: clamp(14px, 2vw, 16px);
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 40px;
}

.header-title-row h1 {
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
  line-height: 1.2;
}

.header-year-controls,
.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.header-year-controls select {
  width: 96px;
  min-width: 96px;
  height: 44px;
  padding: 0 10px;
  border: 2px solid #3069dd5c;
  border-radius: 12px;
  background: #fff;
  font-weight: 700;
}

.header-year-controls .icon,
.header-actions .icon {
  width: 44px;
  height: 44px;
}

.header-controls {
  width: min(100%, 360px);
  align-items: center;
  flex-wrap: nowrap;
}

.header-controls label {
  margin-bottom: 0;
  white-space: nowrap;
}

.header-controls select {
  min-width: 0;
}

.holiday-source-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.holiday-source-actions small {
  flex: 1 1 auto;
  min-width: 0;
}

#btnShowHolidays {
  flex: 0 0 auto;
  margin-right: 6px;
  white-space: nowrap;
}

/* ===== Mobile: echte Einspalten-Ansicht ohne horizontales Scrollen ===== */
@media screen and (max-width: 640px) {
  html,
  body {
    width: 100%;
    min-width: 0;
    margin: 0;
    overflow-x: clip;
  }

  .wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 8px;
  }

  .card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 10px;
    border-radius: 12px;
  }

  .grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 9px;
  }

  .form-save-control:has(.hidden) {
    display: none;
  }

  header.bar {
    align-items: stretch !important;
  }

  .app-header > .header-title-row,
  .app-header > .header-controls {
    flex: 1 1 100%;
    min-width: 0;
  }

  .app-header > .header-controls {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 7px;
  }

  #btnLogout {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    padding: 0;
  }

  .header-title-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "title actions"
      "year year";
    gap: 7px 10px;
    align-items: center;
  }

  .header-title-row h1 {
    grid-area: title;
    margin: 0;
    font-size: clamp(20px, 6vw, 24px);
    line-height: 1.18;
  }

  .header-actions {
    grid-area: actions;
    justify-self: end;
  }

  .header-year-controls {
    grid-area: year;
    justify-self: start;
  }

  #mobileBar {
    display: block;
  }

  #mobileBar .card {
    gap: 6px !important;
    justify-content: space-between !important;
  }

  #mobileBar p {
    margin-inline: 0 !important;
  }

  #mobileBar #mRest {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .holiday-source-actions {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .holiday-source-actions small {
    flex-basis: 100%;
  }

  #btnShowHolidays {
    margin-left: auto;
  }

  #ferienCard > .bar:first-child,
  #pikettCard > .bar:first-child,
  #extraHolidaysCard > .bar:first-child {
    align-items: stretch;
  }

  #ferienCard > .bar:first-child > h2,
  #ferienCard > .bar:first-child > .bar,
  #pikettCard > .bar:first-child > h2,
  #pikettCard > .bar:first-child > .bar,
  #extraHolidaysCard > .bar:first-child > h2,
  #extraHolidaysCard > .bar:first-child > small {
    flex: 1 1 100%;
    min-width: 0;
  }

  #ferienCard > .bar:first-child > .bar,
  #pikettCard > .bar:first-child > .bar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  #ferienCard > .bar:first-child button,
  #pikettCard > .bar:first-child button {
    width: 100%;
    min-width: 0;
    padding-inline: 6px;
    white-space: normal;
  }

  #btnPdfFerien,
  #btnShareFerien,
  #btnPdfPikett,
  #btnSharePikett {
    white-space: nowrap !important;
    overflow-wrap: normal;
    font-size: clamp(11px, 3.4vw, 16px);
  }

  button {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  input,
  select,
  textarea {
    min-width: 0;
    max-width: 100%;
  }

  #overlay {
    padding: 8px;
  }

  #overlay .dialog,
  #holidayOverlay > div {
    width: 100% !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 16px) !important;
  }

  /* Tabellenzeilen werden auf dem Handy zu beschrifteten Karten. */
  table {
    display: block;
    width: 100%;
    max-width: 100%;
  }

  table thead {
    display: none;
  }

  table tbody {
    display: block;
  }

  table tbody tr {
    display: block;
    width: 100%;
    min-width: 0;
    margin: 0 0 10px;
    padding: 7px 9px;
    border: 1px solid #e5e7eb;
    border-radius: 11px;
    background: #fff;
  }

  table tbody td {
    display: grid;
    grid-template-columns: minmax(72px, 34%) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
    padding: 7px 0;
    text-align: right;
    overflow-wrap: anywhere;
  }

  table tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    text-align: left;
  }

  table tbody td:empty {
    display: none;
  }

  table tbody td button {
    min-width: 42px;
    min-height: 42px;
  }

  /* Kalender-, Bearbeiten- und Löschen-Button gleich breit;
     die beiden Aktionsbuttons bleiben in derselben Zeile. */
  #tblVacation tbody td[data-role="ics"],
  #tblVacation tbody td[data-role="action"],
  #tblPikett tbody td[data-role="ics"],
  #tblPikett tbody td[data-role="action"] {
    grid-template-columns: minmax(72px, 34%) repeat(2, minmax(0, 1fr));
  }

  #tblVacation tbody td[data-role="ics"] button,
  #tblVacation tbody td[data-role="action"] button,
  #tblPikett tbody td[data-role="ics"] button,
  #tblPikett tbody td[data-role="action"] button {
    width: 100%;
    min-width: 0;
    height: 44px;
    margin: 0;
    padding: 4px 8px;
  }

  /* Auf Mobilgeräten stehen Kalender und Bearbeiten in einer Aktionszeile.
     Löschen wird erst im Bearbeitungsmodus angeboten. */
  #tblVacation tbody td[data-role="ics"],
  #tblPikett tbody td[data-role="ics"] {
    display: none;
  }

  #tblVacation tbody td[data-role="action"] .mobileIcsRow,
  #tblPikett tbody td[data-role="action"] .mobileIcsRow {
    display: block !important;
  }

  #tblVacation tbody td[data-role="action"] .delRow,
  #tblPikett tbody td[data-role="action"] .delRow {
    display: none;
  }

  #tblVacation tbody tr:has(.saveRow) td[data-role="action"],
  #tblPikett tbody tr:has(.saveRow) td[data-role="action"] {
    grid-template-columns: minmax(72px, 34%) repeat(3, minmax(0, 1fr));
  }

  /* Im Bearbeitungsmodus liegen Tage und ICS exakt unter den
     140 px breiten Datums-/Auswahlfeldern. */
  #tblVacation tbody tr:has(.saveRow) td:not([data-role="action"]),
  #tblPikett tbody tr:has(.saveRow) td:not([data-role="action"]) {
    grid-template-columns: minmax(72px, 34%) minmax(0, 140px) minmax(0, 1fr);
  }

  #tblVacation tbody tr:has(.saveRow) td:not([data-role="action"]) input,
  #tblVacation tbody tr:has(.saveRow) td:not([data-role="action"]) select,
  #tblPikett tbody tr:has(.saveRow) td:not([data-role="action"]) input,
  #tblPikett tbody tr:has(.saveRow) td:not([data-role="action"]) select {
    grid-column: 2;
    width: 100%;
  }

  #tblVacation tbody tr:has(.saveRow) td[data-role="days"],
  #tblVacation tbody tr:has(.saveRow) td[data-role="ics"],
  #tblPikett tbody tr:has(.saveRow) td[data-role="days"],
  #tblPikett tbody tr:has(.saveRow) td[data-role="ics"] {
    text-align: center;
  }

  table tbody td input,
  table tbody td select {
    width: 100%;
    max-width: none;
  }

  table tfoot {
    display: table;
    width: 100%;
    table-layout: fixed;
  }

  table tfoot th,
  table tfoot td {
    padding: 8px 4px;
    overflow-wrap: anywhere;
  }

  .vacTotalLine {
    display: flex;
    flex-wrap: wrap;
    gap: 3px 6px;
  }

  .row-inline {
    flex-wrap: wrap;
  }

  .row-inline input,
  .row-inline button {
    flex: 1 1 100%;
    width: 100%;
  }
}

@media screen and (max-width: 380px) {
  #ferienCard > .bar:first-child > .bar,
  #pikettCard > .bar:first-child > .bar,
  .app-header > .header-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-header > .header-controls > label {
    margin-bottom: 0;
  }

  table tbody td {
    grid-template-columns: minmax(64px, 31%) minmax(0, 1fr);
  }

  #tblVacation tbody td[data-role="ics"],
  #tblVacation tbody td[data-role="action"],
  #tblPikett tbody td[data-role="ics"],
  #tblPikett tbody td[data-role="action"] {
    grid-template-columns: minmax(64px, 31%) repeat(2, minmax(0, 1fr));
  }

  #tblVacation tbody tr:has(.saveRow) td:not([data-role="action"]),
  #tblPikett tbody tr:has(.saveRow) td:not([data-role="action"]) {
    grid-template-columns: minmax(64px, 31%) minmax(0, 140px) minmax(0, 1fr);
  }

  #tblVacation tbody tr:has(.saveRow) td[data-role="action"],
  #tblPikett tbody tr:has(.saveRow) td[data-role="action"] {
    grid-template-columns: minmax(64px, 31%) repeat(3, minmax(0, 1fr));
  }
}
