:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --ink: #16201f;
  --muted: #61716f;
  --line: #d8e0de;
  --accent: #176f6b;
  --accent-2: #255c99;
  --good: #1d7a4f;
  --warn: #ad6b00;
  --bad: #b83a3a;
  --shadow: 0 18px 44px rgba(25, 38, 35, 0.08);
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.app-view {
  display: none;
}

body[data-view="auth"] #authView {
  display: flex;
}

body[data-view="list"] #appTopbar,
body[data-view="detail"] #appTopbar {
  display: flex;
}

body[data-view="list"] #projectListView,
body[data-view="detail"] #estimateView {
  display: block;
}

body[data-view="list"] .detail-only {
  display: none !important;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
  overflow-wrap: anywhere;
}

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

.auth-view {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 430px;
  padding: 28px;
  width: 100%;
}

.auth-brand {
  margin-bottom: 22px;
}

.auth-tabs {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 18px;
  padding: 4px;
}

.auth-tab {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  min-height: 38px;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(25, 38, 35, 0.08);
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: grid;
  gap: 14px;
}

.full-button {
  width: 100%;
}

.checkbox-line {
  align-items: center;
  display: inline-flex;
  gap: 8px;
}

.checkbox-line input {
  min-height: auto;
  width: auto;
}

.checkbox-line span {
  margin: 0;
}

.form-message {
  color: var(--muted);
  min-height: 22px;
  margin: 14px 0 0;
}

.form-message[data-type="error"] {
  color: var(--bad);
}

.topbar {
  align-items: center;
  background: #182523;
  color: #ffffff;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px clamp(18px, 4vw, 48px);
}

.eyebrow {
  color: #6d837f;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: #a8c3be;
}

h1,
h2,
h3 {
  letter-spacing: 0;
  line-height: 1.2;
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 17px;
}

.topbar-actions,
.button-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.icon-button,
.primary-button,
.secondary-button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  gap: 7px;
  justify-content: center;
  min-height: 38px;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-button {
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  font-size: 15px;
  font-weight: 800;
  height: 40px;
  line-height: 1;
  min-width: 40px;
  padding: 0 10px;
}

.icon-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.icon-button.danger {
  color: #ffd2d2;
}

.icon-button.light {
  background: #eef3f2;
  color: var(--ink);
}

.icon-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.secondary-dark-button {
  align-items: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: #ffffff;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
}

.account-chip {
  align-items: center;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  color: #dcece9;
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  min-height: 34px;
  padding: 6px 12px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-button {
  position: relative;
}

.file-button input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.project-band,
.summary-band,
.workspace {
  padding-left: clamp(18px, 4vw, 48px);
  padding-right: clamp(18px, 4vw, 48px);
}

.project-band {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-bottom: 22px;
  padding-top: 22px;
}

.project-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 1.4fr) minmax(190px, 1fr) minmax(150px, 0.7fr) minmax(210px, 0.9fr) minmax(170px, 0.8fr);
}

label span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 7px;
}

input,
select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 38px;
  outline: none;
  padding: 8px 10px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(37, 92, 153, 0.14);
}

.summary-band {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  padding-bottom: 18px;
  padding-top: 18px;
}

.metric,
.profit-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 94px;
  padding: 16px;
}

.metric span,
.profit-block span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.metric strong,
.profit-block strong {
  display: block;
  font-size: 22px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric.emphasis strong,
.profit-block.result strong {
  color: var(--good);
}

.metric.loss strong,
.profit-block.loss strong {
  color: var(--bad);
}

.workspace {
  padding-bottom: 42px;
  padding-top: 24px;
}

.work-section {
  margin-bottom: 30px;
}

.section-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 14px;
}

.section-heading.compact {
  margin-top: 30px;
}

.rate-meta {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(180px, 260px));
  margin-bottom: 14px;
}

.project-editor {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.8fr) minmax(150px, 0.6fr) auto;
  margin-bottom: 16px;
  padding: 16px;
}

.project-editor[hidden] {
  display: none;
}

.editor-actions {
  align-self: end;
}

.primary-button,
.secondary-button {
  font-weight: 800;
  padding: 8px 14px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

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

.wide-table {
  min-width: 1380px;
}

.estimate-grid-table {
  min-width: 1740px;
}

.addon-table {
  min-width: 1320px;
}

.project-table {
  min-width: 1100px;
}

.project-list-wrap {
  margin-bottom: 16px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

th {
  background: var(--surface-2);
  color: #3f514e;
  font-size: 12px;
  font-weight: 800;
}

.group-row th,
.subhead-row th {
  text-align: center;
  white-space: nowrap;
}

.group-row th[colspan] {
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td .short {
  min-width: 72px;
}

td .number {
  min-width: 110px;
}

.amount-cell {
  color: var(--ink);
  font-weight: 800;
  min-width: 128px;
  text-align: right;
  white-space: nowrap;
}

.basis-combo {
  display: grid;
  gap: 6px 10px;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  min-width: 220px;
}

.basis-combo label {
  align-items: center;
  background: #f6f9f8;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  gap: 6px;
  min-height: 32px;
  padding: 5px 8px;
  white-space: nowrap;
}

.basis-combo input {
  min-height: auto;
  width: auto;
}

.basis-summary {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 6px 10px;
  justify-content: space-between;
  margin-top: 8px;
}

.basis-summary strong {
  color: var(--ink);
  font-weight: 800;
}

.amount-cell.positive {
  color: var(--good);
}

.amount-cell.negative {
  color: var(--bad);
}

.row-delete {
  background: #fff3f3;
  color: var(--bad);
  height: 34px;
  min-height: 34px;
  min-width: 34px;
}

.row-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
}

.profit-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  margin-bottom: 22px;
}

.breakdown {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.breakdown h3 {
  margin-bottom: 12px;
}

.breakdown-row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  min-height: 42px;
  padding: 8px 0;
}

.breakdown-row:first-child {
  border-top: 0;
}

.breakdown-row span {
  color: var(--muted);
}

.breakdown-row strong {
  text-align: right;
}

@media (max-width: 1080px) {
  .project-grid,
  .summary-band,
  .profit-grid,
  .rate-meta,
  .project-editor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .project-grid,
  .summary-band,
  .profit-grid,
  .rate-meta,
  .project-editor {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .button-row {
    justify-content: flex-start;
  }

  h1 {
    font-size: 24px;
  }
}

body[data-density="compact"] .topbar {
  align-items: stretch;
  flex-direction: column;
}

body[data-density="compact"] .topbar-actions {
  justify-content: flex-start;
}

@media (max-width: 900px) {
  .responsive-table {
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }

  .responsive-table table,
  .responsive-table thead,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table th,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table table {
    min-width: 0;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table tbody {
    display: grid;
    gap: 12px;
  }

  .responsive-table tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 10px;
  }

  .responsive-table td {
    align-items: center;
    border: 0;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(92px, 35%) minmax(0, 1fr);
    padding: 7px 4px;
    text-align: left;
  }

  .responsive-table td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.25;
  }

  .responsive-table td[data-label=""] {
    display: flex;
    justify-content: flex-end;
  }

  .responsive-table td[data-label=""]::before {
    content: none;
  }

  .responsive-table input,
  .responsive-table select,
  .responsive-table td .number,
  .responsive-table td .short {
    min-width: 0;
    width: 100%;
  }

  .responsive-table .amount-cell {
    min-width: 0;
    text-align: left;
    white-space: normal;
  }

  .basis-combo {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
  }

  .basis-combo label {
    white-space: normal;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar-actions,
  .section-heading button,
  .row-delete {
    display: none !important;
  }

  .work-section {
    margin-bottom: 28px;
  }

  .metric,
  .profit-block,
  .table-wrap,
  .breakdown {
    box-shadow: none;
  }
}
