:root {
  color-scheme: light dark;
  --bg: #0b1020;
  --card: #111a33;
  --text: #eef2ff;
  --muted: #b7c1e3;
  --accent: #8b7bff;
  --danger: #ff3b5f;
  --warning: #f6c453;
  --border: rgba(255, 255, 255, 0.08);
  /* slightly lighter surfaces */
  --panel: rgba(255,255,255,0.045);
  --input: rgba(255,255,255,0.06);
  --dialog: #0f1730;
  --shadowBackdrop: rgba(0,0,0,0.55);

  /* buttons (dark default) */
  --btnPrimaryBg: var(--accent);
  --btnPrimaryText: #ffffff;
  --btnPrimaryBorder: rgba(255,255,255,0.14);
  --btnSecondaryBg: rgba(255,255,255,0.14);
  --btnSecondaryText: var(--text);
  --btnSecondaryBorder: rgba(255,255,255,0.18);
  --btnDangerBg: rgba(255, 59, 95, 0.28);
  --btnDangerText: #ffffff;
  --btnDangerBorder: rgba(255, 59, 95, 0.55);

  --btnWarningBg: rgba(246, 196, 83, 0.22);
  --btnWarningText: #fff7db;
  --btnWarningBorder: rgba(246, 196, 83, 0.6);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --text: #0b1020;
    --muted: #4a567a;
    --accent: #2f5bff;
    --danger: #d61f3c;
    --warning: #c98a08;
    --border: rgba(11, 16, 32, 0.12);
    --panel: rgba(255,255,255,0.55);
    --input: rgba(255,255,255,0.85);
    --dialog: #ffffff;
    --shadowBackdrop: rgba(11,16,32,0.28);

    /* buttons (light) */
    --btnPrimaryBg: var(--accent);
    --btnPrimaryText: #ffffff;
    --btnPrimaryBorder: rgba(11,16,32,0.18);
    --btnSecondaryBg: rgba(11,16,32,0.06);
    --btnSecondaryText: var(--text);
    --btnSecondaryBorder: rgba(11,16,32,0.16);
    --btnDangerBg: var(--danger);
    --btnDangerText: #ffffff;
    --btnDangerBorder: rgba(11,16,32,0.18);

    --btnWarningBg: rgba(201, 138, 8, 0.14);
    --btnWarningText: #5a3b00;
    --btnWarningBorder: rgba(201, 138, 8, 0.35);
  }
}

/* Hide app content when not authenticated */
body:not(.isAuthed) .authedOnly { display: none !important; }

* { box-sizing: border-box; }

html {
  /* Prevent iOS Safari from auto-resizing text and causing layout width shifts */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
  background: var(--bg);
  color: var(--text);
}

@media (prefers-color-scheme: light) {
  body {
    background: var(--bg);
  }
}

.header {
  padding: 10px 10px 4px;
  max-width: 1000px;
  margin: 0 auto;
}

.header h1 { margin: 0 0 3px; font-size: 20px; }

.sub { margin: 0; color: var(--muted); }

.link { color: var(--muted); text-decoration: underline; }
.link:visited { color: var(--muted); }

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 4px 10px 14px;
  display: grid;
  gap: 8px;
}

/* Make room for the bottom-docked add card */
body.isAuthed .container {
  padding-bottom: calc(14px + 140px);
}

.dockCard {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
  width: min(1000px, calc(100vw - 20px));
  z-index: 80;
  box-shadow: 0 18px 50px rgba(0,0,0,0.35);
}

/* Make the bottom add card slightly more opaque */
.dockCard.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.08));
  backdrop-filter: blur(14px);
}

@media (prefers-color-scheme: light) {
  .dockCard.card {
    background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.86));
  }
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  backdrop-filter: blur(10px);
}

.card h2 { margin: 0 0 8px; font-size: 16px; }

.form {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  align-items: end;
}

.suggestions {
  display: none;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.suggestions.show { display: block; }

.suggestItem {
  padding: 10px 12px;
  background: #000;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.suggestItem:hover {
  background: #0b0b0b;
}

.suggestItem:last-child { border-bottom: none; }

.suggestItem .meta { color: var(--muted); font-size: 12px; margin-left: 8px; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

/* iOS Safari auto-zoom on focus happens when font-size < 16px.
   Keep form controls at 16px to maintain a stable viewport width. */
input,
select,
textarea,
button {
  font-size: 16px;
}

input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text);
}

select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text);
}

/* Ensure dropdown options are readable in dark mode and light mode */
select option,
select optgroup {
  background: var(--card);
  color: var(--text);
}

/* Some browsers style the native dropdown differently; provide a focused surface color */
select:focus {
  background: color-mix(in srgb, var(--input) 85%, black 15%);
}

button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--btnPrimaryBg);
  border-color: var(--btnPrimaryBorder);
  color: var(--btnPrimaryText);
  cursor: pointer;
  white-space: nowrap;
}

button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--btnPrimaryBg) 65%, transparent);
  outline-offset: 2px;
}

button.secondary {
  background: var(--btnSecondaryBg);
  border-color: var(--btnSecondaryBorder);
  color: var(--btnSecondaryText);
}

button.danger {
  background: var(--btnDangerBg);
  border-color: var(--btnDangerBorder);
  color: var(--btnDangerText);
}

button.warning {
  background: var(--btnWarningBg);
  border-color: var(--btnWarningBorder);
  color: var(--btnWarningText);
}

.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.status { margin: 6px 0 12px; color: var(--muted); font-size: 13px; min-height: 18px; }


.list {
  display: grid;
  gap: 8px;
}

.item {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  background: var(--panel);
}

.itemTop {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.itemName {
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.itemMeta {
  margin-top: 6px;
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

.itemActions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.listHeader {
  align-items: flex-end;
}

.listActions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter {
  display: grid;
  gap: 6px;
}

.filter input {
  min-width: 140px;
}

.filter select {
  min-width: 140px;
}

/* auth buttons a bit smaller */
#loginBtn,
#signupBtn,
#logoutBtn {
  padding: 6px 8px;
}

.iconBtn {
  padding: 6px;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.iconBtn svg {
  width: 18px;
  height: 18px;
  display: block;
}

.actions { display: flex; gap: 8px; }

.dialog::backdrop { background: var(--shadowBackdrop); }

.dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  background: var(--dialog);
  color: var(--text);
  width: min(520px, calc(100vw - 24px));
}

.dialogInner { padding: 14px; }

.dlgTitle { margin: 0 0 10px; font-size: 16px; }

.dlgBody { display: grid; gap: 10px; }

.dlgRow { display: grid; grid-template-columns: 92px 1fr; gap: 10px; align-items: center; }

.dlgLabel { color: var(--muted); font-size: 12px; }

.dlgValue { font-size: 14px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.chip.secondary { color: var(--muted); }

.dlgActions { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 0 0; }

.dlgActions button { min-width: 92px; }

@media (max-width: 760px) {
  .header { padding: 8px 10px 4px; }
  .header h1 { font-size: 20px; }

  /* Mobile: keep header compact and prevent buttons from wrapping */
  .header .row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .header .sub {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #authUser {
    max-width: 48vw;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .actions {
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .actions button {
    flex: 0 0 auto;
  }

  /* Keep a stable readable layout on mobile */
  .container { padding: 4px 10px 12px; gap: 8px; max-width: 560px; }

  body.isAuthed .container {
    padding-bottom: calc(12px + 150px);
  }

  .dockCard {
    width: min(560px, calc(100vw - 20px));
    bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  }
  .card { padding: 10px; }
  .card h2 { font-size: 15px; margin-bottom: 8px; }
  .form { grid-template-columns: 1fr; }

  /* Make buttons denser (keep >=16px font-size to avoid iOS zoom) */
  button { padding: 8px 10px; }

  .listActions {
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .filter {
    min-width: 140px;
  }

  .filter input {
    min-width: 140px;
  }

  .filter select {
    min-width: 140px;
  }

  /* Mobile: keep task action buttons in one row; allow horizontal scroll if needed */
  .itemTop {
    flex-direction: column;
    align-items: stretch;
  }

  .itemActions {
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }

  .itemActions button {
    flex: 0 0 auto;
  }

  .dlgRow { grid-template-columns: 80px 1fr; }

  /* (kept globally) */
}
