:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --ink: #1b2030;
  --muted: #646b7e;
  --line: #e1e4ec;
  --brand: #1f2a44;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --us: #1f6f43;
  --us-bg: #e5f4ea;
  --other: #c00000;
  --other-bg: #fdeaea;
  --question: #5b3cc4;
  --question-bg: #efeafe;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  color-scheme: light;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

[hidden] {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

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

.small {
  font-size: 0.85em;
}

.error {
  color: var(--other);
  background: var(--other-bg);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0;
}

/* ---------- controls ---------- */

input,
select,
textarea {
  font: inherit;
  color: inherit;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
}

textarea {
  resize: vertical;
}

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

label {
  display: grid;
  gap: 4px;
  font-weight: 600;
  font-size: 0.9rem;
}

label.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  white-space: nowrap;
}

label.check input {
  width: auto;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: #c4c9d6;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: #d14f0a;
  border-color: #d14f0a;
}

.btn-danger {
  background: var(--other);
  border-color: var(--other);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: rgb(0 0 0 / 5%);
  border-color: transparent;
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.85rem;
}

/* ---------- login ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(380px, 100%);
  padding: 28px;
  display: grid;
  gap: 14px;
}

/* ---------- layout ---------- */

#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.topbar h1 {
  font-size: 1.6rem;
}

.topbar-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  font: inherit;
  font-weight: 600;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 14px;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: -1px;
}

.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.count {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink);
  font-size: 0.8rem;
  text-align: center;
  margin-left: 4px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  margin-bottom: 20px;
}

.toolbar select {
  width: auto;
}

/* ---------- list ---------- */

.list {
  display: grid;
  gap: 24px;
}

.group {
  display: grid;
  gap: 10px;
}

.group-title {
  font-size: 1rem;
  color: var(--brand);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
}

.task {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 16px;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--us);
}

.task-external {
  border-left-color: var(--other);
}

.task-external .task-title {
  color: var(--other);
}

.task-done,
.task-deleted {
  border-left-color: var(--line);
}

.task-done .task-title,
.task-deleted .task-title {
  color: var(--muted);
}

.task-deleted .task-title {
  text-decoration: line-through;
}

.task-body {
  display: grid;
  gap: 6px;
  align-content: start;
  min-width: 0;
}

.task-title {
  font-size: 1rem;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.details {
  margin: 0;
  color: #3a4156;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.details.expanded {
  display: block;
}

.meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chip {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink);
  border: none;
}

.chip-us {
  background: var(--us-bg);
  color: var(--us);
}

.chip-other {
  background: var(--other-bg);
  color: var(--other);
}

.chip-question {
  background: var(--question-bg);
  color: var(--question);
}

.chip-overdue {
  background: var(--other);
  color: #fff;
}

.chip-muted {
  background: #eef0f4;
  color: var(--muted);
}

.chip-button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 12px;
  cursor: pointer;
}

.status-line {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.status-line .note {
  display: block;
  margin-top: 2px;
  white-space: pre-wrap;
}

.task-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
}

/* ---------- dialogs ---------- */

.dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgb(16 24 40 / 25%);
  padding: 0;
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}

.dialog::backdrop {
  background: rgb(16 24 40 / 45%);
}

.dialog form {
  display: grid;
  gap: 14px;
  padding: 24px;
}

.dialog h2 {
  font-size: 1.2rem;
}

.dialog-subject {
  font-weight: 600;
  color: var(--ink);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border: none;
  padding: 0;
  margin: 0;
}

.history {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.history h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.history ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.history li {
  display: grid;
  gap: 1px;
  font-size: 0.88rem;
}

.owner-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.owner-list li,
.owner-add {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
}

.owner-add {
  grid-template-columns: 1fr auto auto;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--brand);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 10;
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  #app {
    padding: 16px 12px 48px;
  }

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

  .toolbar #search {
    grid-column: 1 / -1;
  }

  .toolbar select {
    width: 100%;
  }

  .toolbar #new-button {
    grid-column: 1 / -1;
  }

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

  .task-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .grid-2,
  .owner-list li,
  .owner-add {
    grid-template-columns: 1fr;
  }

  .tab {
    padding: 10px 8px;
  }
}
