:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --soft: #9ca3af;
  --accent: #ff9900;
  --accent-dark: #e08600;
  --accent-soft: #fff4e0;
  --side: #111827;
  --side-text: #d1d5db;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --purple: #7c3aed;
  --purple-soft: #ede9fe;
  --grey-soft: #f3f4f6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 1px 3px rgba(17, 24, 39, .06);
  --shadow-lg: 0 20px 40px rgba(17, 24, 39, .18);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

/* ---------- Boot / auth ---------- */
.boot-loader { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #111827 0%, #1f2937 55%, #111827 100%); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 32px; box-shadow: var(--shadow-lg); }
.auth-card .brand { margin-bottom: 24px; }
.auth-card h2 { font-size: 18px; margin-bottom: 4px; }
.auth-card p.sub { color: var(--muted); margin: 0 0 20px; }
.auth-card .link-btn { margin-top: 14px; }
.notice { background: var(--accent-soft); border: 1px solid #ffd699; padding: 12px 14px; border-radius: 8px; line-height: 1.5; }
.notice code { background: #fff; padding: 1px 5px; border-radius: 4px; }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #111827; display: grid; place-items: center; font-weight: 700; font-size: 17px; flex-shrink: 0; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-sub { color: var(--soft); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.sidebar .brand { padding: 4px 8px 22px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-text); font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(255, 153, 0, .14); color: #fff; }
.nav a.active svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav .badge { margin-left: auto; background: var(--accent); color: #111827; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; }
.side-user { border-top: 1px solid rgba(255, 255, 255, .08); padding: 14px 8px 0; display: flex; align-items: center; gap: 10px; }
.side-user .who { min-width: 0; }
.side-user .who b { display: block; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user .who span { font-size: 12px; color: var(--soft); text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 19px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.view { padding: 24px 28px 48px; }

/* ---------- Avatars ---------- */
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; font-weight: 600; color: #fff; flex-shrink: 0; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.avatar.empty { background: var(--grey-soft); color: var(--soft); border: 1px dashed var(--border-strong); }
.person { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.person span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--grey-soft); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #111827; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--grey-soft); }
.btn.block { width: 100%; padding: 10px 14px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 13px; text-decoration: underline; }
.icon-btn { border: none; background: none; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--grey-soft); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 500; color: #374151; }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 153, 0, .18); }
.input:disabled { background: var(--grey-soft); color: var(--muted); }
textarea.input { resize: vertical; min-height: 84px; line-height: 1.5; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.form-error { background: var(--danger-soft); color: #991b1b; padding: 9px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.toolbar .input { width: auto; min-width: 150px; padding: 7px 10px; }
.toolbar .search { min-width: 220px; }
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 7px 12px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--text); color: #fff; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-h h3 { font-size: 15px; }
.card-h .muted { font-size: 13px; }
.card-b { padding: 16px 18px; }
.muted { color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.stat .foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.warn .value { color: var(--danger); }
.stat.hl { border-top: 3px solid var(--accent); }

.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
.dash-grid > .col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ---------- Lists / tables ---------- */
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); cursor: pointer; }
.row:last-child { border-bottom: none; }
.row:hover { background: #fafafa; }
.row .main-col { flex: 1; min-width: 0; }
.row .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 28px 18px; text-align: center; color: var(--muted); }
.empty-big { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-big h3 { color: var(--text); margin-bottom: 6px; }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: #fafafa; white-space: nowrap; }
.tbl td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fafafa; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--grey-soft); color: #374151; }
.pill.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-todo { background: var(--grey-soft); color: #4b5563; }
.s-in_progress { background: var(--blue-soft); color: var(--blue); }
.s-review { background: var(--purple-soft); color: var(--purple); }
.s-done { background: var(--ok-soft); color: var(--ok); }
.ps-planning { background: var(--grey-soft); color: #4b5563; }
.ps-active { background: var(--blue-soft); color: var(--blue); }
.ps-on_hold { background: var(--accent-soft); color: #b45309; }
.ps-completed { background: var(--ok-soft); color: var(--ok); }
.p-low { background: var(--grey-soft); color: #6b7280; }
.p-medium { background: var(--blue-soft); color: var(--blue); }
.p-high { background: var(--accent-soft); color: #b45309; }
.p-urgent { background: var(--danger-soft); color: var(--danger); }
.cs-active { background: var(--ok-soft); color: var(--ok); }
.cs-paused { background: var(--accent-soft); color: #b45309; }
.cs-ended { background: var(--grey-soft); color: #6b7280; }
.role-admin { background: #111827; color: #fff; }
.due { font-size: 12px; color: var(--muted); white-space: nowrap; }
.due.over { color: var(--danger); font-weight: 600; }
.due.soon { color: #b45309; font-weight: 500; }

/* ---------- Projects ---------- */
.proj-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.proj-card { padding: 16px 18px; cursor: pointer; transition: border-color .15s, transform .15s; display: flex; flex-direction: column; gap: 12px; }
.proj-card:hover { border-color: var(--accent); }
.proj-card .client { font-size: 12px; color: var(--muted); font-weight: 500; }
.proj-card h3 { font-size: 15px; margin-top: 2px; }
.proj-card .top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.proj-card .bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.progress { height: 6px; background: var(--grey-soft); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 999px; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.proj-head { padding: 20px 22px; margin-bottom: 20px; }
.proj-head .top { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.proj-head h2 { font-size: 20px; margin: 4px 0 8px; }
.proj-head .desc { color: #374151; line-height: 1.6; margin: 12px 0 0; white-space: pre-wrap; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.meta-grid .k { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 500; margin-bottom: 14px; }
.back:hover { color: var(--text); }
.back svg { width: 16px; height: 16px; }

/* ---------- Board ---------- */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 6px; }
.col-b { background: #eef0f3; border-radius: var(--radius); padding: 10px; min-height: 220px; display: flex; flex-direction: column; gap: 8px; transition: background .15s, outline-color .15s; outline: 2px dashed transparent; outline-offset: -2px; }
.col-b.over { background: var(--accent-soft); outline-color: var(--accent); }
.col-b .col-h { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; font-weight: 600; font-size: 13px; }
.col-b .count { background: #fff; color: var(--muted); font-size: 12px; padding: 1px 8px; border-radius: 999px; }
.tcard { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.tcard:hover { border-color: var(--border-strong); }
.tcard.dragging { opacity: .45; }
.tcard[draggable="true"] { cursor: grab; }
.tcard .t { font-weight: 500; line-height: 1.4; }
.tcard .proj { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcard .foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tcard .foot .l { display: flex; align-items: center; gap: 6px; }
.tcard .cmt { font-size: 12px; color: var(--soft); }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 50; display: grid; place-items: center; padding: 20px; animation: fade .12s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .15s ease-out; }
.modal.sm { max-width: 420px; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal-h { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-h h3 { font-size: 16px; }
.modal-b { padding: 20px 22px 6px; overflow-y: auto; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, .35); z-index: 40; animation: fade .12s ease-out; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 520px; max-width: 100%; background: #fff; z-index: 41; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-h { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.drawer-h .crumb { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-h .crumb a:hover { color: var(--text); text-decoration: underline; }
.drawer-b { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-f { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; gap: 8px; }
.title-input { font-size: 18px; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; margin: -6px -8px 12px; width: calc(100% + 16px); outline: none; }
.title-input:hover:not(:disabled) { border-color: var(--border); }
.title-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 153, 0, .18); }
.title-input:disabled { background: transparent; color: var(--text); }
.section-t { font-size: 13px; font-weight: 600; margin: 22px 0 10px; color: #374151; }
.comments { display: flex; flex-direction: column; gap: 14px; margin-bottom: 14px; }
.comment { display: flex; gap: 10px; }
.comment .bubble { flex: 1; min-width: 0; }
.comment .head { font-size: 12px; color: var(--muted); margin-bottom: 3px; display: flex; gap: 8px; align-items: center; }
.comment .head b { color: var(--text); font-weight: 600; }
.comment .body { background: var(--grey-soft); padding: 9px 12px; border-radius: 0 10px 10px 10px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.comment .del { margin-left: auto; font-size: 12px; }

/* ---------- Workload ---------- */
.load-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--grey-soft); min-width: 80px; }
.load-bar span { height: 100%; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); font-weight: 500; animation: pop .15s ease-out; max-width: 90vw; }
.toast.error { background: var(--danger); }
.toast.ok { background: #111827; border-left: 4px solid var(--accent); }

/* ---------- Info box ---------- */
.info { background: #f9fafb; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; line-height: 1.6; color: #374151; margin-bottom: 18px; }
.info b { color: var(--text); }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; max-width: 900px; }

/* ---------- Mobile ---------- */
.mobile-nav { display: none; }
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .sidebar { display: none; }
  .mobile-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--side); z-index: 30; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .mobile-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--side-text); font-size: 11px; padding: 4px 6px; border-radius: 6px; }
  .mobile-nav a.active { color: var(--accent); }
  .mobile-nav svg { width: 20px; height: 20px; }
  .topbar { padding: 14px 16px; }
  .view { padding: 16px 16px 90px; }
  .board { grid-template-columns: repeat(4, 82vw); }
  .grid-2, .grid-3, .settings-grid { grid-template-columns: 1fr; }
  .toolbar .input, .toolbar .search { min-width: 0; flex: 1 1 140px; }
  .topbar .btn .lbl { display: none; }
}
