:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f0f2f5;
  --surface-strong: #e7eaee;
  --ink: #17191d;
  --muted: #69707a;
  --subtle: #9299a3;
  --line: #dfe3e8;
  --line-strong: #cbd1d8;
  --accent: #2166d1;
  --accent-soft: #e9f1ff;
  --green: #157a55;
  --green-soft: #e8f6ef;
  --amber: #9a5b09;
  --amber-soft: #fff4df;
  --red: #ba3b3b;
  --red-soft: #fdecec;
  --violet: #6950b8;
  --violet-soft: #f0edfb;
  --shadow: 0 14px 40px rgba(25, 32, 45, 0.12);
  --sidebar: 228px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  position: fixed;
  inset: 0 auto 0 0;
  padding: 20px 14px;
  background: #eef0f3;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 24px; }
.brand strong { display: block; font-size: 14px; }
.brand span { display: block; color: var(--muted); font-size: 11px; margin-top: 1px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  background: #17191d;
  font-weight: 700;
  font-size: 13px;
}
.brand-mark.small { width: 34px; height: 34px; font-size: 10px; }
nav { display: grid; gap: 4px; }
.nav-item {
  border: 0;
  background: transparent;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #505761;
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.65); color: var(--ink); }
.nav-item.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(25,32,45,.05); }
.nav-item svg { width: 17px; height: 17px; stroke-width: 1.8; }
.nav-count { margin-left: auto; min-width: 19px; height: 19px; border-radius: 10px; padding: 0 5px; display: grid; place-items: center; background: var(--red-soft); color: var(--red); font-size: 11px; }
.sidebar-footer { margin-top: auto; }

.main-shell { margin-left: var(--sidebar); min-height: 100vh; }
.topbar {
  min-height: 78px;
  padding: 17px 30px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: rgba(245,246,248,.92);
  position: sticky;
  top: 0;
  z-index: 15;
  backdrop-filter: blur(14px);
}
.topbar h1 { margin: 0; font-size: 20px; line-height: 1.2; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }
.view { padding: 24px 30px 50px; max-width: 1540px; margin: 0 auto; }

.primary-button, .secondary-button, .danger-button, .search-button, .icon-button, .text-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.primary-button { background: var(--ink); color: #fff; padding: 0 13px; }
.primary-button:hover { background: #2b2f35; }
.primary-button svg, .secondary-button svg, .search-button svg { width: 15px; height: 15px; }
.secondary-button { background: var(--surface); border-color: var(--line); padding: 0 12px; }
.secondary-button:hover { border-color: var(--line-strong); background: #fafafa; }
.danger-button { background: var(--red-soft); color: var(--red); padding: 0 12px; }
.search-button { min-width: 178px; justify-content: flex-start; padding: 0 10px; background: var(--surface); border-color: var(--line); color: var(--muted); }
.search-button kbd { margin-left: auto; border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; background: var(--surface-soft); font-size: 10px; color: var(--subtle); }
.icon-button { width: 34px; padding: 0; background: transparent; border-color: var(--line); }
.icon-button:hover { background: var(--surface-soft); }
.icon-button svg { width: 16px; height: 16px; }
.text-button { border: 0; background: transparent; color: var(--accent); padding: 0; min-height: auto; }
.full { width: 100%; }

.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 0 0 13px; }
.section-head h2 { font-size: 14px; margin: 0; }
.section-head p { color: var(--muted); margin: 3px 0 0; font-size: 12px; }
.section-actions { display: flex; gap: 8px; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 18px; }
.stack { display: grid; gap: 18px; align-content: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.panel-body { padding: 16px; }
.panel-head { min-height: 46px; padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { font-size: 13px; margin: 0; }
.panel-head span { font-size: 11px; color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px; margin-bottom: 18px; }
.metric { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 13px 14px; min-height: 82px; }
.metric .label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 10px; }
.metric strong { display: block; font-size: 24px; line-height: 1; }
.metric small { display: block; color: var(--subtle); font-size: 10px; margin-top: 6px; }
.metric.alert strong { color: var(--red); }

.focus-list, .task-list { display: grid; }
.focus-row, .task-row { min-height: 52px; display: grid; grid-template-columns: 24px minmax(0,1fr) auto; gap: 9px; align-items: center; padding: 8px 13px; border-bottom: 1px solid var(--line); }
.focus-row:last-child, .task-row:last-child { border-bottom: 0; }
.task-check { width: 18px; height: 18px; appearance: none; border: 1.5px solid var(--line-strong); border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.task-check:checked { background: var(--green); border-color: var(--green); }
.task-check:checked::after { content: ""; width: 7px; height: 4px; border-left: 1.5px solid #fff; border-bottom: 1.5px solid #fff; transform: rotate(-45deg) translateY(-1px); }
.row-main { min-width: 0; }
.row-main strong { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 11px; color: var(--muted); text-align: right; }
.row-meta.overdue { color: var(--red); font-weight: 600; }

.pipeline-bars { display: grid; grid-template-columns: repeat(8, minmax(70px,1fr)); gap: 5px; padding: 14px; overflow-x: auto; }
.stage-bar { min-width: 72px; }
.stage-bar .bar { height: 5px; background: var(--surface-strong); border-radius: 3px; overflow: hidden; margin-bottom: 9px; }
.stage-bar .bar span { display: block; height: 100%; background: var(--accent); }
.stage-bar strong { font-size: 16px; }
.stage-bar small { display: block; color: var(--muted); font-size: 10px; line-height: 1.2; margin-top: 2px; max-width: 84px; white-space: normal; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.contact-toolbar { gap: 6px; }
.contact-toolbar .input-shell { min-width: 180px; }
.contact-toolbar .filter-select { max-width: 175px; }
.input-shell { min-height: 34px; min-width: 220px; display: flex; align-items: center; gap: 7px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 0 9px; }
.input-shell svg { width: 15px; color: var(--muted); }
.input-shell input { width: 100%; border: 0; outline: 0; background: transparent; }
.filter-select { min-height: 34px; padding: 0 28px 0 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: #505761; }
.segmented { display: inline-flex; padding: 3px; background: var(--surface-strong); border-radius: 7px; gap: 2px; }
.segmented button { border: 0; background: transparent; min-height: 28px; padding: 0 10px; border-radius: 5px; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(25,32,45,.08); }

.table-wrap { overflow: auto; max-height: calc(100vh - 220px); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1040px; }
.contact-table { min-width: 1900px; }
.data-table th { position: sticky; top: 0; z-index: 3; background: #f7f8fa; color: var(--muted); font-size: 10.5px; font-weight: 600; text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
.data-table td { min-height: 44px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 12px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover td { background: #fafbfc; }
.cell-title { font-weight: 600; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-state { padding: 50px 20px; text-align: center; color: var(--muted); }
.empty-state svg { width: 24px; height: 24px; margin-bottom: 10px; }

.pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 7px; border-radius: 11px; font-size: 10.5px; white-space: nowrap; background: var(--surface-soft); color: #565d67; }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.violet { background: var(--violet-soft); color: var(--violet); }
.priority-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 5px; background: var(--subtle); }
.priority-dot.high { background: var(--red); }
.priority-dot.medium { background: var(--amber); }
.priority-dot.low { background: var(--green); }

.tasks-layout { display: grid; grid-template-columns: minmax(0,1.6fr) minmax(280px,.6fr); gap: 18px; }
.task-section + .task-section { margin-top: 18px; }
.task-section h2 { font-size: 12px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; }
.task-row.done .row-main { text-decoration: line-through; color: var(--subtle); }
.task-summary { padding: 14px; display: grid; gap: 13px; }
.summary-line { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.summary-line strong { font-size: 16px; }

.materials-layout { display: grid; grid-template-columns: 220px minmax(0,1fr); gap: 18px; }
.materials-filter { padding: 12px; position: sticky; top: 102px; align-self: start; }
.materials-filter h3 { margin: 4px 7px 8px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.materials-filter button { width: 100%; min-height: 33px; padding: 0 8px; border: 0; background: transparent; border-radius: 5px; text-align: left; color: var(--muted); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.materials-filter button:hover, .materials-filter button.active { background: var(--surface-soft); color: var(--ink); }
.material-list { display: grid; gap: 8px; }
.material-row { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 13px 14px; cursor: pointer; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; }
.material-row:hover { border-color: var(--line-strong); }
.material-row h3 { margin: 0 0 4px; font-size: 13px; }
.material-row p { margin: 0; color: var(--muted); font-size: 11.5px; }
.material-tags { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px; }
.material-detail-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.material-detail-actions > div { display: flex; flex-wrap: wrap; gap: 5px; }
.material-detail .summary { color: var(--muted); margin: 0 0 18px; }
.template-box { white-space: pre-wrap; font-family: inherit; line-height: 1.55; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 6px; padding: 14px; font-size: 12.5px; }
.checklist { display: grid; gap: 8px; padding: 0; list-style: none; }
.checklist li { display: flex; gap: 9px; line-height: 1.45; }
.checklist li::before { content: ""; width: 15px; height: 15px; margin-top: 2px; flex: 0 0 15px; border: 1px solid var(--line-strong); border-radius: 4px; }
.tip-list { display: grid; gap: 7px; padding: 0; list-style: none; }
.tip-list li { border-left: 2px solid var(--amber); padding-left: 9px; color: #555c66; line-height: 1.4; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(20,24,30,.42); backdrop-filter: blur(4px); display: flex; justify-content: flex-end; }
.modal-panel { width: min(620px, 100%); height: 100%; background: var(--surface); box-shadow: var(--shadow); overflow: auto; }
.modal-header { min-height: 74px; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(255,255,255,.95); backdrop-filter: blur(12px); z-index: 3; }
.modal-header p { margin: 0 0 4px; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-content { padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 13px; }
.form-field { display: grid; gap: 5px; min-width: 0; }
.form-field.wide { grid-column: 1 / -1; }
.form-field label { font-size: 11px; color: var(--muted); }
.form-field input, .form-field select, .form-field textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px 9px; outline: 0; background: #fff; color: var(--ink); }
.form-field input, .form-field select { min-height: 36px; }
.form-field textarea { min-height: 84px; resize: vertical; line-height: 1.4; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: #90b4eb; box-shadow: 0 0 0 3px var(--accent-soft); }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-actions > div { display: flex; gap: 8px; }
.score-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 10px; grid-column: 1/-1; padding: 12px; background: var(--surface-soft); border-radius: 6px; }
.score-head { grid-column: 1/-1; display: flex; justify-content: space-between; align-items: center; }
.score-head h3 { margin: 0; font-size: 12px; }
.score-head strong { color: var(--accent); }
.form-error { color: var(--red); min-height: 17px; font-size: 11px; }
.query-error { color: var(--red); background: var(--red-soft); border: 1px solid #f3cccc; border-radius: 6px; padding: 8px 10px; margin: -4px 0 10px; font-size: 11px; }

.command-panel { width: min(640px, calc(100% - 30px)); max-height: min(620px, calc(100vh - 80px)); margin: 40px auto auto; background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.command-input { min-height: 54px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.command-input svg { width: 18px; color: var(--muted); }
.command-input input { border: 0; outline: 0; width: 100%; font-size: 15px; }
.command-results { max-height: 540px; overflow: auto; padding: 7px; }
.command-result { width: 100%; min-height: 48px; border: 0; background: transparent; border-radius: 6px; padding: 7px 9px; display: flex; justify-content: space-between; align-items: center; text-align: left; cursor: pointer; }
.command-result:hover { background: var(--surface-soft); }
.command-result strong { display: block; font-size: 12px; }
.command-result span { display: block; margin-top: 2px; color: var(--muted); font-size: 10.5px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg); }
.login-panel { width: min(340px, 100%); }
.login-panel .brand-mark { margin-bottom: 22px; }
.login-panel h1 { margin: 0; font-size: 24px; }
.login-panel > p { margin: 5px 0 28px; color: var(--muted); }
.login-panel form { display: grid; gap: 9px; }
.login-panel label { color: var(--muted); font-size: 11px; }
.password-row { display: grid; grid-template-columns: minmax(0,1fr) 34px; gap: 6px; }
.password-row input { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; outline: 0; }
.password-row input:focus { border-color: #90b4eb; box-shadow: 0 0 0 3px var(--accent-soft); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 200; padding: 10px 13px; border-radius: 6px; background: #1f2328; color: #fff; font-size: 12px; box-shadow: var(--shadow); }
.settings-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.settings-card { padding: 16px; }
.settings-card h2 { font-size: 13px; margin: 0 0 5px; }
.settings-card p { font-size: 11.5px; line-height: 1.45; color: var(--muted); margin: 0 0 16px; }
.mobile-nav { display: none; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3,1fr); }
  .dashboard-grid, .tasks-layout { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  :root { --sidebar: 0px; }
  .sidebar { display: none; }
  .main-shell { margin-left: 0; padding-bottom: 66px; }
  .topbar { min-height: 68px; padding: 13px 16px; }
  .topbar h1 { font-size: 18px; }
  .view { padding: 16px; }
  .search-button { width: 34px; min-width: 34px; padding: 0; justify-content: center; }
  .search-button span, .search-button kbd, .primary-button span { display: none; }
  .topbar .primary-button { width: 34px; padding: 0; }
  .mobile-nav { position: fixed; inset: auto 0 0; z-index: 40; height: 62px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); backdrop-filter: blur(14px); display: grid; grid-template-columns: repeat(5,1fr); }
  .mobile-nav button { border: 0; background: transparent; color: var(--muted); display: grid; justify-items: center; align-content: center; gap: 3px; font-size: 9px; }
  .mobile-nav button.active { color: var(--accent); }
  .mobile-nav svg { width: 18px; height: 18px; }
  .materials-layout { grid-template-columns: 1fr; }
  .materials-filter { position: static; display: flex; overflow-x: auto; gap: 5px; padding: 7px; }
  .materials-filter h3 { display: none; }
  .materials-filter button { width: auto; flex: 0 0 auto; overflow: visible; text-overflow: clip; white-space: nowrap; padding: 0 10px; }
  .modal-panel { width: 100%; }
}

@media (max-width: 560px) {
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .metric { min-height: 74px; }
  .metric strong { font-size: 21px; }
  .form-grid, .settings-grid { grid-template-columns: 1fr; }
  .form-field.wide, .score-grid { grid-column: auto; }
  .score-grid { grid-template-columns: 1fr; }
  .score-head { grid-column: auto; }
  .toolbar .input-shell { min-width: 100%; order: -1; }
  .material-row { grid-template-columns: 1fr; }
  .material-tags { justify-content: flex-start; }
}
