:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #45536b;
  --muted: #7d8899;
  --line: #e4e8f1;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --green: #15803d;
  --green-soft: #e7f7ee;
  --amber: #b45309;
  --amber-soft: #fdf3e3;
  --red: #c2410c;
  --red-soft: #fdeceb;
  --blue: #1d4ed8;
  --blue-soft: #e8f0ff;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }

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

.sidebar {
  width: 256px;
  flex: 0 0 256px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 70;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  display: grid; place-items: center;
  font-size: 1.05rem;
  box-shadow: 0 6px 14px rgba(79, 70, 229, .32);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: .98rem; }
.brand-text small { color: var(--muted); font-size: .74rem; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--ink-2);
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item i { width: 18px; text-align: center; font-size: .92rem; color: var(--muted); }
.nav-item:hover { background: #f5f6fb; color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-item.active i { color: var(--primary); }

.sidebar-foot { margin-top: auto; }
.me-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcff;
}
.me-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
  flex: 0 0 34px;
}
.me-info { display: flex; flex-direction: column; min-width: 0; }
.me-info span { font-size: .84rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-info small { color: var(--muted); font-size: .74rem; }

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

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  height: 62px;
  padding: 0 20px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 650; font-size: .98rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.role-chip {
  font-size: .76rem; font-weight: 600;
  padding: 5px 11px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
  white-space: nowrap;
}
#sidebar-toggle { display: none; }

.view { padding: 24px 20px 56px; width: 100%; max-width: 1200px; margin: 0 auto; }

/* ---------- generic ---------- */
.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-head .head-text { flex: 1; min-width: 200px; }
.page-head h1 { margin-bottom: 4px; }
.page-head .head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .88rem;
  padding: 9px 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .06s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 14px rgba(79, 70, 229, .22); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: #f6f7fc; }
.btn-danger { background: var(--red-soft); color: var(--red); border-color: #f7d6d1; }
.btn-danger:hover:not(:disabled) { background: #fbdcd8; }
.btn-sm { padding: 6px 11px; font-size: .8rem; border-radius: 8px; }

.icon-btn {
  border: 1px solid transparent;
  background: transparent;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: inline-grid; place-items: center;
  cursor: pointer;
  color: var(--ink-2);
  font-size: .95rem;
  transition: background .15s;
}
.icon-btn:hover { background: #f1f3f9; }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: #a5b4fc;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .14);
}
textarea { resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237d8899' d='M6 8.5 1.5 4h9z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.field { display: block; margin-bottom: 13px; }
.field-label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field-hint { display: block; font-size: .74rem; color: var(--muted); margin-top: 5px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }

.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search { position: relative; flex: 1 1 220px; }
.search input { padding-left: 34px; }
.search > i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .85rem; }
.toolbar select { width: auto; min-width: 160px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .74rem; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: #f1f3f9; color: var(--ink-2);
  white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-primary { background: var(--primary-soft); color: var(--primary-dark); }

.progress { height: 7px; border-radius: 999px; background: #eef1f7; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #6366f1, #4f46e5); transition: width .3s; }
.progress.sm { height: 5px; }
.progress > span.done { background: linear-gradient(90deg, #34d399, #15803d); }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin .7s linear infinite;
}
.loading-block {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted);
  padding: 40px 4px;
  font-size: .9rem;
}
.loading-block .spinner { border-color: var(--line); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: 44px 18px;
  color: var(--muted);
}
.empty i { font-size: 1.6rem; color: #c3cad8; display: block; margin-bottom: 10px; }
.empty strong { display: block; color: var(--ink-2); margin-bottom: 4px; }

.error-box {
  background: var(--red-soft);
  border: 1px solid #f7d6d1;
  color: #8c2f10;
  border-radius: var(--radius);
  padding: 16px 18px;
}

/* ---------- dashboard ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  box-shadow: var(--shadow-sm);
}
.kpi .kpi-top { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.kpi .kpi-icon {
  width: 26px; height: 26px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary);
  font-size: .78rem;
}
.kpi .kpi-value { font-size: 1.75rem; font-weight: 700; margin-top: 8px; letter-spacing: -.02em; }
.kpi .kpi-sub { font-size: .76rem; color: var(--muted); }

.dash-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 16px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

.mini-list { display: flex; flex-direction: column; }
.mini-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 2px;
  border-top: 1px solid var(--line);
}
.mini-item:first-child { border-top: none; }
.mini-main { flex: 1; min-width: 0; }
.mini-title { font-weight: 600; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-sub { font-size: .76rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- project cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.pcard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow .18s, transform .18s, border-color .18s;
  display: flex; flex-direction: column; gap: 10px;
}
.pcard:hover { box-shadow: var(--shadow); transform: translateY(-2px); border-color: #d6dbea; }
.pcard-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pcard h3 { font-size: .98rem; line-height: 1.35; }
.pcard .pcard-desc {
  color: var(--muted); font-size: .82rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.4em;
}
.pcard-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); }
.pcard-meta span { display: inline-flex; align-items: center; gap: 5px; }
.pcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pcard-foot .pct { font-size: .78rem; font-weight: 600; color: var(--ink-2); }

/* ---------- detail ---------- */
.detail-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.back-link { display: inline-flex; align-items: center; gap: 7px; font-size: .82rem; color: var(--muted); margin-bottom: 10px; font-weight: 500; }
.back-link:hover { color: var(--primary); }
.detail-title-row { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.detail-title-row h1 { flex: 1; min-width: 220px; }
.detail-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-desc { color: var(--ink-2); font-size: .88rem; margin-top: 8px; }
.info-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px; margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--line);
}
.info-item .info-label { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.info-item .info-value { font-size: .9rem; font-weight: 600; margin-top: 3px; }

/* ---------- task list ---------- */
.task-list { display: flex; flex-direction: column; }
.task-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 14px 2px;
  border-top: 1px solid var(--line);
}
.task-row:first-child { border-top: none; }
.task-check {
  width: 20px; height: 20px; margin-top: 2px;
  border-radius: 6px; border: 1.5px solid #cbd3e2;
  background: #fff; cursor: pointer;
  display: grid; place-items: center;
  color: transparent; font-size: .62rem;
  transition: background .15s, border-color .15s, color .15s;
}
.task-check:hover { border-color: var(--primary); }
.task-check.done { background: var(--green); border-color: var(--green); color: #fff; }
.task-name { font-weight: 600; font-size: .9rem; }
.task-name.done { text-decoration: line-through; color: var(--muted); }
.task-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .76rem; color: var(--muted); margin-top: 5px; }
.task-meta span { display: inline-flex; align-items: center; gap: 5px; }
.task-meta .late { color: var(--red); font-weight: 600; }
.task-bar { margin-top: 8px; max-width: 220px; display: flex; align-items: center; gap: 8px; }
.task-bar .progress { flex: 1; }
.task-bar small { color: var(--muted); font-size: .72rem; width: 32px; text-align: right; }
.task-actions { display: flex; gap: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; min-width: 620px; }
table.data th {
  text-align: left; font-size: .74rem; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: #fbfcff; white-space: nowrap;
}
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: .86rem; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #fafbff; }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: .76rem; color: var(--muted); }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 200;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 16px;
  width: 100%; max-width: 520px;
  max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  overflow: hidden;
}
.modal-wide { max-width: 680px; }
.modal form { display: flex; flex-direction: column; min-height: 0; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); background: #fbfcff; }

/* ---------- misc small ---------- */
.role-legend { display: grid; gap: 8px; margin-top: 4px; }
.role-legend div { display: flex; gap: 10px; align-items: baseline; font-size: .84rem; }
.tabs { display: inline-flex; background: #eef0f7; border-radius: 10px; padding: 3px; gap: 3px; }
.tab {
  border: none; background: transparent; font: inherit; font-weight: 600; font-size: .85rem;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--ink-2);
}
.tab.active { background: #fff; color: var(--primary-dark); box-shadow: var(--shadow-sm); }
.summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 16px; }
.summary-strip .kpi { padding: 12px 14px; }
.summary-strip .kpi-value { font-size: 1.4rem; }
.load-more-row { display: flex; justify-content: center; padding-top: 14px; }

.skeleton {
  background: linear-gradient(90deg, #eef1f7 25%, #f6f8fd 50%, #eef1f7 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: 10px;
  height: 92px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .4);
  z-index: 60;
}

/* ---------- chips / members ---------- */
.chip-group {
  display: flex; flex-wrap: wrap; gap: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fbfcff;
}
.chip-scroll { max-height: 168px; overflow-y: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .82rem; font-weight: 500;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  max-width: 100%;
}
.chip:hover { border-color: #c3caf5; }
.chip input { width: 14px; height: 14px; margin: 0; accent-color: var(--primary); flex: 0 0 14px; }
.chip:has(input:checked) { background: var(--primary-soft); border-color: #c7cbf9; color: var(--primary-dark); font-weight: 600; }
.chip-sub { color: var(--muted); font-weight: 400; font-size: .74rem; }

.avatar-stack { display: inline-flex; align-items: center; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-dark);
  display: inline-grid; place-items: center;
  font-size: .74rem; font-weight: 700;
  border: 2px solid #fff;
  margin-left: -7px;
  flex: 0 0 auto;
}
.avatar-stack .avatar:first-child { margin-left: 0; }
.avatar-more { background: #eef1f7; color: var(--ink-2); font-size: .68rem; }

.member-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; }
.member-card {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfcff;
}
.member-card .avatar { margin-left: 0; border: none; width: 30px; height: 30px; font-size: .8rem; }
.member-main { flex: 1; min-width: 0; }
.member-name { font-weight: 600; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.open { display: block; }
  #sidebar-toggle { display: inline-grid; }
  .view { padding: 18px 14px 48px; }
}

@media (max-width: 560px) {
  h1 { font-size: 1.32rem; }
  .page-head { margin-bottom: 16px; }
  .page-head .head-actions { width: 100%; }
  .page-head .head-actions .btn { flex: 1; }
  .task-row { grid-template-columns: 22px minmax(0, 1fr); }
  .task-actions { grid-column: 2; justify-content: flex-end; }
  .modal { max-height: 96vh; }
  .modal-body { padding: 14px; }
  .card { padding: 14px; }
}

@media (min-width: 1024px) {
  .view { padding: 28px 28px 64px; }
}
