/* Inspired - phone-first styles. Light and dark mode via CSS variables. */

:root {
  color-scheme: light dark;

  --bg: #f7f7fb;
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #1c1d26;
  --muted: #5f6272;
  --border: #dfe1ea;

  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #e8e7fc;

  /* Energy colors: solid (selected button) + soft (badge background) + ink (badge text) */
  --low: #15803d;
  --low-soft: #dcf5e4;
  --low-ink: #14532d;
  --medium: #b45309;
  --medium-soft: #fdefd3;
  --medium-ink: #78350f;
  --high: #dc2626;
  --high-soft: #fde2e0;
  --high-ink: #7f1d1d;

  /* v2: toast (inverted surface), dialog backdrop, danger text */
  --toast-bg: #1c1d26;
  --toast-text: #ffffff;
  --toast-action: #a5b4fc;
  --backdrop: rgba(17, 18, 24, 0.45);
  --danger: #b91c1c;

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --gap: 16px;
  --fab: 56px; /* the round + button */

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111218;
    --surface: #1b1c24;
    --surface-2: #262833;
    --text: #ececf2;
    --muted: #a0a3b3;
    --border: #2f3240;

    --accent: #818cf8;
    --accent-text: #111218;
    --accent-soft: #2a2b4d;

    --low: #4ade80;
    --low-soft: #173a26;
    --low-ink: #a7f3c0;
    --medium: #fbbf24;
    --medium-soft: #3d2e10;
    --medium-ink: #fde68a;
    --high: #f87171;
    --high-soft: #45201f;
    --high-ink: #fecaca;

    --toast-bg: #ececf2;
    --toast-text: #111218;
    --toast-action: #4f46e5;
    --backdrop: rgba(0, 0, 0, 0.6);
    --danger: #f87171;
  }
}

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

[hidden] {
  display: none !important;
}

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

html,
body {
  margin: 0;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p,
ul {
  margin: 0;
}

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

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Layout: centered column, respects notch and home bar */
.app {
  max-width: 560px;
  margin: 0 auto;
  padding-top: calc(env(safe-area-inset-top) + 20px);
  padding-right: calc(env(safe-area-inset-right) + var(--gap));
  /* room for the fixed + button so it never covers the last card */
  padding-bottom: calc(env(safe-area-inset-bottom) + var(--fab) + 40px);
  padding-left: calc(env(safe-area-inset-left) + var(--gap));
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* 1. Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-side {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

/* Log out: small text button, still a 44px tap target */
.logout {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 4px 0 10px;
  font-size: 15px;
  font-weight: 500;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--accent);
  white-space: nowrap;
}

.title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.open-count {
  color: var(--muted);
  font-size: 15px;
}

/* 2. Search */
.search input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  font-size: 17px; /* 16px+ stops iOS zooming on focus */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  -webkit-appearance: none;
  appearance: none;
}

.search input::placeholder {
  color: var(--muted);
}

/* 3-5. Filters */
.filter {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.filter-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Segmented buttons (energy, time) */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 4px;
  font-size: 15px;
  font-weight: 500;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  white-space: nowrap;
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.segmented button.energy-low[aria-pressed="true"] {
  background: var(--low);
}

.segmented button.energy-medium[aria-pressed="true"] {
  background: var(--medium);
}

.segmented button.energy-high[aria-pressed="true"] {
  background: var(--high);
}

@media (prefers-color-scheme: light) {
  .segmented button.energy-low[aria-pressed="true"],
  .segmented button.energy-medium[aria-pressed="true"],
  .segmented button.energy-high[aria-pressed="true"] {
    color: #ffffff;
  }
}

@media (prefers-color-scheme: dark) {
  .segmented button.energy-low[aria-pressed="true"],
  .segmented button.energy-medium[aria-pressed="true"],
  .segmented button.energy-high[aria-pressed="true"] {
    color: #111218;
  }
}

/* Area chips: the row scrolls sideways, the page does not */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  max-width: 100%;
  min-width: 0;
  /* bleed to the screen edges so chips scroll under the gutter */
  margin-left: calc(-1 * var(--gap));
  margin-right: calc(-1 * var(--gap));
  padding: 2px var(--gap);
  scroll-padding: 0 var(--gap);
}

.chips::-webkit-scrollbar {
  display: none;
}

.chips button {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 16px;
  font-size: 15px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.chips button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* 6 + 10. Actions */
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pick {
  flex: 1 1 auto;
  min-height: var(--tap);
  padding: 0 18px;
  font-size: 16px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: var(--radius-sm);
}

.pick:disabled {
  opacity: 0.45;
  cursor: default;
}

.clear {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 8px;
  font-size: 15px;
  background: none;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* 13. Load error */
.load-error {
  padding: 14px 16px;
  background: var(--high-soft);
  color: var(--high-ink);
  border-radius: var(--radius-sm);
}

/* 14. Login screen: full screen, centered card, respects notch and home bar.
   app.js shows #login and hides main + #add when you're not logged in. */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: calc(env(safe-area-inset-top) + 24px);
  padding-right: calc(env(safe-area-inset-right) + var(--gap));
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
  padding-left: calc(env(safe-area-inset-left) + var(--gap));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-card {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 24px var(--gap) var(--gap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.login-intro {
  color: var(--muted);
  font-size: 15px;
}

.login-form {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* Keep me logged in: the whole row is a 44px tap target */
.login-remember {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
}

.login-remember input {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.login-remember label {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  min-height: var(--tap);
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.login-error {
  padding: 12px 14px;
  background: var(--high-soft);
  color: var(--high-ink);
  border-radius: var(--radius-sm);
  font-size: 15px;
}

.login-error:empty {
  display: none;
}

.login-submit {
  width: 100%;
  min-height: 48px;
  padding: 0 18px;
  font-size: 17px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: var(--radius-sm);
}

.login-submit:disabled {
  opacity: 0.45;
  cursor: default;
}

/* 7. Results */
.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.results-count {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.task-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Task card
   app.js builds: li.card > .card-main (> .card-title, .card-note, .badges > .badge)
                          + .card-actions (> button.edit-btn, button.done-btn) */
.card {
  padding: 14px 12px 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  overflow-wrap: anywhere;
}

.card-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Edit: small text button, still a 44px tap target */
.edit-btn {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 8px;
  font-size: 15px;
  font-weight: 500;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--accent);
}

/* Done: a round check, 44x44 (the check is drawn in CSS, app.js leaves the button empty) */
.done-btn {
  position: relative;
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  min-width: var(--tap);
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
}

.done-btn::before {
  /* the visible circle (32px) inside the 44px tap area */
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
}

.done-btn::after {
  /* the check mark */
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 13px;
  margin: -8px 0 0 -4px;
  border-right: 2.5px solid currentColor;
  border-bottom: 2.5px solid currentColor;
  transform: rotate(45deg);
}

.done-btn:active::before,
.done-btn:focus-visible::before {
  border-color: var(--low);
  background: var(--low-soft);
}

.done-btn:active {
  color: var(--low-ink);
}

.done-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.card-title {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.card-note {
  font-size: 15px;
  color: var(--muted);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge-low {
  background: var(--low-soft);
  color: var(--low-ink);
}

.badge-medium {
  background: var(--medium-soft);
  color: var(--medium-ink);
}

.badge-high {
  background: var(--high-soft);
  color: var(--high-ink);
}

/* Owner badge on the partner's cards: neutral, never an energy color */
.badge-owner {
  background: transparent;
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--border);
}

/* Picked task: highlighted at the top of the results */
.picked {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picked-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.picked .card {
  border: 2px solid var(--accent);
  background: var(--accent-soft);
}

.picked-none {
  padding: 14px 16px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius);
}

/* 9. Empty state */
.empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius);
}

/* 8. Lower energy: visually quieter */
.lower {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.lower-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.task-list-quiet .card {
  background: transparent;
  opacity: 0.8;
}

.task-list-quiet .card-title {
  font-size: 16px;
  font-weight: 500;
}

/* 12. Add button: round +, fixed bottom right, above the home bar.
   On wide screens it stays at the right edge of the centered column. */
.add {
  position: fixed;
  z-index: 10;
  right: calc(max(var(--gap), (100vw - 560px) / 2 + var(--gap)) + env(safe-area-inset-right));
  bottom: calc(env(safe-area-inset-bottom) + var(--gap));
  width: var(--fab);
  height: var(--fab);
  padding: 0;
  font-size: 32px;
  font-weight: 400;
  line-height: 1;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Undo toast: fixed at the bottom, above the home bar and the + button */
.toast {
  position: fixed;
  z-index: 20;
  left: calc(env(safe-area-inset-left) + var(--gap));
  right: calc(env(safe-area-inset-right) + var(--gap));
  bottom: calc(env(safe-area-inset-bottom) + var(--gap) + var(--fab) + 12px);
  max-width: 528px;
  margin: 0 auto;
  min-height: 52px;
  padding: 4px 6px 4px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--toast-bg);
  color: var(--toast-text);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.toast-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
}

.toast-undo {
  flex: 0 0 auto;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 14px;
  font-size: 16px;
  font-weight: 700;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--toast-action);
}

/* Task form dialog (add and edit).
   Docked near the top so the text fields stay above the iPhone keyboard.
   It scrolls inside itself; its height follows the visible screen
   (app.js may set --vvh from visualViewport.height while the keyboard is open). */
.task-dialog {
  width: calc(100% - 2 * var(--gap) - env(safe-area-inset-left) - env(safe-area-inset-right));
  max-width: 528px;
  max-height: calc(var(--vvh, 100dvh) - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  margin: calc(env(safe-area-inset-top) + 12px) auto auto;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.task-dialog::backdrop {
  background: var(--backdrop);
}

.task-form {
  padding: 18px var(--gap) var(--gap);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.form-heading {
  font-size: 20px;
  font-weight: 700;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label,
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.counter {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* 16px+ so iOS does not zoom in on focus */
.field input,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font-size: 17px;
  line-height: 1.35;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  -webkit-appearance: none;
  appearance: none;
}

.field textarea {
  min-height: 84px;
  resize: vertical;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted);
}

/* Area chips in the form wrap onto more lines instead of scrolling */
.chips.chips-wrap {
  flex-wrap: wrap;
  overflow-x: visible;
  margin-left: 0;
  margin-right: 0;
  padding: 0;
}

.task-form .chips button {
  padding: 0 14px;
}

.form-error {
  padding: 12px 14px;
  background: var(--high-soft);
  color: var(--high-ink);
  border-radius: var(--radius-sm);
  font-size: 15px;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.form-actions button {
  min-height: var(--tap);
  padding: 0 16px;
  font-size: 16px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 0;
}

.form-delete {
  margin-right: auto;
  background: none;
  color: var(--danger);
  padding-left: 4px;
}

.form-cancel {
  background: var(--surface-2);
  color: var(--text);
}

.form-save {
  background: var(--accent);
  color: var(--accent-text);
  min-width: 88px;
}

.form-save:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Bigger screens: a bit more breathing room */
@media (min-width: 600px) {
  .app {
    padding-top: calc(env(safe-area-inset-top) + 40px);
    gap: 22px;
  }

  .title {
    font-size: 32px;
  }
}
