/* ===== Themes ===== */
:root {
  --bg: #1e1f21;
  --surface: #252628;
  --card: #2e2f31;
  --card-hover: #353638;
  --border: #3a3b3d;
  --text: #f1f0ee;
  --text-dim: #9ca0a4;
  --accent: #4573d2;
  --danger: #d64f4f;
  --drop-indicator: #4573d2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

body.light {
  --bg: #f4f3f1;
  --surface: #ffffff;
  --card: #ffffff;
  --card-hover: #f7f7f6;
  --border: #dedcd8;
  --text: #1f1e1c;
  --text-dim: #6f6d68;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Top bar ===== */
.topbar { padding: 12px 20px 0; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.topbar-row { display: flex; align-items: center; gap: 10px; }

.project-badge {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #e05c78, #c94f6d);
  color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}

.project-name { font-size: 18px; font-weight: 600; margin: 0; flex: 1; }

.theme-toggle {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 6px; width: 32px; height: 32px; font-size: 16px; cursor: pointer;
}
.theme-toggle:hover { color: var(--text); }

.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tab {
  background: none; border: none; color: var(--text-dim); font-size: 14px;
  padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); font-weight: 600; }

/* ===== Main view container ===== */
#view { flex: 1; overflow: auto; }
.board-loading { color: var(--text-dim); padding: 20px; }

/* ===== Board view ===== */
#view.view-board {
  display: flex; gap: 14px; padding: 18px 20px;
  overflow-x: auto; align-items: flex-start;
}

.column {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  width: 290px; min-width: 290px; max-height: 100%;
  display: flex; flex-direction: column;
}

.column-header { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; }

.column-name {
  font-size: 15px; font-weight: 600; border: 1px solid transparent; border-radius: 5px;
  padding: 2px 6px; margin-left: -6px; background: none; color: var(--text);
  width: 100%; min-width: 0;
}
.column-name:hover { border-color: var(--border); }
.column-name:focus { outline: none; border-color: var(--accent); background: var(--card); }

.column-count { color: var(--text-dim); font-size: 13px; flex-shrink: 0; }

.column-delete {
  background: none; border: none; color: var(--text-dim); font-size: 15px;
  cursor: pointer; border-radius: 5px; padding: 2px 6px; flex-shrink: 0;
  opacity: 0; transition: opacity 0.15s;
}
.column:hover .column-delete { opacity: 1; }
.column-delete:hover { color: var(--danger); background: var(--card); }

.tasks { padding: 4px 10px; overflow-y: auto; flex: 1; min-height: 30px; }

.task {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; margin-bottom: 8px; cursor: pointer;
  box-shadow: var(--shadow); position: relative;
}
.task:hover { background: var(--card-hover); }
.task.dragging { opacity: 0.4; }

.task-title { font-size: 14px; line-height: 1.4; word-break: break-word; padding-right: 20px; }

.task-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }

.chip {
  display: inline-block; font-size: 11px; font-weight: 600; color: #fff;
  border-radius: 10px; padding: 2px 8px; line-height: 1.5; white-space: nowrap;
}

.task-meta {
  margin-top: 8px; font-size: 12px; color: var(--text-dim);
  display: flex; gap: 10px; align-items: center;
}
.task-meta .overdue { color: var(--danger); font-weight: 600; }

.task-delete {
  position: absolute; top: 8px; right: 8px; background: none; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 14px; border-radius: 4px;
  padding: 1px 5px; opacity: 0; transition: opacity 0.15s;
}
.task:hover .task-delete { opacity: 1; }
.task-delete:hover { color: var(--danger); }

.drop-indicator { height: 3px; background: var(--drop-indicator); border-radius: 2px; margin: 2px 0 8px; }

.add-task-btn, .add-column-btn {
  background: none; border: none; color: var(--text-dim); font-size: 14px;
  text-align: left; padding: 10px 14px; cursor: pointer; border-radius: 0 0 10px 10px;
}
.add-task-btn:hover, .add-column-btn:hover { color: var(--text); background: var(--card); }

.add-column-btn {
  border: 1px dashed var(--border); border-radius: 10px;
  width: 290px; min-width: 290px; padding: 14px; flex-shrink: 0;
}

.add-task-form { padding: 0 10px 10px; }
.add-task-input {
  width: 100%; font-size: 14px; font-family: inherit;
  background: var(--card); color: var(--text);
  border: 1px solid var(--accent); border-radius: 8px; padding: 10px 12px; resize: none;
}
.add-task-input:focus { outline: none; }

/* ===== List view ===== */
#view.view-list { padding: 18px 20px; }

.list-section { margin-bottom: 22px; }
.list-section-header {
  font-size: 15px; font-weight: 600; margin-bottom: 6px;
  display: flex; gap: 8px; align-items: baseline;
}
.list-section-header .column-count { font-weight: 400; }

.list-row, .list-head {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 110px 110px 110px 80px;
  gap: 10px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
}
.list-head { font-size: 12px; color: var(--text-dim); border-bottom-width: 2px; }
.list-row { cursor: pointer; font-size: 14px; }
.list-row:hover { background: var(--card); }
.list-cell-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-cell-dim { font-size: 13px; color: var(--text-dim); }
.list-cell-dim.overdue { color: var(--danger); font-weight: 600; }

/* ===== Calendar view ===== */
#view.view-calendar { padding: 18px 20px; display: flex; flex-direction: column; }

.cal-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.cal-title { font-size: 17px; font-weight: 600; min-width: 170px; }
.cal-nav {
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 12px; font-size: 14px; cursor: pointer;
}
.cal-nav:hover { background: var(--card-hover); }
.cal-hint { font-size: 12px; color: var(--text-dim); margin-left: auto; }

.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex: 1;
  grid-auto-rows: auto;
}
.cal-dow {
  background: var(--surface); font-size: 12px; color: var(--text-dim);
  padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left;
}
.cal-day {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 6px; min-height: 96px; font-size: 12px;
}
.cal-day.other-month { opacity: 0.4; }
.cal-day-num { color: var(--text-dim); margin-bottom: 4px; }
.cal-day.today .cal-day-num {
  background: var(--accent); color: #fff; border-radius: 10px;
  display: inline-block; padding: 0 7px;
}
.cal-task {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 5px; color: var(--text); font-size: 12px;
  padding: 3px 6px; margin-bottom: 3px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-task:hover { background: var(--card-hover); }

/* ===== Timeline view ===== */
#view.view-timeline { padding: 18px 20px; }

.tl-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
.tl-inner { position: relative; min-width: max-content; }

.tl-header { display: flex; border-bottom: 1px solid var(--border); background: var(--surface); }
.tl-label-col { width: 220px; min-width: 220px; padding: 6px 10px; font-size: 12px; color: var(--text-dim); border-right: 1px solid var(--border); position: sticky; left: 0; background: var(--surface); z-index: 2; }
.tl-day { width: 34px; min-width: 34px; font-size: 10px; color: var(--text-dim); text-align: center; padding: 6px 0; border-right: 1px solid var(--border); }
.tl-day.weekend { background: var(--card); }
.tl-day.today { color: var(--accent); font-weight: 700; }

.tl-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); height: 38px; }
.tl-row:hover { background: var(--card); }
.tl-row .tl-label-col {
  font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; cursor: pointer; height: 100%; display: flex; align-items: center;
}
.tl-track { position: relative; height: 100%; flex: 1; }
.tl-bar {
  position: absolute; top: 8px; height: 20px; border-radius: 10px;
  background: var(--accent); opacity: 0.9; cursor: pointer; min-width: 12px;
}
.tl-bar:hover { opacity: 1; }
.tl-today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); opacity: 0.5; z-index: 1; }

.tl-empty { padding: 24px; color: var(--text-dim); font-size: 14px; }

/* ===== Overview view ===== */
#view.view-overview { padding: 18px 20px; }

.ov-cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 22px; }
.ov-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; min-width: 150px;
}
.ov-card-num { font-size: 26px; font-weight: 700; }
.ov-card-num.danger { color: var(--danger); }
.ov-card-label { font-size: 13px; color: var(--text-dim); margin-top: 2px; }

.ov-section { margin-bottom: 22px; max-width: 560px; }
.ov-section h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

.ov-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 7px; font-size: 13px; }
.ov-bar-label { width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ov-bar-track { flex: 1; background: var(--card); border-radius: 5px; height: 10px; overflow: hidden; }
.ov-bar-fill { height: 100%; background: var(--accent); border-radius: 5px; }
.ov-bar-count { width: 30px; text-align: right; color: var(--text-dim); }

.ov-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }

/* ===== Task modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40;
}

.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 680px; max-width: calc(100vw - 24px); max-height: calc(100vh - 40px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  z-index: 50; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modal-in 0.16s ease-out;
}

.modal[hidden] { display: none; }

@keyframes modal-in {
  from { transform: translate(-50%, -48%); opacity: 0; }
  to { transform: translate(-50%, -50%); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .modal { animation: none; }
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; gap: 10px;
}

.status-select {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-family: inherit; cursor: pointer;
}
.status-select:focus { outline: none; border-color: var(--accent); }

.modal-actions { display: flex; gap: 6px; }

.icon-btn {
  background: none; border: 1px solid transparent; color: var(--text-dim);
  font-size: 15px; cursor: pointer; border-radius: 6px; padding: 4px 8px;
}
.icon-btn:hover { color: var(--text); background: var(--card); }
.icon-btn.danger:hover { color: var(--danger); }

.modal-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

.modal-title {
  width: 100%; font-size: 21px; font-weight: 600; font-family: inherit;
  background: none; color: var(--text); border: 1px solid transparent; border-radius: 6px;
  padding: 6px 8px; margin: 0 0 10px -8px; resize: none; line-height: 1.35;
}
.modal-title:hover { border-color: var(--border); }
.modal-title:focus { outline: none; border-color: var(--accent); background: var(--card); }

.field-grid {
  display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px;
  align-items: center; margin-bottom: 16px;
}
.field-label { font-size: 13px; color: var(--text-dim); }
.field-control { display: flex; align-items: center; gap: 6px; }

.field-select {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-family: inherit;
  cursor: pointer; min-width: 140px;
}
.field-select:focus { outline: none; border-color: var(--accent); }

.field-value-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

.gear-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 14px; border-radius: 5px; padding: 3px 6px;
}
.gear-btn:hover { color: var(--text); background: var(--card); }

.date-input {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px; font-size: 13px; font-family: inherit;
  color-scheme: dark;
}
body.light .date-input { color-scheme: light; }
.date-input:focus { outline: none; border-color: var(--accent); }

.field-static { font-size: 13px; color: var(--text-dim); }

.modal-section-label {
  font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 18px 0 8px;
}

.modal-desc {
  width: 100%; min-height: 80px; font-size: 14px; font-family: inherit; line-height: 1.5;
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; resize: vertical;
}
.modal-desc:focus { outline: none; border-color: var(--accent); }

/* Attachments */
.attachment-list { display: flex; flex-direction: column; gap: 8px; }
.attachment {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.attachment-thumb {
  width: 44px; height: 44px; object-fit: cover; border-radius: 6px;
  background: var(--bg); flex-shrink: 0; cursor: zoom-in;
}
.attachment-fileicon {
  width: 44px; height: 44px; border-radius: 6px; background: var(--bg);
  display: grid; place-items: center; font-size: 18px; flex-shrink: 0;
}
.attachment-info { flex: 1; min-width: 0; }
.attachment-name {
  font-size: 13px; color: var(--text); text-decoration: none; display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attachment-name:hover { text-decoration: underline; }
.attachment-size { font-size: 12px; color: var(--text-dim); }

.upload-btn {
  background: none; border: 1px dashed var(--border); color: var(--text-dim);
  font-size: 13px; border-radius: 8px; padding: 10px; cursor: pointer; width: 100%; margin-top: 8px;
}
.upload-btn:hover { color: var(--text); border-color: var(--text-dim); }
.upload-btn:disabled { opacity: 0.5; cursor: wait; }

/* Comments */
.comment { padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.comment-author { font-size: 13px; font-weight: 600; }
.comment-date { font-size: 12px; color: var(--text-dim); flex: 1; }
.comment-delete { background: none; border: none; color: var(--text-dim); font-size: 12px; cursor: pointer; opacity: 0; }
.comment:hover .comment-delete { opacity: 1; }
.comment-delete:hover { color: var(--danger); }
.comment-body { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.comment-form { border-top: 1px solid var(--border); padding: 12px 20px; flex-shrink: 0; }
.comment-name-input {
  width: 100%; font-size: 13px; font-family: inherit; background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; margin-bottom: 8px;
}
.comment-name-input:focus { outline: none; border-color: var(--accent); }
.comment-input {
  width: 100%; font-size: 14px; font-family: inherit; background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; resize: none; min-height: 56px;
}
.comment-input:focus { outline: none; border-color: var(--accent); }
.comment-submit {
  margin-top: 8px; background: var(--accent); border: none; color: #fff;
  font-size: 14px; font-weight: 600; border-radius: 8px; padding: 8px 16px; cursor: pointer;
}
.comment-submit:hover { filter: brightness(1.1); }
.comment-submit:disabled { opacity: 0.5; cursor: wait; }

.empty-hint { font-size: 13px; color: var(--text-dim); }

/* ===== Options editor (on top of the modal) ===== */
.editor-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 70; }
.editor {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 420px; max-width: calc(100vw - 24px); max-height: 80vh;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  z-index: 71; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.editor-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px;
}
.editor-body { padding: 12px 16px; overflow-y: auto; }
.editor-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.editor-color {
  width: 34px; height: 30px; padding: 2px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--card); cursor: pointer;
}
.editor-label {
  flex: 1; font-size: 14px; font-family: inherit; background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
}
.editor-label:focus { outline: none; border-color: var(--accent); }
.editor-add {
  background: none; border: 1px dashed var(--border); color: var(--text-dim);
  font-size: 13px; border-radius: 8px; padding: 8px; cursor: pointer; width: 100%; margin-top: 4px;
}
.editor-add:hover { color: var(--text); border-color: var(--text-dim); }

/* Image lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85); z-index: 80;
  display: grid; place-items: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); z-index: 100;
}

/* ===== Scrollbars ===== */
::-webkit-scrollbar { height: 10px; width: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 720px) {
  .list-row, .list-head { grid-template-columns: 1fr 90px 90px; }
  .list-cell-scope, .list-cell-created { display: none; }
}
