/* =====================================================================
   MPM Toolkits — components
   ===================================================================== */

/* ---- App shell ------------------------------------------------------ */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
/* collapse is driven by html[data-nav-collapsed] (see below) */

.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  overflow: hidden;
}
.brand {
  height: var(--header-h); display: flex; align-items: center; gap: .6rem;
  padding: 0 1.1rem; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: var(--accent-ink);
  font-family: var(--font-mono); font-weight: 700; font-size: 14px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.15);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.brand-name small { display: block; font-weight: 500; font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); font-family: var(--font-mono); }

.nav { padding: .75rem .6rem; overflow-y: auto; flex: 1; }
.nav-group + .nav-group { margin-top: 1.1rem; }
.nav-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint); padding: 0 .55rem .4rem;
}
.nav-item {
  display: flex; align-items: center; gap: .65rem; padding: .5rem .55rem;
  border-radius: var(--r-md); color: var(--ink-2); font-weight: 500;
  transition: background .12s, color .12s; position: relative;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav-item.active { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -.6rem; top: 20%; bottom: 20%;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; stroke-width: 1.8; }
.nav-item .count { margin-left: auto; font-family: var(--font-mono); font-size: 11px;
  color: var(--muted); background: var(--surface-2); padding: 1px 6px; border-radius: 20px; }

/* ---- Header --------------------------------------------------------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--header-h); display: flex; align-items: center; gap: 1rem;
  padding: 0 1.5rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 16px; }
.topbar .crumb { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted);
  letter-spacing: .04em; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 17px; height: 17px; stroke-width: 1.8; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 12px; color: #fff;
  background: var(--accent); flex-shrink: 0;
}
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: .55rem; padding: .3rem .3rem; border: 0;
  background: none; cursor: pointer; color: var(--ink); border-radius: var(--r-md); }
.user-btn:hover { background: var(--surface-2); }
.user-btn .u-name { font-weight: 600; font-size: 13px; }
.user-btn .u-role { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }

.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop); padding: .4rem; z-index: 50;
}
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left;
  padding: .5rem .6rem; border-radius: var(--r-sm); color: var(--ink-2);
  border: 0; background: none; cursor: pointer; font: inherit;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.dropdown .sep { height: 1px; background: var(--line); margin: .35rem .2rem; }

/* ---- Content -------------------------------------------------------- */
.content { padding: 1.5rem; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-end; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.page-head .titles h1 { font-size: 22px; letter-spacing: -.02em; }
.page-head .titles p { margin: .2rem 0 0; color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: .6rem; }

/* ---- Cards ---------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-pad { padding: 1.15rem 1.25rem; }
.card-head { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 14px; }
.card-head .actions { margin-left: auto; }

/* metric tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow-1); position: relative; overflow: hidden; }
.tile .t-label { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); }
.tile .t-value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin-top: .35rem;
  font-variant-numeric: tabular-nums; }
.tile .t-sub { font-size: 12px; color: var(--muted); margin-top: .2rem; }
.tile .t-accent { position: absolute; right: -12px; top: -12px; width: 64px; height: 64px;
  border-radius: 50%; opacity: .08; background: var(--accent); }

/* ---- Tables --------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
  padding: .65rem .9rem; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.data td { padding: .7rem .9rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data .row-actions { display: flex; gap: .35rem; justify-content: flex-end; }

/* ---- Badges & status ------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: .35rem; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px; line-height: 1.5; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.tint { background: color-mix(in srgb, var(--tint) 14%, transparent); color: var(--tint); }
.badge.solid { background: var(--tint); color: #fff; }

.pill-count { font-family: var(--font-mono); font-size: 11px; background: var(--surface-3);
  color: var(--muted); padding: 1px 7px; border-radius: 20px; }

/* progress */
.progress { height: 6px; background: var(--surface-3); border-radius: 20px; overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 20px; }

/* ---- Buttons -------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; font: inherit; font-weight: 600;
  font-size: 13px; padding: .5rem .9rem; border-radius: var(--r-md); border: 1px solid transparent;
  cursor: pointer; transition: background .12s, border-color .12s, color .12s; white-space: nowrap;
  text-decoration: none;
}
.btn svg { width: 16px; height: 16px; stroke-width: 2; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-2); text-decoration: none; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.btn-subtle { background: var(--surface-2); color: var(--ink-2); }
.btn-subtle:hover { background: var(--surface-3); text-decoration: none; }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); text-decoration: none; }
.btn-sm { padding: .3rem .6rem; font-size: 12px; }
.btn-icon { padding: .4rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Forms ---------------------------------------------------------- */
.field { margin-bottom: 1.05rem; }
.field label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: .35rem; color: var(--ink-2); }
.field label .req { color: var(--err); }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: .3rem; }
.field .err-msg { font-size: 11.5px; color: var(--err); margin-top: .3rem; }

.input, .select, .textarea {
  width: 100%; font: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: .55rem .7rem; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--err); }
.select { appearance: none; background-image:
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .6rem center; padding-right: 2rem; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1.1rem; }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

.checkline { display: flex; align-items: center; gap: .5rem; font-size: 13px; }

/* ---- Flash / alerts ------------------------------------------------- */
.flash-stack { position: fixed; top: 1rem; right: 1rem; z-index: 200; display: flex;
  flex-direction: column; gap: .6rem; max-width: 380px; }
.alert {
  display: flex; gap: .6rem; align-items: flex-start; padding: .75rem .9rem;
  border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-2); font-size: 13px; animation: slidein .2s ease;
}
.alert .bar { width: 3px; border-radius: 3px; align-self: stretch; }
.alert.success .bar { background: var(--ok); } .alert.success svg { color: var(--ok); }
.alert.danger .bar  { background: var(--err); } .alert.danger svg { color: var(--err); }
.alert.info .bar    { background: var(--info); } .alert.info svg { color: var(--info); }
@keyframes slidein { from { opacity: 0; transform: translateX(12px); } }

/* ---- Empty state ---------------------------------------------------- */
.empty { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.empty svg { width: 40px; height: 40px; stroke-width: 1.4; color: var(--faint); margin-bottom: .75rem; }
.empty h3 { font-size: 15px; margin-bottom: .3rem; color: var(--ink-2); }

/* ---- Kanban --------------------------------------------------------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(272px, 1fr);
  gap: 1rem; overflow-x: auto; padding-bottom: .5rem; align-items: start; }
.column { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-lg);
  display: flex; flex-direction: column; max-height: calc(100vh - 220px); }
.column-head { display: flex; align-items: center; gap: .5rem; padding: .8rem .9rem;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.column-head .k-dot { width: 9px; height: 9px; border-radius: 50%; }
.column-head .k-title { font-weight: 600; font-size: 13px; }
.column-head .k-count { margin-left: auto; }
.column-body { padding: .7rem; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem;
  flex: 1; min-height: 60px; }
.column-body.drop-hover { background: var(--accent-wash); outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: var(--r-md); }

.tcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: .7rem .8rem; box-shadow: var(--shadow-1); cursor: grab; transition: box-shadow .12s, transform .06s; }
.tcard:hover { box-shadow: var(--shadow-2); }
.tcard.dragging { opacity: .5; }
.tcard .t-code { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); letter-spacing: .03em; }
.tcard .t-title { font-weight: 600; font-size: 13px; margin: .25rem 0 .5rem; line-height: 1.35; }
.tcard .t-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.tcard .t-foot { display: flex; align-items: center; gap: .5rem; margin-top: .55rem;
  padding-top: .55rem; border-top: 1px solid var(--line-2); }
.tcard .t-foot .att { font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  display: inline-flex; align-items: center; gap: .2rem; }

/* ---- Modal ---------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(8,13,19,.55); z-index: 100;
  display: grid; place-items: start center; padding: 3rem 1rem; overflow-y: auto;
  animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-pop);
  width: 100%; max-width: 640px; animation: pop .18s cubic-bezier(.2,.9,.3,1.1); }
.modal.lg { max-width: 820px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal-head { display: flex; align-items: center; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 16px; }
.modal-head .close { margin-left: auto; }
.modal-body { padding: 1.3rem; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; gap: .6rem; justify-content: flex-end; padding: 1rem 1.3rem;
  border-top: 1px solid var(--line); }

/* ---- Detail layout -------------------------------------------------- */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.dl { display: grid; grid-template-columns: minmax(120px,auto) 1fr; gap: .55rem 1rem; font-size: 13px; }
.dl dt { color: var(--muted); font-family: var(--font-mono); font-size: 11.5px; letter-spacing: .03em;
  text-transform: uppercase; padding-top: 1px; }
.dl dd { margin: 0; color: var(--ink); }

/* file list */
.file-row { display: flex; align-items: center; gap: .7rem; padding: .55rem .2rem; border-bottom: 1px solid var(--line-2); }
.file-row:last-child { border-bottom: 0; }
.file-ic { width: 32px; height: 32px; border-radius: var(--r-sm); background: var(--accent-wash);
  color: var(--accent); display: grid; place-items: center; flex-shrink: 0; }
.file-ic svg { width: 16px; height: 16px; }
.file-row .f-name { font-weight: 500; font-size: 13px; }
.file-row .f-meta { font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

/* login */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
@media (max-width: 860px) { .auth-wrap { grid-template-columns: 1fr; } .auth-aside { display: none; } }
.auth-aside { background: linear-gradient(150deg, #0b2430, #0f1720 60%); color: #cfe8ee; padding: 3rem;
  display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-aside .grid-bg { position: absolute; inset: 0; opacity: .5;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 28px 28px; mask-image: radial-gradient(circle at 30% 40%, #000, transparent 80%); }
.auth-aside .a-inner { position: relative; z-index: 1; }
.auth-aside h2 { color: #fff; font-size: 26px; letter-spacing: -.02em; max-width: 15ch; line-height: 1.2; }
.auth-aside .lede { color: #9fc4cd; margin-top: 1rem; max-width: 34ch; }
.auth-aside .stat-line { display: flex; gap: 2rem; margin-top: 2rem; }
.auth-aside .stat-line .n { font-family: var(--font-mono); font-size: 22px; font-weight: 700; color: #fff; }
.auth-aside .stat-line .l { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #7ea7b0; }
.auth-main { display: grid; place-items: center; padding: 2rem; background: var(--ground); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { border: 0; height: auto; padding: 0; margin-bottom: 2rem; }

/* responsive sidebar */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; width: var(--sidebar-w); transform: translateX(-100%);
    transition: transform .2s; }
  .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-pop); }
  .scrim { position: fixed; inset: 0; background: rgba(8,13,19,.5); z-index: 55; }
}

/* ---- Segmented view switcher (List/Board/Gantt) ------------------- */
.segmented { display:inline-flex; border:1px solid var(--line); border-radius:var(--r-md); overflow:hidden; background:var(--surface-2); }
.segmented .seg-btn { padding:.42rem .85rem; font-size:.85rem; font-weight:600; color:var(--ink-2); text-decoration:none; border-right:1px solid var(--line); transition:background .12s,color .12s; }
.segmented .seg-btn:last-child { border-right:0; }
.segmented .seg-btn:hover { background:var(--surface); color:var(--ink); }
.segmented .seg-btn.active { background:var(--accent); color:#fff; }
.chip { display:inline-block; padding:.32rem .6rem; border:1px solid var(--line); border-radius:999px; font-size:.8rem; color:var(--ink-2); background:var(--surface-2); }
a.chip:hover { border-color:var(--accent); color:var(--ink); text-decoration:none; }

/* ---- Collapsible sidebar (icon rail) --------------------------------- */
.desktop-only { display: inline-flex; }
@media (max-width: 900px) { .desktop-only { display: none !important; } }

.app { transition: grid-template-columns .18s ease; }
html[data-nav-collapsed="1"] .app { grid-template-columns: var(--sidebar-rail-w, 68px) 1fr; }

/* Collapse the sidebar down to a centred icon rail. */
html[data-nav-collapsed="1"] .app .sidebar { overflow: hidden; }
html[data-nav-collapsed="1"] .app .nav-item span,
html[data-nav-collapsed="1"] .app .nav-label,
html[data-nav-collapsed="1"] .app .brand-name { display: none; }
html[data-nav-collapsed="1"] .app .brand { justify-content: center; padding: 0; }
html[data-nav-collapsed="1"] .app .nav { padding: .75rem .4rem; }
html[data-nav-collapsed="1"] .app .nav-item { justify-content: center; padding-left: 0; padding-right: 0; }
html[data-nav-collapsed="1"] .app .sidebar-foot { display: none; }

/* On small screens the sidebar is off-canvas, so ignore the collapsed rail. */
@media (max-width: 900px) { html[data-nav-collapsed="1"] .app { grid-template-columns: 1fr; } }
