:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #64717f;
  --line: #dce3ea;
  --paper: #ffffff;
  --wash: #f3f7f8;
  --accent: #176d6b;
  --accent-strong: #10514f;
  --gold: #a87318;
  --danger: #b3261e;
  --shadow: 0 18px 45px rgba(23, 32, 42, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--wash);
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

button:hover {
  background: var(--accent-strong);
}

button.ghost {
  color: var(--ink);
  background: #e8eef1;
}

button.danger {
  background: var(--danger);
}

button.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  font-size: 26px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

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

.eyebrow {
  margin-bottom: 6px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.9)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='560' viewBox='0 0 900 560'%3E%3Crect width='900' height='560' fill='%23f3f7f8'/%3E%3Cpath d='M90 420h720M150 340h600M210 260h480' stroke='%23d7e3e6' stroke-width='28'/%3E%3Ccircle cx='230' cy='165' r='76' fill='%23176d6b' opacity='.22'/%3E%3Crect x='370' y='110' width='270' height='120' rx='12' fill='%23ffffff' stroke='%23dce3ea'/%3E%3Cpath d='M405 150h190M405 185h120' stroke='%2317202a' stroke-width='14' opacity='.42'/%3E%3C/svg%3E");
  background-size: cover;
}

.login-panel {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 28px;
  font-size: clamp(2rem, 5vw, 3.1rem);
}

.stack {
  display: grid;
  gap: 16px;
}

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

.topbar {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.topbar h1 {
  margin-bottom: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
}

.tab-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
}

.tab-button:hover,
.tab-button.active {
  color: #fff;
  background: var(--accent);
}

#userBadge {
  color: var(--muted);
  font-weight: 700;
}

.workspace {
  height: calc(100vh - 92px);
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.project-list {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  overflow: auto;
}

.list-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.list-header h2 {
  margin-bottom: 0;
}

.projects {
  display: grid;
}

.project-item {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 98px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 16px 20px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.project-item:hover,
.project-item.active {
  background: #edf6f5;
}

.project-item strong {
  font-size: 1rem;
}

.project-item span {
  color: var(--muted);
}

.project-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.empty-state,
.detail {
  overflow: auto;
  padding: 28px;
}

.empty-state {
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.empty-state p {
  max-width: 520px;
  color: var(--muted);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.detail-header h2 {
  margin-bottom: 6px;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

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

.detail-actions {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.summary-grid article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.summary-grid span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.summary-grid strong {
  font-size: 1.25rem;
}

.fact-box {
  margin-bottom: 24px;
  padding: 20px;
  border-left: 5px solid var(--accent);
  background: #fff;
}

.fact-box p {
  margin-bottom: 0;
  color: #2c3b45;
  line-height: 1.6;
  white-space: pre-wrap;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.preview-grid article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.preview-grid span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.preview-grid strong {
  overflow-wrap: anywhere;
}

.cost-box {
  border-left-color: var(--gold);
}

.timeline {
  display: grid;
  gap: 10px;
}

.dashboard {
  min-height: calc(100vh - 92px);
  padding: 28px;
  overflow: auto;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.dashboard-header h2 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.dashboard-header p {
  color: var(--muted);
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.analytics-list,
.profit-table {
  display: grid;
  gap: 10px;
}

.analytics-row,
.profit-row {
  display: grid;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.analytics-row {
  grid-template-columns: 1.1fr 1fr 150px;
}

.analytics-row div,
.profit-row {
  min-width: 0;
}

.analytics-row span,
.profit-row span {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.profit-row {
  grid-template-columns: 110px 1.2fr 1.2fr 140px 140px 140px;
}

.payment-row {
  display: grid;
  grid-template-columns: 130px 1fr 130px 110px 1fr 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.payment-row strong,
.payment-row span {
  overflow-wrap: anywhere;
}

.status {
  display: inline-flex;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.status.paid {
  color: #125538;
  background: #dff4e9;
}

.status.pending {
  color: #7a5010;
  background: #fff1cf;
}

dialog {
  width: min(980px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(23, 32, 42, 0.52);
}

.project-form {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.modal-header,
.modal-footer,
.installments-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2,
.installments-header legend {
  margin: 0;
}

fieldset {
  display: grid;
  gap: 14px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

legend {
  padding: 0 8px;
  font-weight: 800;
}

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

.installments-editor {
  display: grid;
  gap: 10px;
}

.installment-count {
  max-width: 320px;
}

.installment-edit-row {
  display: grid;
  grid-template-columns: 70px 1fr 1fr 1fr 1fr 42px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.autosave-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

@media (max-width: 900px) {
  .topbar,
  .detail-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .detail-actions {
    flex-wrap: wrap;
  }

  .workspace {
    height: auto;
    grid-template-columns: 1fr;
  }

  .project-list {
    max-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-grid,
  .form-grid,
  .preview-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .payment-row,
  .analytics-row,
  .profit-row {
    grid-template-columns: 1fr;
  }

  .installment-edit-row {
    grid-template-columns: 1fr;
  }
}
