:root {
  --red: #DA1F26;
  --green: #15924A;
  --ink: #141A21;
  --ink-2: #48586B;
  --ink-3: #93A1B2;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --line: #E5E9EF;
  --shadow-card: 0 1px 2px rgba(15,23,42,.05);
  --radius-card: 14px;
  --radius-btn: 10px;
  --radius-input: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
svg { width: 18px; height: 18px; flex-shrink: 0; }
.x-btn svg { width: 17px; height: 17px; }
::selection { background: rgba(218,31,38,.18); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,.3); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
@keyframes mitFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mitSheet { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

.grotesk { font-family: 'Space Grotesk', sans-serif; letter-spacing: -0.02em; }
.mono { font-family: 'IBM Plex Mono', monospace; }
.muted { color: var(--ink-3); }
.pre { white-space: pre-wrap; }
.section-label { font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- toasts ---------- */
.toast-wrap { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: 92vw; }
.toast { padding: 11px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600; box-shadow: 0 8px 24px rgba(15,23,42,.16); transition: opacity .4s; animation: mitFade .2s ease; }
.toast-error { background: #FCE8E9; color: #9b1c1c; border: 1px solid #f3b9bb; }
.toast-success { background: #E4F5EB; color: #15803d; border: 1px solid #a7e3bd; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; font-size: 14px; font-weight: 600; border-radius: var(--radius-btn); border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; transition: filter .15s, background .15s, transform .05s; }
.btn:active { transform: translateY(1px); }
.btn:hover { filter: brightness(.98); }
.btn svg { width: 17px; height: 17px; }
.btn-sm { padding: 7px 12px; font-size: 13px; gap: 6px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-lg { padding: 13px 20px; font-size: 15px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--red); color: #fff; border-color: var(--red); box-shadow: 0 1px 2px rgba(218,31,38,.25); }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-success { background: var(--green); color: #fff; border-color: var(--green); box-shadow: 0 1px 2px rgba(21,146,74,.25); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: transparent; }
.btn-danger { background: var(--surface); color: var(--red); border-color: #DA1F2633; }
.btn[disabled], .btn.is-disabled { opacity: .5; pointer-events: none; }

/* ---------- card ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 18px; box-shadow: var(--shadow-card); }
.card.pad0 { padding: 0; }
a.card, .card.clickable { display: block; transition: box-shadow .18s, transform .18s; }
a.card:hover, .card.clickable:hover { box-shadow: 0 6px 22px rgba(15,23,42,.09); transform: translateY(-1px); }
.card.alert { border-color: var(--red); }
.divider { height: 1px; background: var(--line); }

/* ---------- pills / tags ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 1; white-space: nowrap; }
.pill.sm { padding: 3px 9px; font-size: 11.5px; }
.pill .dot { width: 7px; height: 7px; border-radius: 999px; background: currentColor; }
.prio { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.prio .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 7px; background: var(--bg); border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.eta-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 8px; background: var(--bg); color: var(--ink-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.eta-chip svg { width: 13px; height: 13px; }
.eta-chip.big { padding: 6px 11px; font-size: 13px; }
.eta-chip.big svg { width: 15px; height: 15px; }
.eta-chip.over { background: #FCE8E9; color: var(--red); }
.eta-chip.soon { background: #FBF0DD; color: #C2700A; }

/* ---------- avatar ---------- */
.avatar { display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-family: 'Space Grotesk', sans-serif; flex-shrink: 0; border-radius: 9px; }

/* ---------- fields ---------- */
.field { display: block; }
.field > .label { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.field > .hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.input, .select, .textarea, input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], textarea, select {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-input); border: 1px solid var(--line);
  background: var(--surface); font-family: inherit; font-size: 14.5px; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(218,31,38,.12); }
.select-wrap { position: relative; }
.select-wrap select { appearance: none; padding-right: 36px; cursor: pointer; }
.select-wrap::after { content: ""; position: absolute; right: 14px; top: 50%; width: 9px; height: 9px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: translateY(-65%) rotate(45deg); pointer-events: none; }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--ink-3); }
.search-wrap input { padding-left: 38px; }

/* ---------- layout: client portal ---------- */
.portal { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }
.client-header { position: sticky; top: 0; z-index: 50; background: var(--surface); border-bottom: 1px solid var(--line); }
.client-header .inner { max-width: 980px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; gap: 14px; }
.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 28px 24px 48px; }
.icon-btn { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.dot-badge { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); }

/* brand logo lockup */
.logo { display: inline-flex; align-items: center; gap: 10px; }
.logo img { display: block; width: auto; }
.logo .word { font-family: 'Space Grotesk', sans-serif; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.logo .word .sep { color: var(--red); }

/* ---------- layout: admin ---------- */
.admin { min-height: 100vh; display: flex; background: var(--bg); }
.sidebar { width: 232px; flex-shrink: 0; background: var(--ink); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { padding: 20px 18px 18px; display: flex; align-items: center; gap: 10px; }
.sidebar .brand .word { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 16px; }
.sidebar nav { padding: 6px 12px; display: grid; gap: 4px; }
.side-btn { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; border: none; cursor: pointer; font-size: 14px; font-weight: 600; width: 100%; text-align: left; white-space: nowrap; background: transparent; color: rgba(255,255,255,.62); }
.side-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-btn.active { background: rgba(255,255,255,.13); color: #fff; }
.side-btn svg { width: 19px; height: 19px; }
.side-btn .grow { flex: 1; }
.nav-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11.5px; font-weight: 700; display: grid; place-items: center; }
.sidebar .foot { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,.1); }
.side-alert { background: rgba(218,31,38,.16); border: 1px solid rgba(218,31,38,.4); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 12.5px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 6px; }
.admin-main { flex: 1; min-width: 0; padding: 26px 30px 40px; max-width: 1180px; margin: 0 auto; width: 100%; }
.page-title { font-family: 'Space Grotesk', sans-serif; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.page-sub { color: var(--ink-2); font-size: 14px; margin: 4px 0 0; }

.row-between { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.back-btn { display: inline-flex; align-items: center; gap: 7px; background: none; border: none; color: var(--ink-2); font-size: 14px; font-weight: 600; cursor: pointer; padding: 4px 0; margin-bottom: 16px; }
.back-btn svg { width: 18px; height: 18px; }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 11px 16px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); background: var(--bg); border-bottom: 1px solid var(--line); }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--ink-2); vertical-align: middle; }
.table tr.clickable:hover td { background: var(--bg); }
.table .ttl { font-size: 14px; font-weight: 600; color: var(--ink); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.table .right { text-align: right; }

/* ---------- filter tabs (client) ---------- */
.filter-tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.filter-tabs a { padding: 10px 12px; font-size: 14px; font-weight: 600; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.filter-tabs a.active { color: var(--red); border-bottom-color: var(--red); }
.filter-tabs .n { opacity: .6; font-family: 'IBM Plex Mono', monospace; font-size: 12px; }

/* ---------- timeline ---------- */
.timeline { position: relative; }
.tl-item { display: flex; gap: 13px; position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item:not(:last-child)::before { content: ""; position: absolute; left: 15px; top: 30px; bottom: 0; width: 2px; background: var(--line); }
.tl-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; z-index: 1; }
.tl-ico svg { width: 16px; height: 16px; }
.tl-text { font-size: 14px; color: var(--ink); line-height: 1.45; }
.tl-meta { font-size: 12px; color: var(--ink-3); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- meta rows / cost ---------- */
.meta-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.meta-row svg { width: 17px; height: 17px; color: var(--ink-3); flex-shrink: 0; }
.meta-row .k { font-size: 13px; color: var(--ink-3); width: 88px; flex-shrink: 0; }
.meta-row .v { font-size: 13.5px; color: var(--ink); font-weight: 500; text-align: right; margin-left: auto; }
.cost-row { display: flex; justify-content: space-between; align-items: baseline; }
.cost-row .k { font-size: 13.5px; color: var(--ink-2); }
.cost-row .v { font-family: 'IBM Plex Mono', monospace; font-size: 14px; font-weight: 500; }
.cost-row.strong .v { font-size: 17px; font-weight: 700; color: var(--red); }

/* ---------- attachments ---------- */
.att { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-input); background: var(--bg); }
.att .ico { width: 32px; height: 32px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-2); flex-shrink: 0; }
.att .ico svg { width: 17px; height: 17px; }
.att .nm { font-size: 13.5px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .sz { font-size: 11.5px; color: var(--ink-3); }
.dropzone { display: flex; align-items: center; gap: 11px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; color: var(--ink-3); font-size: 13.5px; flex-wrap: wrap; }
.dropzone input[type=file] { font-size: 13px; border: none; padding: 0; width: auto; }

/* ---------- estimate banner ---------- */
.est-banner { border: 1.5px solid var(--red); border-radius: var(--radius-card); overflow: hidden; box-shadow: 0 4px 20px rgba(218,31,38,.10); }
.est-banner .hd { background: var(--red); color: #fff; padding: 11px 18px; display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 700; }
.est-banner .bd { padding: 18px; background: var(--surface); }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { flex: 1 1 120px; min-width: 110px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px; }
.stat.accent { background: var(--red); border-color: var(--red); }
.stat .k { font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin-bottom: 3px; }
.stat.accent .k { color: rgba(255,255,255,.8); }
.stat .v { font-family: 'IBM Plex Mono', monospace; font-size: 18px; font-weight: 600; color: var(--ink); }
.stat.accent .v { color: #fff; }
.note-box { font-size: 14px; color: var(--ink); line-height: 1.55; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; }
.est-result { display: flex; align-items: center; gap: 11px; padding: 12px 16px; border-radius: var(--radius-card); font-size: 13.5px; font-weight: 600; }
.est-result.ok { border: 1px solid #15924A33; background: #15924A0F; }
.est-result.no { border: 1px solid #DA1F2633; background: #DA1F260F; }
.est-result svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ---------- sheets (dialog) ---------- */
dialog.sheet { padding: 0; border: none; border-radius: 18px; width: 100%; max-width: 480px; max-height: 92vh; box-shadow: 0 24px 60px rgba(15,23,42,.28); overflow: hidden; animation: mitSheet .22s cubic-bezier(.2,.8,.2,1); }
dialog.sheet.wide { max-width: 620px; }
dialog.sheet::backdrop { background: rgba(15,23,42,.42); backdrop-filter: blur(2px); }
.sheet .sh-hd { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.sheet .sh-hd .t { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 17px; }
.sheet .sh-bd { padding: 20px; overflow-y: auto; }
.sheet .sh-ft { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; background: var(--bg); }
.x-btn { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; color: var(--ink-2); }
.total-bar { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--ink); border-radius: 12px; }
.total-bar .k { color: rgba(255,255,255,.8); font-size: 13.5px; font-weight: 600; }
.total-bar .v { font-family: 'IBM Plex Mono', monospace; color: #fff; font-size: 24px; font-weight: 700; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 16px; }
.stack-sm { display: grid; gap: 12px; }
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.detail-grid.client { grid-template-columns: 1fr 300px; }
.rail { display: grid; gap: 16px; position: sticky; top: 26px; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--ink-3); }
.empty .ico { width: 56px; height: 56px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; margin: 0 auto 14px; color: var(--ink-2); }
.empty .t { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: flex; background: var(--surface); }
.brand-panel { position: relative; overflow: hidden; background: var(--ink); color: #fff; flex: 1 1 0; padding: 48px 44px; display: flex; flex-direction: column; justify-content: space-between; }
.brand-panel .matrix { position: absolute; inset: 0; opacity: .16; background: repeating-linear-gradient(90deg, transparent 0 22px, rgba(43,212,74,.5) 22px 23px); -webkit-mask-image: linear-gradient(120deg,transparent,#000 60%); mask-image: linear-gradient(120deg,transparent,#000 60%); }
.brand-panel .top { position: relative; display: flex; align-items: center; gap: 12px; }
.brand-panel .top .word { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 27px; letter-spacing: -0.02em; }
.brand-panel h2 { position: relative; font-family: 'Space Grotesk', sans-serif; font-size: 30px; font-weight: 700; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 12px; }
.brand-panel p { position: relative; font-size: 15px; color: rgba(255,255,255,.7); line-height: 1.6; max-width: 360px; margin: 0; }
.brand-panel .addr { position: relative; font-size: 12.5px; color: rgba(255,255,255,.5); font-family: 'IBM Plex Mono', monospace; }
.signin-pane { flex: 1 1 0; display: flex; align-items: center; justify-content: center; padding: 48px 44px; background: var(--bg); }
.signin { width: 100%; max-width: 380px; }
.signin-logo { max-width: 240px; height: auto; display: block; margin: 0 0 22px; }
.signin h1 { font-family: 'Space Grotesk', sans-serif; font-size: 24px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.02em; }
.signin .sub { font-size: 14px; color: var(--ink-2); margin: 0 0 22px; }
.notice { margin-top: 20px; padding: 11px 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }
.notice strong { color: var(--ink-2); }

/* mobile FAB */
.fab { position: fixed; right: 18px; bottom: 24px; z-index: 60; width: 56px; height: 56px; border-radius: 18px; background: var(--red); color: #fff; border: none; box-shadow: 0 8px 24px rgba(218,31,38,.4); display: grid; place-items: center; cursor: pointer; }
.fab svg { width: 26px; height: 26px; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .sidebar { display: none; }
  .admin-main { padding: 16px 16px 88px; }
  .container { padding: 18px 16px 90px; }
  .client-header .inner { padding: 12px 16px; }
  .grid2 { grid-template-columns: 1fr; }
  .detail-grid, .detail-grid.client { grid-template-columns: 1fr; }
  .rail { position: static; }
  .login { flex-direction: column; }
  .brand-panel { padding: 30px 24px 26px; }
  .brand-panel h2, .brand-panel p { display: none; }
  .signin-pane { padding: 28px 20px 40px; }
  .hide-mobile { display: none !important; }
  dialog.sheet { max-width: 100%; margin: auto auto 0; border-radius: 20px 20px 0 0; }
}
.admin-topbar { display: none; }
.admin-bottomnav { display: none; }
@media (max-width: 760px) {
  .admin-topbar { display: flex; position: sticky; top: 0; z-index: 50; background: var(--ink); color: #fff; padding: 12px 16px; align-items: center; gap: 10px; }
  .admin-topbar .word { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 16px; }
  .admin-topbar .so { margin-left: auto; background: rgba(255,255,255,.1); border: none; border-radius: 9px; width: 36px; height: 36px; display: grid; place-items: center; color: #fff; cursor: pointer; }
  .admin-bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px 10px; }
  .admin-bottomnav a { flex: 1; display: grid; justify-items: center; gap: 3px; padding: 6px 0; color: var(--ink-3); font-size: 11px; font-weight: 600; position: relative; }
  .admin-bottomnav a.active { color: var(--red); }
}
@media (min-width: 761px) { .only-mobile { display: none !important; } }
