:root {
  --bg: #f3f5ef;
  --card: #fffdf8;
  --ink: #1f2923;
  --muted: #55635a;
  --accent: #13795b;
  --accent-2: #dcefe8;
  --danger: #8f2d2d;
  --line: #c8d2cb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #e6efe8 0%, transparent 38%),
    radial-gradient(circle at 90% 5%, #dbe8df 0%, transparent 30%),
    var(--bg);
}

.app-shell {
  max-width: 760px;
  margin: 2rem auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 12px 36px rgba(21, 34, 28, 0.08);
}

.shared-space-shell {
  max-width: 1120px;
}

.app-header h1 {
  margin: 0;
}

.app-header p {
  margin-top: 0.35rem;
  color: var(--muted);
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  padding: 0 0.9rem;
}

.header-actions {
  display: grid;
  gap: 0.45rem;
  justify-items: end;
  margin-left: auto;
}

.auth-form {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: end;
}

.auth-form input {
  height: 2rem;
  min-width: 120px;
}

.auth-form button {
  height: 2rem;
  font-size: 0.8rem;
}

.auth-status {
  margin: 0;
  text-align: right;
  max-width: 420px;
}

.auth-shell {
  max-width: 860px;
}

.auth-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: stretch;
}

.logo-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 20%, #cfe8dd 0%, transparent 55%),
    radial-gradient(circle at 80% 15%, #b9dcca 0%, transparent 45%),
    #eef7f2;
  padding: 1rem;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.6rem;
}

.logo-mark {
  display: flex;
  align-items: center;
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.logo-letter {
  display: inline-flex;
  width: 2.8rem;
  height: 2.8rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.6rem;
  border: 1px solid #96bda9;
  background: #ffffffcf;
}

.logo-letter-d {
  margin-left: -0.8rem;
}

.logo-caption {
  margin: 0;
  color: var(--muted);
}

.auth-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  background: #fcfdfb;
  display: grid;
  align-content: start;
}

.standalone-auth-form {
  display: grid;
  gap: 0.7rem;
  justify-items: stretch;
  justify-content: start;
  align-content: start;
}

.standalone-auth-form .field {
  width: 100%;
}

.standalone-auth-form input {
  width: 100%;
  min-width: 100%;
}

.auth-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.auth-actions button {
  min-width: 8.5rem;
}

.auth-panel .app-header,
.standalone-auth-form,
.auth-status {
  justify-self: start;
  width: 100%;
}

.auth-status {
  text-align: left;
  max-width: none;
}

.profile-menu {
  position: relative;
}

.profile-bubble {
  width: 2.5rem;
  min-width: 2.5rem;
  border-radius: 999px;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  border-color: #0f6b50;
  background: linear-gradient(160deg, #1a8a67, #0f6b50);
  color: #fff;
}

.profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  width: 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(21, 34, 28, 0.15);
  padding: 0.5rem;
  display: none;
  gap: 0.4rem;
  z-index: 20;
}

.profile-menu.is-open .profile-dropdown {
  display: grid;
}

.profile-dropdown .link-button,
.profile-dropdown button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

.profile-password-form {
  max-width: 540px;
}

.profile-password-form input {
  width: 100%;
}

.password-status {
  margin: 0.6rem 0 0;
  text-align: left;
  max-width: none;
}

@media (max-width: 760px) {
  .auth-layout {
    grid-template-columns: 1fr;
  }

  .logo-mark {
    font-size: 2.1rem;
  }
}

.composer form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  align-items: end;
}

.composer-task {
  grid-column: 1 / -1;
}

.composer form button[type="submit"] {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 0.4rem;
}

.field span {
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 0.75rem;
}

button {
  height: 2.5rem;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  padding: 0 0.9rem;
  cursor: pointer;
}

.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.toolbar {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.toolbar-controls {
  display: flex;
  gap: 0.75rem;
}

.compact-picker {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 2.5rem;
  padding: 0.25rem 1.85rem 0.25rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.compact-picker::after {
  content: "v";
  position: absolute;
  right: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.7rem;
  pointer-events: none;
}

.compact-picker span {
  font-size: 0.78rem;
  white-space: nowrap;
  color: var(--ink);
}

.compact-picker select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.compact-picker:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(19, 121, 91, 0.12);
}

.toolbar p {
  margin: 0;
  color: var(--muted);
}

.category-manager {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fcfdfb;
}

.nested-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.65rem 0.75rem;
  margin-top: 0.6rem;
}

.nested-card p {
  margin: 0;
}

.nested-card .category-actions {
  margin-top: 0.55rem;
}

#shared-space-current-name {
  font-size: 1rem;
  font-weight: 700;
}

#shared-space-access-list,
#shared-space-members-list,
#shared-space-incoming-list,
#shared-space-invite-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

#shared-space-access-list li,
#shared-space-members-list li,
#shared-space-incoming-list li,
#shared-space-invite-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.55rem 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

#shared-space-access-list strong,
#shared-space-members-list strong,
#shared-space-incoming-list strong {
  display: block;
  margin-bottom: 0.15rem;
}

#shared-space-members-list .category-actions,
#shared-space-invite-list .category-actions,
#shared-space-incoming-list .category-actions {
  justify-content: flex-end;
  align-items: center;
}

#shared-space-members-list .category-actions button,
#shared-space-invite-list .category-actions button,
#shared-space-incoming-list .category-actions button {
  min-height: 2rem;
  height: auto;
  padding: 0.25rem 0.7rem;
  white-space: nowrap;
}

.settings-grid {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
  align-items: start;
}

.shared-space-layout {
  margin-top: 0.75rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  align-items: start;
}

.shared-space-hero {
  grid-column: 1 / -1;
}

#shared-space-current-card,
#shared-space-members-card,
#shared-space-invites-card {
  margin-top: 0;
}

.shared-space-destructive {
  justify-content: flex-start;
}

#shared-space-members-panel,
#shared-space-pending-panel {
  margin-top: 0.75rem;
}

#shared-space-current-card.is-empty,
#shared-space-invites-card.is-passive {
  background: #f8fbf9;
}

.capture-panel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #f8fbf9;
}

.capture-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.capture-form {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: 140px 1fr 1.8fr auto;
  gap: 0.6rem;
  align-items: end;
}

.capture-message textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 2.5rem;
  resize: vertical;
  font: inherit;
  padding: 0.6rem 0.75rem;
}

#capture-list {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.capture-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.55rem 0.65rem;
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
}

.capture-meta,
.capture-text {
  margin: 0;
}

.capture-meta {
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  gap: 0.45rem;
}

.capture-text {
  margin-top: 0.35rem;
}

.capture-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.capture-actions button {
  height: 2rem;
  font-size: 0.85rem;
}

.capture-triage {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr;
  gap: 0.45rem;
  width: 100%;
}

.capture-triage input,
.capture-triage select {
  height: 2rem;
  font-size: 0.85rem;
}

.category-manager.standalone {
  margin-top: 0.75rem;
  min-width: 0;
}

.category-manager h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

#category-form {
  display: flex;
  gap: 0.6rem;
  align-items: end;
  flex-wrap: wrap;
}

#category-form .field {
  flex: 1;
  min-width: 0;
}

#sender-form {
  display: flex;
  gap: 0.6rem;
  align-items: end;
  flex-wrap: wrap;
}

#sender-form .field {
  flex: 1;
  min-width: 0;
}

#shared-space-form,
#shared-space-invite-form {
  display: flex;
  gap: 0.6rem;
  align-items: end;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

#shared-space-form .field,
#shared-space-invite-form .field {
  flex: 1;
  min-width: 0;
}

#category-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

#category-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.45rem 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#category-list li .category-actions {
  width: 100%;
  justify-content: flex-end;
}

#sender-list {
  list-style: none;
  margin: 0.65rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

#sender-list li {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.45rem 0.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.sender-edit-form {
  width: 100%;
  display: flex;
  gap: 0.6rem;
  align-items: end;
}

.sender-edit-form .field {
  flex: 1;
}

.category-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.category-actions button {
  height: 1.8rem;
  font-size: 0.8rem;
}

#category-form button,
#sender-form button {
  flex-shrink: 0;
  white-space: nowrap;
}

#sender-list li,
#category-list li,
.category-manager,
.auth-panel {
  min-width: 0;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.list-panel {
  margin-top: 1rem;
}

#todo-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.6rem;
}

.todo-row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fff;
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
}

.todo-row.is-done {
  background: var(--accent-2);
}

.todo-row.is-editing {
  background: #f8fbf9;
}

.todo-title {
  margin: 0;
  font-weight: 600;
}

.todo-row.is-done .todo-title {
  text-decoration: line-through;
  color: var(--muted);
}

.todo-meta {
  margin: 0.45rem 0 0;
  display: flex;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.todo-sync-status {
  margin: 0.45rem 0 0;
  color: var(--danger);
  font-size: 0.88rem;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  background: #f9fbf8;
  text-transform: capitalize;
}

.todo-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.todo-actions button {
  height: 2rem;
  font-size: 0.85rem;
}

.todo-actions .danger {
  border-color: var(--danger);
  background: #fff;
  color: var(--danger);
}

.todo-actions .secondary {
  border-color: var(--line);
}

.todo-edit-form {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 170px 170px auto;
  gap: 0.6rem;
  align-items: end;
}

.empty-state {
  margin: 0.5rem 0 0;
  color: var(--muted);
}

@media (max-width: 720px) {
  .app-shell {
    margin: 1rem;
  }

  .header-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
  }

  .header-actions {
    justify-items: end;
    margin-left: 0;
  }

  .auth-form {
    justify-content: stretch;
  }

  .auth-form input,
  .auth-form button {
    width: 100%;
  }

  .auth-status {
    text-align: left;
  }

  .composer form {
    grid-template-columns: 1fr 1fr;
  }

  .composer form button[type="submit"] {
    grid-column: span 2;
  }

  .capture-form {
    grid-template-columns: 1fr;
  }

  .capture-row {
    flex-direction: column;
  }

  .capture-triage {
    grid-template-columns: 1fr;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #category-form {
    flex-direction: column;
    align-items: stretch;
  }

  #sender-form {
    flex-direction: column;
    align-items: stretch;
  }

  #shared-space-form,
  #shared-space-invite-form {
    flex-direction: column;
    align-items: stretch;
  }

  .sender-edit-form {
    flex-direction: column;
    align-items: stretch;
  }

  #category-list li {
    flex-wrap: wrap;
  }

  #sender-list li {
    flex-wrap: wrap;
  }

  #shared-space-access-list li,
  #shared-space-members-list li,
  #shared-space-incoming-list li,
  #shared-space-invite-list li {
    flex-wrap: wrap;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .shared-space-layout {
    grid-template-columns: 1fr;
  }

  .todo-row {
    flex-direction: column;
  }

  .todo-edit-form {
    grid-template-columns: 1fr;
  }
}
