:root {
  --board-bg: #eee3b8;
  --paper-bg: #eee3b8;
  --ink: #3a3226;
  --ink-soft: #6b5f4a;
  --accent: #d69e2e;
  --danger: #c0392b;
  --shadow: rgba(0, 0, 0, 0.18);

  --note-yellow: #fff3a3;
  --note-yellow-edge: #f2e37e;
  --note-pink: #ffd3e0;
  --note-pink-edge: #f5b6c8;
  --note-blue: #cdeaff;
  --note-blue-edge: #aed9f5;
  --note-green: #d9f5c4;
  --note-green-edge: #bde8a0;
  --note-orange: #ffdcb0;
  --note-orange-edge: #f7c187;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Segoe Print', Tahoma, sans-serif;
  color: var(--ink);
}

body {
  display: flex;
  flex-direction: column;
  background-color: var(--board-bg);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.35);
  border-bottom: 2px solid rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(2px);
  flex: 0 0 auto;
  z-index: 10;
}

.app-title {
  font-size: 20px;
  margin: 0;
  font-weight: 700;
  color: var(--ink);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.new-project-slot:not(:empty) {
  min-width: 220px;
}

.board {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
}

.board > * {
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

.board::-webkit-scrollbar {
  width: 12px;
}
.board::-webkit-scrollbar-track {
  background: transparent;
}
.board::-webkit-scrollbar-thumb {
  background-color: var(--note-yellow-edge);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
.board::-webkit-scrollbar-thumb:hover {
  background-color: var(--accent);
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  font-size: 15px;
  margin-top: 60px;
}

.projects-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.project {
  background: var(--project-color, var(--note-yellow));
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  box-shadow: 3px 4px 10px var(--shadow);
  padding: 12px 14px 14px;
}

.project-header, .task-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.project-header .title-text {
  font-size: 17px;
  font-weight: 700;
}

.project-stats {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.mini-stat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: var(--ink-soft);
}
.mini-stat b { color: var(--ink); font-weight: 700; }
.mini-stat-urgent b { color: var(--danger); }

.attachment-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: var(--ink-soft);
  cursor: pointer;
  flex: 0 0 auto;
}
.attachment-badge:hover { background: #fff; border-color: var(--accent); }
.attachment-badge b { color: var(--ink); font-weight: 700; }

.attachment-empty {
  font-size: 13px;
  color: var(--ink-soft);
  padding: 4px 2px;
}

.attachment-filename {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-size {
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.project-color-input {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  overflow: hidden;
}
.project-color-input::-webkit-color-swatch-wrapper { padding: 0; }
.project-color-input::-webkit-color-swatch { border: none; border-radius: 50%; }

.board-bg-input {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  overflow: hidden;
}
.board-bg-input::-webkit-color-swatch-wrapper { padding: 0; }
.board-bg-input::-webkit-color-swatch { border: none; border-radius: 50%; }

.task-group-header .title-text {
  font-size: 14px;
  font-weight: 600;
}

.collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--ink-soft);
  padding: 2px 4px;
  transition: transform 0.15s ease;
}
.collapse-btn.collapsed { transform: rotate(-90deg); }

.title-text {
  flex: 1;
  outline: none;
  border-radius: 3px;
  padding: 2px 4px;
  cursor: text;
}
.title-text:hover { background: rgba(255, 255, 255, 0.4); }
.title-text[contenteditable="true"] {
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 1px var(--accent);
}

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

.icon-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.icon-btn:hover { background: #fff; }
.icon-btn.danger { color: var(--danger); }

.task-groups-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0 4px 22px;
}

.task-group {
  background: rgba(255, 255, 255, 0.35);
  border: 1px dashed rgba(0, 0, 0, 0.15);
  border-radius: 5px;
  padding: 8px 10px 10px;
}

.tasks-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0 2px 20px;
}

.task-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 4px;
  padding: 5px 8px;
}
.task-row.status-completed .task-title { text-decoration: line-through; color: var(--ink-soft); }
.task-row.status-cancelled .task-title { text-decoration: line-through; color: #b0a89a; font-style: italic; }

.drag-handle {
  cursor: grab;
  color: var(--ink-soft);
  font-size: 12px;
}

.task-title {
  flex: 1;
  min-width: 80px;
  font-size: 13px;
}

.due-date {
  font-size: 12px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 2px 4px;
  background: #fffef8;
  width: 132px;
}

.priority-select {
  font-size: 12px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 3px;
  padding: 2px 4px;
  background: #fffef8;
}

.status-icons {
  display: flex;
  gap: 3px;
}

.status-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  opacity: 0.35;
  display: flex;
  align-items: center;
  justify-content: center;
}
.status-btn.active { opacity: 1; }
.status-progress.active { background: #fff2c2; border-color: #d69e2e; color: #a06e0f; }
.status-complete.active { background: #d9f5c4; border-color: #4c9a2a; color: #2f6b16; }
.status-cancel.active { background: #ffd3d3; border-color: #c0392b; color: #8f271b; }

.inline-add-slot { margin-top: 6px; }

.inline-add {
  display: flex;
  gap: 6px;
  align-items: center;
}

.inline-add-input {
  flex: 1;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  background: #fffef8;
}

.btn {
  border: none;
  border-radius: 4px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(0, 0, 0, 0.15);
}
.btn:hover { background: #faf5e0; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #c48a25; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; }

#btn-refresh.spinning {
  display: inline-block;
  animation: btn-refresh-spin 0.7s linear infinite;
}
@keyframes btn-refresh-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.dragging { opacity: 0.4; }
[draggable="true"] { cursor: grab; }
.title-text[draggable="true"]:active { cursor: grabbing; }

/* ---------- User badge ---------- */

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 10px;
  border-left: 1px solid rgba(0, 0, 0, 0.15);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  background: #fff;
  object-fit: cover;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Stats bar ---------- */

.stats-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 12px 24px;
  flex: 0 0 auto;
}

.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  padding: 8px 16px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(0, 0, 0, 0.12);
  min-width: 160px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-urgent .stat-value { color: var(--danger); }
.stat-pending .stat-value { color: var(--accent); }

/* ---------- Overlays (login screen, share dialog) ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 50, 38, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.login-card, .share-card {
  background: var(--note-yellow);
  border: 1px solid var(--note-yellow-edge);
  border-radius: 8px;
  box-shadow: 4px 6px 18px var(--shadow);
  padding: 28px 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}

.login-card h2 { margin: 0 0 8px; }
.login-card p { color: var(--ink-soft); font-size: 13px; margin: 0 0 18px; }

.btn-login {
  font-size: 14px;
  padding: 10px 20px;
  display: inline-block;
  text-decoration: none;
}

.login-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--danger);
  margin: 12px 0 0;
}

.share-card {
  text-align: left;
  max-width: 440px;
}

.share-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.share-card-header h3 {
  margin: 0;
  font-size: 15px;
  word-break: break-word;
}

.share-form {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.share-form input[type="email"] {
  flex: 1;
  font-size: 13px;
  padding: 5px 8px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  background: #fffef8;
}
.share-form select {
  font-size: 12px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 3px;
  background: #fffef8;
}

.share-error {
  color: var(--danger);
  font-size: 12px;
  margin: -4px 0 10px;
}

.share-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
}
.share-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.share-pending { font-size: 11px; color: var(--ink-soft); font-style: italic; }
.share-row-permission { font-size: 12px; }

/* ---------- Permission badge / view-only state ---------- */

.permission-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: var(--ink-soft);
  white-space: nowrap;
}

.permission-badge-clickable {
  cursor: pointer;
}
.permission-badge-clickable:hover {
  background: #fff;
  color: var(--ink);
  border-color: var(--accent);
}

.project.view-only .row-actions [data-role="add-group"],
.task-group.view-only .row-actions [data-role="add-task"],
.project.view-only .row-actions [data-role="delete"],
.task-group.view-only .row-actions [data-role="delete"],
.task-row.view-only .row-actions [data-role="delete"] {
  display: none;
}
.task-row.view-only [data-role="delete"] { display: none; }
.task-row.view-only .drag-handle { visibility: hidden; }
.project.view-only .title-text,
.task-group.view-only .title-text,
.task-row.view-only .title-text {
  cursor: default;
}
