:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #1f2937;
  --muted: #64748b;
  --line: #dbe3ef;
  --brand: #1d4ed8;
  --brand-dark: #163b8f;
  --good: #0f766e;
  --danger: #b91c1c;
  --shadow: 0 16px 40px rgba(15, 23, 42, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: var(--brand);
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #172033;
  color: #fff;
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: #38bdf8;
  color: #082f49;
  border-radius: 8px;
  font-weight: 800;
}

.brand-title {
  font-weight: 800;
}

.brand-subtitle {
  color: #b6c3d7;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav a {
  color: #cbd5e1;
  padding: 10px 12px;
  border-radius: 8px;
}

.nav a:hover,
.nav a.active {
  background: rgba(255, 255, 255, .09);
  color: #fff;
}

.main {
  min-width: 0;
  padding: 24px;
}

.app-shell.embedded {
  display: block;
  min-height: 100vh;
}

.app-shell.embedded .main {
  padding: 20px;
}

.placement-head h1 {
  font-size: 24px;
}

.placement-metrics {
  grid-template-columns: .7fr 1fr 1fr;
}

.placement-split {
  grid-template-columns: minmax(0, 1fr) 300px;
}

.estimate-workspace {
  display: grid;
  gap: 14px;
}

.estimate-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.estimate-toolbar h1 {
  margin-bottom: 4px;
  font-size: 28px;
}

.back-link {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.estimate-summary-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.estimate-summary-bar > div {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.estimate-summary-bar > div:last-child {
  border-right: 0;
}

.estimate-summary-bar span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.estimate-summary-bar strong {
  font-size: 22px;
}

.estimate-summary-bar .total {
  background: #e0f2fe;
}

.estimate-sheet-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.sheet-head h2 {
  margin-bottom: 0;
}

.sheet-scroll {
  overflow-x: auto;
}

.estimate-sheet {
  min-width: 1180px;
}

.estimate-sheet th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
}

.estimate-sheet .col-section {
  width: 160px;
}

.estimate-sheet .col-type {
  width: 130px;
}

.estimate-sheet .col-title {
  width: 320px;
}

.estimate-sheet .col-unit {
  width: 86px;
}

.estimate-sheet .col-qty,
.estimate-sheet .col-price,
.estimate-sheet .col-percent {
  width: 120px;
}

.estimate-sheet .col-money {
  width: 130px;
}

.estimate-sheet .col-action {
  width: 106px;
}

.estimate-sheet .num {
  text-align: right;
  white-space: nowrap;
}

.estimate-sheet .strong {
  font-weight: 800;
}

.sheet-section-row td {
  background: #eef6ff;
  color: #1f2937;
  font-weight: 800;
}

.sheet-empty-row td {
  color: var(--muted);
}

.sheet-add-row td {
  background: #fbfdff;
  vertical-align: middle;
}

.sheet-add-row input,
.sheet-add-row select {
  min-height: 34px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.sheet-add-row button {
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.sheet-add-label {
  color: var(--muted);
  font-size: 12px;
}

.section-inline-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 28px;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

p,
.muted {
  color: var(--muted);
}

.panel,
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 16px;
}

.metric span,
.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: 22px;
}

.metric.accent {
  background: #e0f2fe;
  border-color: #bae6fd;
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.button:hover,
button:hover {
  background: var(--brand-dark);
  color: #fff;
}

.button.ghost {
  background: var(--surface);
  color: var(--brand);
}

.button.ghost:hover {
  background: #eff6ff;
  color: var(--brand);
}

.icon-danger {
  min-height: 30px;
  padding: 5px 8px;
  border-color: #fecaca;
  background: #fff;
  color: var(--danger);
  font-size: 12px;
}

.icon-danger:hover {
  background: #fef2f2;
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 650;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid .wide,
.form-actions {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 180px auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.quick-create {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  background: #f0f9ff;
}

.stack-form {
  display: grid;
  gap: 12px;
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

.side-panel {
  align-self: start;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-weight: 700;
}

.notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  background: #f0fdf4;
  color: #166534;
}

.notice-error {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
}

.empty {
  padding: 22px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: var(--surface-soft);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.status-grid > div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.deal-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-block {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.section-block:first-of-type {
  padding-top: 0;
  border-top: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric-grid,
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split,
  .form-grid,
  .filters,
  .quick-create {
    grid-template-columns: 1fr;
  }

  .deal-panel {
    display: grid;
  }

  .placement-metrics,
  .placement-split,
  .estimate-summary-bar,
  .section-inline-form {
    grid-template-columns: 1fr;
  }

  .estimate-summary-bar > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .estimate-summary-bar > div:last-child {
    border-bottom: 0;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 16px;
  }

  .page-head {
    display: grid;
  }

  .metric-grid,
  .status-grid,
  .mini-grid,
  .nav {
    grid-template-columns: 1fr;
  }
}
