/* Material 3 Design Tokens — Seed-Farbe #6750A4 (Material Default Purple) */
:root {
  color-scheme: light dark;
  --md-sys-color-primary: #6750A4;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #EADDFF;
  --md-sys-color-on-primary-container: #21005D;
  --md-sys-color-secondary: #625B71;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #E8DEF8;
  --md-sys-color-on-secondary-container: #1D192B;
  --md-sys-color-tertiary: #7D5260;
  --md-sys-color-tertiary-container: #FFD8E4;
  --md-sys-color-on-tertiary-container: #31111D;
  --md-sys-color-error: #B3261E;
  --md-sys-color-on-error: #FFFFFF;
  --md-sys-color-error-container: #F9DEDC;
  --md-sys-color-on-error-container: #410E0B;
  --md-sys-color-background: #FEF7FF;
  --md-sys-color-on-background: #1D1B20;
  --md-sys-color-surface: #FEF7FF;
  --md-sys-color-surface-dim: #DED8E1;
  --md-sys-color-surface-bright: #FEF7FF;
  --md-sys-color-surface-container-lowest: #FFFFFF;
  --md-sys-color-surface-container-low: #F7F2FA;
  --md-sys-color-surface-container: #F3EDF7;
  --md-sys-color-surface-container-high: #ECE6F0;
  --md-sys-color-surface-container-highest: #E6E0E9;
  --md-sys-color-on-surface: #1D1B20;
  --md-sys-color-on-surface-variant: #49454F;
  --md-sys-color-outline: #79747E;
  --md-sys-color-outline-variant: #CAC4D0;
  --md-sys-color-scrim: rgba(0,0,0,0.32);
  --md-sys-color-shadow: rgba(0,0,0,0.15);

  --md-elevation-1: 0 1px 2px rgba(0,0,0,0.30), 0 1px 3px 1px rgba(0,0,0,0.15);
  --md-elevation-2: 0 1px 2px rgba(0,0,0,0.30), 0 2px 6px 2px rgba(0,0,0,0.15);
  --md-elevation-3: 0 1px 3px rgba(0,0,0,0.30), 0 4px 8px 3px rgba(0,0,0,0.15);

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 28px;
  --radius-full: 999px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --md-sys-color-primary: #D0BCFF;
    --md-sys-color-on-primary: #381E72;
    --md-sys-color-primary-container: #4F378B;
    --md-sys-color-on-primary-container: #EADDFF;
    --md-sys-color-secondary: #CCC2DC;
    --md-sys-color-on-secondary: #332D41;
    --md-sys-color-secondary-container: #4A4458;
    --md-sys-color-on-secondary-container: #E8DEF8;
    --md-sys-color-tertiary: #EFB8C8;
    --md-sys-color-tertiary-container: #633B48;
    --md-sys-color-on-tertiary-container: #FFD8E4;
    --md-sys-color-error: #F2B8B5;
    --md-sys-color-on-error: #601410;
    --md-sys-color-error-container: #8C1D18;
    --md-sys-color-on-error-container: #F9DEDC;
    --md-sys-color-background: #141218;
    --md-sys-color-on-background: #E6E0E9;
    --md-sys-color-surface: #141218;
    --md-sys-color-surface-dim: #141218;
    --md-sys-color-surface-bright: #3B383E;
    --md-sys-color-surface-container-lowest: #0F0D13;
    --md-sys-color-surface-container-low: #1D1B20;
    --md-sys-color-surface-container: #211F26;
    --md-sys-color-surface-container-high: #2B2930;
    --md-sys-color-surface-container-highest: #36343B;
    --md-sys-color-on-surface: #E6E0E9;
    --md-sys-color-on-surface-variant: #CAC4D0;
    --md-sys-color-outline: #938F99;
    --md-sys-color-outline-variant: #49454F;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: 'Roboto', 'Roboto Flex', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
body { min-height: 100vh; min-height: 100dvh; }

button, input, textarea, select { font: inherit; color: inherit; }
input[type="text"], input[type="email"], input[type="password"] {
  -webkit-appearance: none;
  appearance: none;
}

/* ===== App Layout ===== */
.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--md-sys-color-surface);
}

/* ===== Top App Bar (Material 3) ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 4px 8px 4px;
  background: var(--md-sys-color-surface);
  min-height: 64px;
}
.top-bar.scrolled { background: var(--md-sys-color-surface-container); }
.top-bar .title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 400;
  margin: 0 4px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  text-align: left;
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}
.top-bar .title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-bar .title .chevron {
  flex-shrink: 0;
  width: 24px; height: 24px;
  opacity: 0.7;
}
.top-bar .title:active { background: var(--md-sys-color-surface-container-high); }
.top-bar .actions { display: flex; align-items: center; gap: 4px; }

/* ===== Icon Button (Material 3 Standard Icon Button) ===== */
.icon-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: background-color .16s ease;
}
.icon-btn:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.icon-btn:active { background: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent); }
.icon-btn svg { width: 24px; height: 24px; pointer-events: none; }

/* ===== Buttons (Material 3) ===== */
.btn {
  height: 40px;
  padding: 0 24px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: box-shadow .16s ease, background-color .16s ease;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.btn-filled:not(:disabled):hover { box-shadow: var(--md-elevation-1); }
.btn-filled:not(:disabled):active { box-shadow: none; }
.btn-tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.btn-outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}
.btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 0 12px;
}
.btn-error {
  background: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

/* ===== FAB (Material 3 Floating Action Button) ===== */
.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right, 0px) + 16px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  width: 56px; height: 56px;
  border-radius: var(--radius-lg);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--md-elevation-3);
  z-index: 15;
  transition: transform .12s ease;
}
.fab:active { transform: scale(0.95); }
.fab svg { width: 24px; height: 24px; }
.fab-extended {
  width: auto;
  padding: 0 20px;
  gap: 8px;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.1px;
}

/* ===== Text Field (Material 3 Outlined) ===== */
.field {
  position: relative;
  margin: 0 0 16px 0;
}
.field input {
  width: 100%;
  height: 56px;
  padding: 16px;
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--radius-xs);
  outline: none;
  transition: border-color .16s ease, border-width .16s ease;
}
.field input:focus {
  border-color: var(--md-sys-color-primary);
  border-width: 2px;
  padding: 15px;
}
.field label {
  position: absolute;
  left: 12px;
  top: 18px;
  padding: 0 4px;
  color: var(--md-sys-color-on-surface-variant);
  background: var(--md-sys-color-surface);
  pointer-events: none;
  transition: transform .16s ease, color .16s ease, font-size .16s ease;
  font-size: 16px;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label {
  transform: translateY(-26px);
  font-size: 12px;
  color: var(--md-sys-color-primary);
}
.field-error { color: var(--md-sys-color-error); font-size: 12px; margin: 4px 16px 0 16px; min-height: 16px; }

/* ===== Card / Surface ===== */
.surface {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-md);
  padding: 16px;
}
.surface-low { background: var(--md-sys-color-surface-container-low); }

/* ===== Section (Page Content) ===== */
.page {
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 96px);
}
.page h2 {
  margin: 16px 0 12px 0;
  font-size: 22px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface);
}
.page p { color: var(--md-sys-color-on-surface-variant); line-height: 1.5; }

/* ===== Login Screen ===== */
.login-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--md-sys-color-surface);
}
.login-card {
  max-width: 400px;
  width: 100%;
  padding: 32px 24px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-xl);
}
.login-card .logo {
  width: 72px; height: 72px;
  border-radius: var(--radius-lg);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
}
.login-card .logo svg { width: 40px; height: 40px; }
.login-card h1 { margin: 0 0 8px; text-align: center; font-size: 24px; font-weight: 400; }
.login-card .subtitle { text-align: center; color: var(--md-sys-color-on-surface-variant); margin-bottom: 24px; }
.login-card .form-actions { margin-top: 8px; display: flex; justify-content: center; }
.login-card .btn-filled { width: 100%; }

/* ===== Items List ===== */
.items-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--radius-md);
  transition: background-color .16s ease;
  position: relative;
  overflow: hidden;
}
.item:active { background: var(--md-sys-color-surface-container-high); }
.item.checked .item-text { text-decoration: line-through; color: var(--md-sys-color-on-surface-variant); }
.item .checkbox {
  width: 24px; height: 24px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 2px solid var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color .12s ease, border-color .12s ease;
}
.item .checkbox.checked {
  background: var(--md-sys-color-primary);
  border-color: var(--md-sys-color-primary);
}
.item .checkbox.checked::after {
  content: '';
  width: 14px; height: 8px;
  border-left: 2px solid var(--md-sys-color-on-primary);
  border-bottom: 2px solid var(--md-sys-color-on-primary);
  transform: rotate(-45deg) translate(2px, -2px);
}
.item-body { flex: 1; min-width: 0; cursor: pointer; }
.item-text { font-size: 16px; word-break: break-word; }
.item-meta { font-size: 12px; color: var(--md-sys-color-on-surface-variant); margin-top: 2px; }
.item-actions { display: flex; gap: 4px; }
.item-actions .icon-btn { width: 40px; height: 40px; }
.item-actions .icon-btn svg { width: 20px; height: 20px; }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--md-sys-color-on-surface-variant);
}
.empty-state .icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.6;
}

/* ===== Quick-Add Bar (above FAB on focus) ===== */
.quick-add {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  max-width: 688px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 16px;
  box-shadow: var(--md-elevation-3);
  z-index: 14;
  transform: translateY(120%);
  opacity: 0;
  transition: transform .25s ease, opacity .2s ease;
}
.quick-add.open { transform: translateY(0); opacity: 1; }
.quick-add input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px;
  color: var(--md-sys-color-on-surface);
  min-width: 0;
}
.quick-add .icon-btn {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}
.quick-add .icon-btn:hover { background: var(--md-sys-color-primary); }

/* ===== Bottom Sheet ===== */
.scrim {
  position: fixed; inset: 0;
  background: var(--md-sys-color-scrim);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 51;
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  max-height: 85vh;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateY(100%);
  transition: transform .25s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sheet.open { transform: translateY(0); }
.sheet .handle {
  width: 32px; height: 4px;
  background: var(--md-sys-color-on-surface-variant);
  opacity: 0.4;
  border-radius: var(--radius-full);
  margin: 12px auto;
}
.sheet .sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 16px 8px;
}
.sheet .sheet-header h3 { margin: 0; font-size: 18px; font-weight: 500; }
.sheet .sheet-body {
  padding: 4px 16px 16px;
  overflow-y: auto;
  flex: 1;
}

/* ===== List Row (für Bottom-Sheet-Listen) ===== */
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color .12s ease;
}
.row:active { background: var(--md-sys-color-surface-container-high); }
.row.active { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.row .row-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.row .row-icon svg { width: 20px; height: 20px; }
.row .row-content { flex: 1; min-width: 0; }
.row .row-title { font-size: 16px; line-height: 1.3; }
.row .row-subtitle { font-size: 13px; color: var(--md-sys-color-on-surface-variant); margin-top: 2px; }
.row .row-trailing { display: flex; gap: 4px; flex-shrink: 0; }

.divider { height: 1px; background: var(--md-sys-color-outline-variant); margin: 8px 0; }

/* ===== Snackbar (Material 3) ===== */
#snackbar {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  max-width: 560px;
  margin: 0 auto;
  background: var(--md-sys-color-on-surface);
  color: var(--md-sys-color-surface);
  padding: 14px 16px;
  border-radius: var(--radius-xs);
  font-size: 14px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  transform: translateY(150%);
  transition: transform .25s ease;
  box-shadow: var(--md-elevation-3);
}
#snackbar.open { transform: translateY(0); }
#snackbar .action {
  color: var(--md-sys-color-primary-container);
  background: transparent;
  border: none;
  padding: 4px 8px;
  cursor: pointer;
  font-weight: 500;
  border-radius: var(--radius-xs);
}

/* ===== Chips / Badges ===== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  letter-spacing: 2px;
}
.chip-primary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: transparent;
}

/* ===== Banner (für Hinweise, z. B. „Passwort jetzt ändern") ===== */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-radius: var(--radius-md);
  margin: 12px 16px 0;
}
.banner .banner-icon { width: 24px; height: 24px; flex-shrink: 0; }
.banner .banner-body { flex: 1; font-size: 14px; line-height: 1.4; }
.banner .banner-action {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: none;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 500;
  border-radius: var(--radius-full);
}

/* ===== Push-Status Pills ===== */
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.status-tile {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--radius-md);
  padding: 12px;
}
.status-tile .label { font-size: 12px; color: var(--md-sys-color-on-surface-variant); }
.status-tile .value { font-size: 18px; margin-top: 4px; }
.status-tile .value.ok { color: #2E7D32; }
.status-tile .value.warn { color: #B26A00; }
.status-tile .value.err { color: var(--md-sys-color-error); }
@media (prefers-color-scheme: dark) {
  .status-tile .value.ok { color: #81C784; }
  .status-tile .value.warn { color: #FFB74D; }
}

/* ===== Dialog (modal) ===== */
.dialog {
  position: fixed;
  left: 24px; right: 24px;
  top: 50%;
  max-width: 480px;
  margin: 0 auto;
  transform: translateY(-50%) scale(0.95);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--radius-xl);
  padding: 24px;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--md-elevation-3);
}
.dialog.open { opacity: 1; transform: translateY(-50%) scale(1); pointer-events: auto; }
.dialog h3 { margin: 0 0 16px; font-size: 24px; font-weight: 400; }
.dialog p { margin: 0 0 16px; color: var(--md-sys-color-on-surface-variant); }
.dialog .dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
}

/* ===== Settings/Listen-Item ===== */
.menu-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--md-sys-color-on-surface);
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
}
.menu-item:hover { background: var(--md-sys-color-surface-container); }
.menu-item:active { background: var(--md-sys-color-surface-container-high); }
.menu-item .menu-icon {
  width: 24px; height: 24px;
  color: var(--md-sys-color-on-surface-variant);
  flex-shrink: 0;
}
.menu-item .menu-label { flex: 1; font-size: 16px; }
.menu-item.danger { color: var(--md-sys-color-error); }
.menu-item.danger .menu-icon { color: var(--md-sys-color-error); }

/* ===== Hidden / Visible Helper ===== */
[hidden] { display: none !important; }
.muted { color: var(--md-sys-color-on-surface-variant); }
