/* deadline-ninja base styles. Theme via CSS variables:
   data-theme="auto" follows the OS, "light"/"dark" force a theme. */

:root {
  --bg: #ffffff;
  --fg: #1d2129;
  --muted: #5f6673;
  --border: #d9dde3;
  --accent: #d32f2f;
  --surface: #f5f6f8;
  --mark: #ffe082;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #14161a;
    --fg: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2d3138;
    --accent: #f44336;
    --surface: #1d2025;
    --mark: #6d5a14;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --fg: #e6e8eb;
  --muted: #9aa1ab;
  --border: #2d3138;
  --accent: #f44336;
  --surface: #1d2025;
  --mark: #6d5a14;
  color-scheme: dark;
}

/* A forced theme also sets the browser's own controls (scrollbars, inputs). */
:root[data-theme="light"] { color-scheme: light; }

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

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

.locale-switch { display: flex; gap: 0.5rem; align-items: center; }

/* Theme toggle: the button shows the theme it switches to. */
.theme-switch { margin: 0; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: 2.2rem; line-height: 1.2; }
.theme-toggle[value="dark"] .theme-icon-light,
.theme-toggle[value="light"] .theme-icon-dark { display: none; }

select, button {
  font: inherit;
  padding: 0.3rem 0.6rem;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

button { cursor: pointer; }

.container { flex: 1; width: 100%; max-width: 48rem; margin: 0 auto; padding: 2rem 1rem; }

.muted, .footer { color: var(--muted); }

.footer { padding: 1rem; text-align: center; font-size: 0.875rem; }

/* --- Navigation ---------------------------------------------------------- */

.nav { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-left: auto; }
.nav form { margin: 0; }

/* The notifications bell; the red dot shows while anything is unread. */
.bell { position: relative; display: inline-flex; padding: 0.15rem; color: var(--fg); border-radius: 6px; }
.bell:hover, .bell:focus-visible { color: var(--accent); }
.bell-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 0.6rem;
  height: 0.6rem;
  background: #e53935;
  border: 2px solid var(--bg);
  border-radius: 50%;
}
a { color: var(--accent); }

/* --- Cards, forms, buttons ----------------------------------------------- */

.card {
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.narrow { max-width: 26rem; margin: 0 auto; }
.card h1 { margin-top: 0; }

.form { display: flex; flex-direction: column; gap: 0.35rem; }
.form label { margin-top: 0.6rem; font-weight: 600; }
.form input, .form select { width: 100%; }
.form button { margin-top: 1rem; }

input {
  font: inherit;
  padding: 0.45rem 0.6rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input[aria-invalid="true"] { border-color: var(--accent); }

.button {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
}
.primary, .button.primary { color: #fff; background: var(--accent); border-color: var(--accent); }

.actions { display: flex; gap: 1rem; align-items: center; }
.actions button { margin-top: 1rem; }
.actions a { margin-top: 1rem; }

.field-error { margin: 0; color: var(--accent); font-size: 0.875rem; }

.alert { padding: 0.6rem 0.8rem; border-radius: 6px; border: 1px solid var(--border); }
.alert-error { border-color: var(--accent); }
.alert-success { border-color: #4caf50; }

/* --- Tables -------------------------------------------------------------- */

.heading-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.5rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; }

/* --- Task board ---------------------------------------------------------- */

.container.wide { max-width: 72rem; }

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

.board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 1.5rem;
  align-items: start;
}

.column-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.column-head h2 { margin: 0 0 0.75rem; font-size: 1.25rem; }
.empty { margin: 0.5rem 0; }

.tiles { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

/* Tiles keep their own light colors in both themes, so text on them is always dark. */
.tile {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.6rem 0.6rem 0.6rem 0.4rem;
  color: #111111;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  overflow: hidden;
}
.tile-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.tile > :not(.tile-bg) { position: relative; z-index: 1; }

.tile-handle {
  cursor: grab;
  user-select: none;
  touch-action: none;
  padding: 0 0.25rem;
  font-size: 1.1rem;
  line-height: 1.6;
  color: rgba(0, 0, 0, 0.55);
}
.tile-body { flex: 1; min-width: 0; }
.tile-title { font-weight: 600; overflow-wrap: anywhere; }
.tile-desc {
  margin: 0.2rem 0 0;
  font-size: 0.875rem;
  color: rgba(0, 0, 0, 0.7);
  white-space: pre-line;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-actions { display: flex; gap: 0.25rem; align-items: center; flex-shrink: 0; }
.tile-actions form { margin: 0; }
.tile .icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.35rem;
  color: #111111;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
}
.tile .icon:hover:not([disabled]) { background: rgba(255, 255, 255, 0.9); }
.tile .icon[disabled] { opacity: 0.35; cursor: default; }
.tile .icon:focus-visible, .tile-handle:focus-visible { outline: 2px solid #111111; outline-offset: 1px; }

/* Semi-transparent "+" in the top-right corner. */
.fab {
  position: fixed;
  top: 4.5rem;
  right: 1.25rem;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.25rem;
  height: 3.25rem;
  font-size: 2rem;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border-radius: 50%;
  text-decoration: none;
  opacity: 0.6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: opacity 0.15s;
}
.fab:hover, .fab:focus-visible { opacity: 1; }

.modal {
  width: min(32rem, calc(100% - 2rem));
  padding: 1.5rem;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal h2 { margin-top: 0; }

textarea {
  font: inherit;
  width: 100%;
  padding: 0.45rem 0.6rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
}
textarea[aria-invalid="true"] { border-color: var(--accent); }
.choice { margin: 0.6rem 0 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 1rem; }
.choice legend { padding: 0; margin-bottom: 0.35rem; font-weight: 600; }
.form label.inline { margin-top: 0; font-weight: 400; display: inline-flex; gap: 0.4rem; align-items: center; }
.form label.inline input { width: auto; }

/* Keep the fixed "+" off the column headers: a right gutter on wide
   screens, the bottom-right corner on phones. */
@media (min-width: 40.01rem) {
  .container.wide { padding-right: 5.5rem; }
}
@media (max-width: 40rem) {
  .fab { top: auto; bottom: 1.25rem; }
}

/* Trash */
.board-foot { margin-top: 1.5rem; text-align: right; }
.trash td { vertical-align: top; }
.trash-title { font-weight: 600; overflow-wrap: anywhere; }
.trash-desc {
  margin: 0.2rem 0 0;
  font-size: 0.875rem;
  white-space: pre-line;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.trash form { margin: 0; }

/* Completion checkbox (a button with role="checkbox": works without JS). */
.tile-check { margin: 0; }
.check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  margin-top: 0.15rem;
  padding: 0;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  flex-shrink: 0;
}
.tile .check { color: #111111; }
.check:hover::after, .check.checked::after { content: "\2713"; font-weight: 700; line-height: 1; }
.check:hover::after { opacity: 0.4; }
.check.checked { color: var(--fg); background: var(--surface); border-color: var(--muted); }
.check.checked:hover::after { opacity: 1; content: "\21B6"; }
.check:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

/* Author of a task the viewer did not write. */
.tile-author { display: block; font-size: 0.8rem; color: rgba(0, 0, 0, 0.65); }

/* Completed block and page */
.completed { margin-top: 2rem; }
.done-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.done-item { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.done-item form { margin: 0; }
.done-title { color: var(--fg); text-decoration: line-through; text-decoration-color: var(--muted); overflow-wrap: anywhere; }
.done-meta { font-size: 0.875rem; }
.done-add { margin: 1rem 0; }
.done-add summary { cursor: pointer; color: var(--accent); }
.done-add .form { max-width: 32rem; margin-top: 0.5rem; }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* Details page */
.details .heading-row { align-items: flex-start; }
.details-title { margin: 0; overflow-wrap: anywhere; }
.details-desc { white-space: pre-line; overflow-wrap: anywhere; }
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.badge-done { border-color: #4caf50; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; margin: 1rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.actions form { margin: 1rem 0 0; }

/* Colleagues */
.people { padding-left: 1.2rem; }
.readonly { max-width: 32rem; }

/* Settings: time zone, work hours, work days */
.hint { margin: 0.2rem 0 0; font-size: 0.875rem; }
.work-hours, .work-days { margin: 0.8rem 0 0; padding: 0.5rem 0.8rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; }
.work-hours legend, .work-days legend { padding: 0 0.3rem; font-weight: 600; }
.time-range { display: flex; flex-wrap: wrap; gap: 1rem; }
.time-range span { display: flex; flex-direction: column; }
.time-range label { margin-top: 0; font-weight: 400; }
.time-range input { width: auto; }
.work-days { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }

/* Timers */
.tile-timer { display: block; font-size: 0.8rem; color: rgba(0, 0, 0, 0.7); }
.timer-mark { font-weight: 600; color: #111111; }
.duration { white-space: nowrap; }
.tile[data-status="in_progress"] { box-shadow: inset 4px 0 0 #111111; }
.time-events ol { margin: 0.4rem 0 0; padding-left: 1.2rem; font-size: 0.9rem; }
.time-events summary { cursor: pointer; }
.worktime-prompt { margin: 0 0 1.25rem; border-color: var(--accent); background: var(--surface); }
.worktime-prompt h2 { margin: 0 0 0.3rem; font-size: 1.1rem; }
.worktime-prompt p { margin: 0.3rem 0; }
.worktime-prompt ul { margin: 0.2rem 0; padding-left: 1.2rem; }
.worktime-prompt .actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.worktime-prompt .actions form { margin: 0.5rem 0 0; }
.worktime-prompt .actions button { margin-top: 0; }
.worktime-prompt .prompt-tasks { list-style: none; padding-left: 0; }
.worktime-prompt .prompt-tasks li { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; margin: 0.35rem 0; }
.worktime-prompt .prompt-tasks form { margin: 0; }
.worktime-prompt .prompt-tasks button { margin-top: 0; padding: 0.25rem 0.75rem; }
/* Assignment details (M7b) */
.facts .assignees { margin: 0; padding-left: 1.1rem; }
.admin-completed { margin-top: 1.5rem; }
.admin-completed ol { padding-left: 1.2rem; }

/* Sharing and assignment */
.tile-status { display: block; font-size: 0.8rem; font-weight: 600; color: #111111; }
.tile[data-status="pending_acceptance"], .tile[data-status="declined"] { box-shadow: inset 4px 0 0 rgba(0, 0, 0, 0.35); }
.copy-forms { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin-top: 1.25rem; }
.copy-forms form { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin: 0; }
.copy-forms label { margin: 0; }
.copy-forms select, .copy-forms button { width: auto; margin-top: 0; }

/* Managers (M4b) */
.team-assign { margin-top: 1.25rem; }
.team-assign fieldset { margin: 0; padding: 0.5rem 0.8rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }
.team-assign legend { padding: 0 0.3rem; font-weight: 600; }
.team-assign .hint { flex-basis: 100%; }
.team-assign label { margin: 0; font-weight: 400; }
.team-assign input[type="checkbox"] { width: auto; margin: 0 0.3rem 0 0; }
.team-assign button { width: auto; }
.manager-form select, .manager-form button { width: auto; }

/* --- Notifications page -------------------------------------------------- */

.notifications { list-style: none; margin: 1rem 0; padding: 0; }
.notification {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.notification form { margin: 0; flex-shrink: 0; }
.notification-body { display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: baseline; min-width: 0; }
.notification-text { overflow-wrap: anywhere; }
.notification[data-read="false"] .notification-text { font-weight: 600; }
.notification[data-read="true"] .notification-text { color: var(--muted); }
.notification-new {
  padding: 0 0.4rem;
  font-size: 0.75rem;
  color: #fff;
  background: #e53935;
  border-radius: 999px;
}
.notification time { font-size: 0.875rem; }

/* --- Search (M6) --------------------------------------------------------- */

.search-form { margin: 0; }
.search-form input { width: 11rem; padding: 0.3rem 0.6rem; }
.search-page-form { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.search-page-form label { font-weight: 600; }
.search-row { display: flex; gap: 0.5rem; }
.search-row input { flex: 1; min-width: 0; }
.search-page-form .search-scope { display: flex; align-items: center; gap: 0.4rem; font-weight: normal; }
.result-group { margin-top: 1.5rem; }
.results { list-style: none; margin: 0; padding: 0; }
.result { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.result-title { font-weight: 600; overflow-wrap: anywhere; }
.result-meta { margin-left: 0.5rem; font-size: 0.875rem; }
.result-desc { margin: 0.2rem 0 0; font-size: 0.9rem; color: var(--muted); overflow-wrap: anywhere; }
mark { padding: 0 0.1em; color: inherit; background: var(--mark); border-radius: 3px; }
@media (max-width: 40rem) {
  .search-form { order: -1; flex-basis: 100%; }
  .search-form input { width: 100%; }
}

/* --- Drag and drop (M6) -------------------------------------------------- */

/* Where the tile will land. */
.tile-ghost { opacity: 0.35; outline: 2px dashed var(--fg); outline-offset: -2px; }
/* The tile while it is held, and the copy under the pointer. */
.tile-chosen { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.tile-drag { transform: rotate(1deg); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3); }
.tiles-dragging, .tiles-dragging .tile-handle { cursor: grabbing; }
.tile-handle:hover { color: #111111; }
.tile-handle[tabindex]:focus-visible { border-radius: 4px; }
.column[aria-busy="true"] .tiles { opacity: 0.85; }
/* Brief flash on the tile that just moved (arrows, keys or drag). */
.tile-moved { animation: tile-moved 0.9s ease-out; }
@keyframes tile-moved {
  from { box-shadow: 0 0 0 3px var(--fg); }
  to { box-shadow: 0 0 0 3px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .tile-moved { animation: none; }
  .tile-drag { transform: none; }
  .fab { transition: none; }
}
/* Reports */
.period-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0; }
.report-export { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0 1rem; }
.report-tasks td.text { min-width: 12rem; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table tfoot th, .report-table tfoot td { font-weight: 600; border-top: 2px solid var(--border); }
/* Team page: each report's year under their column */
.team-member { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.team-year h3 { margin: 0 0 0.25rem; font-size: 1rem; }
.team-year p { margin: 0.2rem 0; }
.team-done { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.team-done li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; }
/* Import */
.import-form { display: flex; flex-direction: column; gap: 0.5rem; }
.hint-list { padding-left: 1.2rem; }
.import-counts { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; }
.import-commit { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin: 1rem 0; }
.import-table td { vertical-align: top; }
.import-title { overflow-wrap: anywhere; }
.import-table p { margin: 0; }
.import-warning { color: var(--muted); }

/* M8b: a deleted user's tasks to reassign; the admin's account actions. */
.reassign-tasks { margin: 0; padding: 0.5rem 0.8rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; display: flex; flex-direction: column; gap: 0.4rem; }
.reassign-tasks input[type="checkbox"] { width: auto; margin: 0 0.3rem 0 0; }
.account-actions { margin-top: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.account-actions form { margin: 0; }
.danger { border-color: var(--accent); }
