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

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-tertiary: #ebebed;
  --text-primary: #1a1a1a;
  --text-secondary: #555558;
  --text-tertiary: #8e8e93;
  --border: rgba(0,0,0,0.10);
  --border-strong: rgba(0,0,0,0.18);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --col-width: 280px;
  --sidebar-width: 220px;
  --red: #e53935;
  --amber: #f59e0b;
  --blue: #2563eb;
  --green: #16a34a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --bg-tertiary: #3a3a3c;
    --text-primary: #f2f2f7;
    --text-secondary: #aeaeb2;
    --text-tertiary: #636366;
    --border: rgba(255,255,255,0.10);
    --border-strong: rgba(255,255,255,0.18);
  }
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg-secondary); color: var(--text-primary); font-size: 14px; }

#app { height: 100%; }

/* ── Layout ── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-primary);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease;
}
.sidebar-header { padding: 16px 14px 8px; font-size: 11px; font-weight: 600; color: var(--text-tertiary); letter-spacing: .06em; text-transform: uppercase; }
.sidebar-list { flex: 1; overflow-y: auto; padding: 0 6px; }
.sidebar-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-md);
  cursor: pointer; margin-bottom: 2px;
  transition: background 0.15s;
}
.sidebar-item:hover { background: var(--bg-secondary); }
.sidebar-item.active { background: var(--bg-tertiary); }
.sidebar-color { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.sidebar-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-badges { display: flex; gap: 3px; flex-shrink: 0; }
.badge { font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 20px; line-height: 1.5; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: var(--bg-tertiary); color: var(--text-secondary); }
.sidebar-footer { padding: 12px 14px; border-top: 0.5px solid var(--border); }
.user-info { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: #dbeafe; color: #1d4ed8; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.user-name { font-size: 13px; color: var(--text-secondary); }
.logout-btn { margin-top: 8px; width: 100%; padding: 6px; font-size: 12px; color: var(--text-tertiary); background: none; border: 0.5px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; }
.logout-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--border);
  background: var(--bg-primary);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-sub { font-size: 12px; color: var(--text-tertiary); }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.year-switcher { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.year-btn { background: none; border: 0.5px solid var(--border); border-radius: var(--radius-sm); padding: 3px 8px; cursor: pointer; color: var(--text-secondary); font-size: 12px; }
.year-btn:hover { background: var(--bg-secondary); }
.year-current { font-weight: 600; min-width: 36px; text-align: center; }
.toggle-events-btn {
  padding: 5px 12px; font-size: 12px; border-radius: var(--radius-sm);
  border: 0.5px solid var(--border); background: none; cursor: pointer;
  color: var(--text-secondary); transition: all 0.15s;
}
.toggle-events-btn.active { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.menu-btn { display: none; background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-primary); font-size: 20px; }

/* ── Board ── */
.board { display: flex; gap: 10px; padding: 12px; flex: 1; overflow-x: auto; align-items: flex-start; }

/* ── Column ── */
.column {
  flex: 0 0 var(--col-width);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  display: flex; flex-direction: column;
  max-height: calc(100vh - 100px);
}
.column-header {
  padding: 10px 12px 8px;
  border-bottom: 0.5px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.column-title { font-size: 13px; font-weight: 600; }
.column-count { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 20px; }
.cnt-wip { background: #fef3c7; color: #b45309; }
.cnt-open { background: #dbeafe; color: #1d4ed8; }
.cnt-done { background: #dcfce7; color: #15803d; }
.column-body { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; flex: 1; }

/* ── Month Group ── */
.month-group { margin-bottom: 6px; }
.month-label {
  font-size: 11px; font-weight: 600; color: var(--text-tertiary);
  padding: 4px 4px 6px; display: flex; align-items: center; gap: 6px;
}
.month-label::after { content: ''; flex: 1; height: 0.5px; background: var(--border); }
.month-label.current { color: var(--blue); }
.month-label.overdue { color: var(--red); }
.month-label.current::after { background: var(--blue); opacity: 0.3; }

/* ── Card ── */
.card {
  background: var(--bg-primary);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 10px;
  margin-bottom: 5px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  border-left-width: 3px;
  position: relative;
}
.card:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.card.dragging { opacity: 0.4; }
.card.drag-over { box-shadow: 0 0 0 2px var(--blue); }
.card-title { font-size: 13px; line-height: 1.4; color: var(--text-primary); word-break: break-word; }
.card.done .card-title { text-decoration: line-through; color: var(--text-tertiary); }
.card-meta { display: flex; align-items: center; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.card-date { font-size: 11px; color: var(--text-tertiary); }
.card-date.overdue { color: var(--red); font-weight: 600; }
.card-date.today { color: var(--amber); font-weight: 600; }
.card-date.thisweek { color: var(--blue); }
.prio-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.prio-1 { background: var(--red); }
.prio-2 { background: var(--red); }
.prio-3 { background: var(--red); }
.prio-4 { background: var(--amber); }
.prio-5 { background: var(--amber); }
.prio-6 { background: var(--blue); }
.prio-7 { background: var(--blue); }
.prio-8 { background: var(--text-tertiary); }
.prio-9 { background: var(--text-tertiary); }
.subtask-count { font-size: 11px; color: var(--text-tertiary); }
.progress-bar { height: 3px; background: var(--bg-tertiary); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 2px; transition: width 0.3s; }

/* Event Card */
.card.event-card {
  border-left-style: dashed;
  opacity: 0.75;
  cursor: default;
}
.card.event-card:hover { opacity: 0.9; }
.event-icon { font-size: 11px; color: var(--text-tertiary); }

/* Drop Zone */
.drop-zone {
  min-height: 40px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 5px;
  transition: all 0.15s;
}
.drop-zone.active { border-color: var(--blue); background: rgba(37,99,235,0.05); }

/* ── Detail Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
.modal-header {
  padding: 14px 16px 10px;
  border-bottom: 0.5px solid var(--border);
  display: flex; align-items: flex-start; gap: 8px;
  flex-shrink: 0;
}
.modal-title-input {
  flex: 1; font-size: 15px; font-weight: 600;
  border: none; background: none; color: var(--text-primary);
  outline: none; resize: none; line-height: 1.4;
}
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-tertiary); padding: 0 4px; line-height: 1; }
.modal-body { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 10px 16px; border-top: 0.5px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-shrink: 0; }

.field-label { font-size: 11px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-group { display: flex; flex-direction: column; flex: 1; min-width: 120px; }

input[type=text], input[type=date], input[type=datetime-local], input[type=number], select, textarea {
  background: var(--bg-secondary);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

.progress-input-row { display: flex; align-items: center; gap: 8px; }
.progress-input-row input[type=range] { flex: 1; }
.progress-val { font-size: 13px; font-weight: 600; min-width: 36px; text-align: right; }

/* Subtasks */
.subtask-list { display: flex; flex-direction: column; gap: 5px; }
.subtask-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--bg-secondary); border-radius: var(--radius-sm); }
.subtask-check { width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.subtask-title { flex: 1; font-size: 13px; color: var(--text-primary); }
.subtask-title.done { text-decoration: line-through; color: var(--text-tertiary); }
.subtask-del { background: none; border: none; cursor: pointer; color: var(--text-tertiary); font-size: 16px; line-height: 1; padding: 0 2px; }
.subtask-del:hover { color: var(--red); }
.add-subtask-row { display: flex; gap: 6px; margin-top: 4px; }
.add-subtask-row input { flex: 1; }
.add-btn { padding: 6px 12px; font-size: 12px; background: var(--blue); color: white; border: none; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; }
.add-btn:hover { opacity: 0.85; }

/* Buttons */
.btn { padding: 7px 16px; font-size: 13px; border-radius: var(--radius-sm); cursor: pointer; border: 0.5px solid var(--border); background: var(--bg-secondary); color: var(--text-primary); transition: all 0.15s; }
.btn:hover { background: var(--bg-tertiary); }
.btn-primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn-primary:hover { opacity: 0.85; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: #fee2e2; }

/* Share */
.share-row { display: flex; gap: 6px; }
.share-row input { flex: 1; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-secondary); padding: 16px; }
.login-card { background: var(--bg-primary); border-radius: var(--radius-lg); border: 0.5px solid var(--border); padding: 28px 28px 24px; width: 100%; max-width: 340px; box-shadow: var(--shadow-md); }
.login-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-tertiary); margin-bottom: 20px; }
.login-field { margin-bottom: 12px; }
.login-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; display: block; }
.login-btn { width: 100%; margin-top: 8px; padding: 9px; font-size: 14px; background: var(--blue); color: white; border: none; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.login-btn:hover { opacity: 0.85; }
.login-error { margin-top: 10px; font-size: 12px; color: var(--red); text-align: center; }
.login-hint { margin-top: 12px; font-size: 11px; color: var(--text-tertiary); text-align: center; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; height: 200px; color: var(--text-tertiary); font-size: 13px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin 0.8s linear infinite; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
  .menu-btn { display: block; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 49; }
  .column { flex: 0 0 calc(100vw - 40px); }
  .board { padding: 8px; gap: 8px; }
  .topbar { padding: 8px 12px; }
  .modal { max-height: 95vh; }
}
