/* Task Boards: light, readable, mobile first. Dark text on a light background. */
:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --text: #1c1c1e;
  --muted: #5d6066;
  --border: #e2e2dd;
  --border-strong: #c8c8c2;
  --accent: #2355d1;
  --accent-ink: #ffffff;
  --danger: #b8322a;
  --radius: 10px;
  --done-bg: #e3f3e7;
  --done-ink: #1b6a33;
  --progress-bg: #e6edfc;
  --progress-ink: #1d4bb3;
  --blocked-bg: #fbe7e5;
  --blocked-ink: #9e271f;
  --todo-bg: #eeeeeb;
  --todo-ink: #46474a;
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

h1 { font-size: 1.55rem; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 6px; }
p { margin: 0 0 8px; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 650; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--accent); }

.container { max-width: 1240px; margin: 0 auto; padding: 20px 16px 56px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

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

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 0.875rem; }
.btn:disabled { opacity: 0.45; cursor: default; }

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span:first-child { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.field.grow { flex: 1 1 260px; }
.field small { font-size: 0.8rem; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 7px 10px;
  min-height: 36px;
  max-width: 100%;
}
textarea { resize: vertical; }

.create-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-top: 12px; }
.create-form .field:first-child { flex: 1 1 220px; }
.create-form input { width: 100%; }

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

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.board-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.board-card:hover { border-color: var(--border-strong); }
.board-link { display: block; flex: 1; padding: 16px 16px 10px; color: inherit; text-decoration: none; }
.board-link:hover h2 { color: var(--accent); }
.board-link .muted { overflow-wrap: anywhere; }
.meta { font-size: 0.82rem; color: var(--muted); margin: 0; }
.card-actions { display: flex; gap: 8px; padding: 0 16px 14px; }

/* ---------- board page ---------- */

.board-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.board-title { min-width: 0; flex: 1 1 320px; }
.board-title h1, .board-title p { overflow-wrap: anywhere; }
.head-actions { display: flex; gap: 8px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.toolbar .search { flex: 1 1 220px; }
.toolbar .search input { width: 100%; }
.field-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.field-row select, .field-row input { min-width: 120px; }
.field-row.actions { margin-left: auto; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}

table { border-collapse: collapse; width: 100%; }

th, td { border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; padding: 0; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fcfcfa; }

th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
}
th + th, td + td { border-left: 1px solid var(--border); }

.th-inner { display: flex; align-items: center; gap: 6px; padding: 6px 8px; }
.col-name {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 650;
  color: var(--text);
  padding: 4px 4px;
  border-radius: 5px;
  cursor: pointer;
}
.col-name:hover { background: var(--border); }
.type-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
}
.sort-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 5px;
  margin-left: auto;
}
.sort-btn:hover { background: var(--border); }
.sort-btn.active { color: var(--accent); font-weight: 700; }

.cell input[type="text"],
.cell input[type="number"],
.cell input[type="date"],
.cell select {
  width: 100%;
  min-width: 150px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 7px 9px;
}
.cell.type-text input { min-width: 220px; }
.cell input:hover, .cell select:hover { border-color: var(--border); }
.cell input:focus, .cell select:focus { border-color: var(--accent); background: var(--surface); outline: none; }
.cell.type-checkbox { text-align: center; width: 1%; }
.cell input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; margin: 9px 14px; accent-color: var(--accent); cursor: pointer; }
.cell .invalid { color: var(--danger); }

select.status { font-weight: 600; }
.tone-done { background: var(--done-bg) !important; color: var(--done-ink); }
.tone-progress { background: var(--progress-bg) !important; color: var(--progress-ink); }
.tone-blocked { background: var(--blocked-bg) !important; color: var(--blocked-ink); }
.tone-todo { background: var(--todo-bg) !important; color: var(--todo-ink); }

.saving { opacity: 0.55; }
.saved { box-shadow: inset 0 0 0 2px #93cfa3; }

.actions-col { width: 1%; white-space: nowrap; padding: 0 6px; text-align: right; }
td.empty { padding: 22px 16px; text-align: center; }

/* ---------- dialog and toast ---------- */

dialog.dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(20, 20, 30, 0.18);
}
dialog.dialog::backdrop { background: rgba(28, 28, 30, 0.35); }
.dialog-form { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.dialog-form input, .dialog-form select, .dialog-form textarea { width: 100%; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog-actions .btn.danger { margin-right: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 9px;
  background: #1c1c1e;
  color: #ffffff;
  font-size: 0.92rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.error { background: var(--danger); }

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

@media (max-width: 720px) {
  .container { padding-top: 14px; }
  h1 { font-size: 1.3rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .field-row { width: 100%; }
  .field-row .field { flex: 1 1 140px; }
  .field-row select, .field-row input { width: 100%; min-width: 0; }
  .field-row.actions { margin-left: 0; }
  .field-row.actions .btn { flex: 1; }
  .create-form .btn { width: 100%; }
}
