:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1b1d23;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff4ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-bg: #14161f;
  --sidebar-text: #b7bac6;
  --sidebar-active-bg: #23273a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
svg.icon { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }

.hidden { display: none !important; }

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 16px 10px; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { color: #fff; font-weight: 700; font-size: 15px; padding: 6px 10px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar .nav-btn {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; border: none;
  background: none; color: var(--sidebar-text); font-size: 13.5px; cursor: pointer; text-align: left; width: 100%;
}
.sidebar .nav-btn:hover { background: #1c1f2c; color: #fff; }
.sidebar .nav-btn.active { background: var(--sidebar-active-bg); color: #fff; font-weight: 600; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.topbar .search-box { flex: 1; max-width: 360px; position: relative; }
.topbar .search-box input {
  width: 100%; padding: 7px 12px 7px 32px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  background: var(--bg);
}
.topbar .search-box svg.icon { position: absolute; left: 9px; top: 8px; color: var(--text-muted); }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.topbar .user-info { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; }
.topbar .user-info b { color: var(--text); }

main { max-width: 1080px; width: 100%; margin: 0 auto; padding: 24px; }
.panel { display: none; }
.panel.active { display: block; }

/* ---- Notification bell ---- */
.notif-wrap { position: relative; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center; cursor: pointer; position: relative; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.notif-badge {
  position: absolute; top: -5px; right: -5px; background: var(--danger); color: #fff; font-size: 10px;
  font-weight: 700; border-radius: 999px; min-width: 16px; height: 16px; display: flex; align-items: center;
  justify-content: center; padding: 0 3px;
}
.notif-dropdown {
  position: absolute; top: 42px; right: 0; width: 340px; max-height: 420px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12); z-index: 50;
}
.notif-dropdown .notif-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.notif-dropdown .notif-header h4 { margin: 0; font-size: 13px; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: var(--primary-soft); }
.notif-item .msg { margin-bottom: 3px; }
.notif-item .time { color: var(--text-muted); font-size: 11px; }

/* ---- Avatar ---- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff;
  font-weight: 700; flex-shrink: 0; font-size: 11px; line-height: 1;
}
.avatar-row { display: inline-flex; align-items: center; gap: 6px; }

/* ---- Cards / grid ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 720px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60; transform: translateX(-100%);
    transition: transform .15s ease-out; box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: flex; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr 1fr; }
  main { padding: 14px; }
}
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55;
}
.sidebar-overlay.show { display: block; }

.stat-tile { text-align: center; }
.stat-tile .value { font-size: 26px; font-weight: 700; }
.stat-tile .label { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.progress-bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; margin-top: 8px; }
.progress-bar > div { height: 100%; background: var(--primary); border-radius: 999px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.bar-row .bar-track { flex: 1; height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar-row .bar-track > div { height: 100%; background: var(--success); }
.bar-row .bar-label { font-size: 11px; color: var(--text-muted); width: 90px; flex-shrink: 0; }
.bar-row .bar-value { font-size: 11px; color: var(--text-muted); width: 50px; text-align: right; flex-shrink: 0; }

/* ---- Forms ---- */
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; margin-top: 12px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; min-height: 70px; }
button.btn {
  padding: 9px 16px; border-radius: 8px; border: none; background: var(--primary); color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer; margin-top: 14px;
}
button.btn:hover { background: var(--primary-hover); }
button.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.btn.small { padding: 5px 10px; font-size: 12px; margin-top: 0; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }

.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.view-toggle button {
  padding: 6px 14px; border: none; background: var(--surface); font-size: 12.5px; cursor: pointer; color: var(--text-muted);
}
.view-toggle button.active { background: var(--primary); color: #fff; }
.view-toggle button + button { border-left: 1px solid var(--border); }

/* ---- Task list ---- */
.task-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.task-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.task-row:hover { border-color: var(--primary); }
.task-row .title { flex: 1; font-weight: 600; }
.task-row .meta { color: var(--text-muted); font-size: 12px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.todo { background: #e5e7eb; color: #374151; }
.badge.in_progress { background: #dbeafe; color: #1d4ed8; }
.badge.done { background: #dcfce7; color: #15803d; }
.badge.blocked { background: #fee2e2; color: #b91c1c; }
.badge.priority-low { background: #f1f5f9; color: #475569; }
.badge.priority-medium { background: #fef3c7; color: #92400e; }
.badge.priority-high { background: #fee2e2; color: #b91c1c; }
.badge.overdue { background: #fee2e2; color: #b91c1c; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot.priority-low { background: #94a3b8; }
.dot.priority-medium { background: #d97706; }
.dot.priority-high { background: #dc2626; }

/* ---- Kanban ---- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 14px; align-items: start; }
@media (max-width: 900px) { .kanban { grid-template-columns: 1fr; } }
.kanban-col { background: #eceef2; border-radius: var(--radius); padding: 10px; min-height: 80px; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); outline-offset: -2px; }
.kanban-col .col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 10px; font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
.kanban-col .col-head .count { background: var(--surface); border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.kanban-cards { display: flex; flex-direction: column; gap: 8px; min-height: 20px; }
.kanban-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 10px 11px;
  cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: .4; }
.kanban-card .title { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.kanban-card .foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.kanban-card .due { font-size: 11px; color: var(--text-muted); }
.kanban-card .due.overdue { color: var(--danger); font-weight: 700; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-start;
  justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal { background: var(--surface); border-radius: var(--radius); max-width: 640px; width: 100%; padding: 22px; }
.modal h3 { margin-top: 0; }
.modal .close { float: right; cursor: pointer; color: var(--text-muted); font-size: 20px; line-height: 1; }

.timeline { border-left: 2px solid var(--border); padding-left: 14px; margin: 14px 0; display: flex; flex-direction: column; gap: 14px; }
.timeline-item .meta { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.timeline-item .note { margin-top: 4px; white-space: pre-wrap; }
.attachment-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 12px; margin: 4px 4px 0 0;
}

/* ---- Checklist ---- */
.checklist { margin: 8px 0 14px; }
.checklist-item { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.checklist-item input[type=checkbox] { width: auto; }
.checklist-item.done span.title { text-decoration: line-through; color: var(--text-muted); }
.checklist-item .del { margin-left: auto; color: var(--text-muted); cursor: pointer; font-size: 13px; }
.checklist-add { display: flex; gap: 6px; margin-top: 6px; }
.checklist-add input { flex: 1; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; }
.empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; }

table { width: 100%; border-collapse: collapse; margin-top: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; }

/* ---- Toast ---- */
#toast-root { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 320px; animation: toast-in .15s ease-out;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
