:root {
  --navy: #0b3158;
  --navy-soft: #153f68;
  --blue-soft: #eaf2f8;
  --green: #7cb342;
  --green-soft: #eef7e8;
  --paper: #fbfcfd;
  --line: #d8e2ea;
  --text: #1f2933;
  --muted: #5f6f7b;
  --danger: #b42318;
  --shadow: 0 18px 55px rgba(11, 49, 88, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #edf3f7;
  color: var(--text);
  font-family: Aptos, "Segoe UI", Arial, sans-serif;
}

body.is-locked .app-shell {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

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

button,
.file-button {
  border: 0;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  padding: 11px 14px;
  text-align: center;
}

button.secondary {
  background: var(--blue-soft);
  color: var(--navy);
}

button.doc-tab.active {
  background: var(--green);
  color: #fff;
}

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

button.inline-action {
  background: var(--green-soft);
  color: #376315;
  padding: 8px 12px;
}

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

textarea {
  min-height: 72px;
  resize: vertical;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.78rem;
  font-weight: 800;
  gap: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

label input,
label textarea,
label select {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
}

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

.control-panel {
  background: #fff;
  border-right: 1px solid var(--line);
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  position: sticky;
  top: 0;
}

.panel-header {
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
  padding-bottom: 20px;
}

.panel-header h1 {
  color: var(--navy);
  font-size: 1.8rem;
  line-height: 1.1;
  margin: 0 0 8px;
}

.panel-header p,
.hint {
  color: var(--muted);
  margin: 0;
}

.eyebrow {
  color: var(--green) !important;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  margin-bottom: 6px !important;
  text-transform: uppercase;
}

.panel-section {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
}

.panel-section h2 {
  color: var(--navy);
  font-size: 0.95rem;
  margin: 0;
}

.button-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.checkbox-line {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 8px;
  letter-spacing: 0;
  text-transform: none;
}

.checkbox-line input {
  width: auto;
}

.user-strip {
  align-items: center;
  background: var(--blue-soft);
  border-radius: 12px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-top: 16px;
  padding: 10px;
}

.user-strip span {
  color: var(--navy);
  font-size: 0.85rem;
  font-weight: 800;
}

.user-strip button {
  padding: 7px 10px;
}

.workspace {
  overflow-x: auto;
  padding: 32px;
}

.invoice-page {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  max-width: 1020px;
  overflow: hidden;
}

.invoice-hero {
  align-items: stretch;
  background: linear-gradient(135deg, var(--navy), #092744);
  color: #fff;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(0, 1fr) 300px;
  padding: 38px;
}

.document-label {
  color: #ddebff;
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  margin: 0 0 10px;
}

.invoice-hero h1 {
  font-size: 2rem;
  margin: 0 0 8px;
}

.invoice-hero p {
  color: #dce9f4;
  margin: 0;
}

.invoice-status-card {
  align-content: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  display: grid;
  gap: 12px;
  padding: 18px;
}

.invoice-status-card label {
  color: #dce9f4;
}

.invoice-meta-grid {
  background: var(--paper);
  display: grid;
  gap: 1px;
  grid-template-columns: repeat(4, 1fr);
  padding: 1px;
}

.invoice-meta-grid label {
  background: #fff;
  padding: 15px;
}

.party-grid,
.payment-grid,
.totals-section {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr 1.3fr;
  padding: 24px 32px;
}

.company-box,
.client-box,
.notes-card,
.totals-card,
.payment-grid > div {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}

.company-box h2,
.client-box h2,
.section-block h2,
.notes-card h2,
.payment-grid h2 {
  color: var(--navy);
  font-size: 1.14rem;
  margin: 0 0 12px;
}

.company-box p {
  margin: 0 0 8px;
}

.two-col {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.client-box {
  display: grid;
  gap: 12px;
}

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

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

.section-heading-row p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-x: auto;
}

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

th {
  background: var(--navy);
  color: #fff;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  padding: 12px;
  text-align: left;
  text-transform: uppercase;
}

td {
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
}

tr:nth-child(even) td {
  background: #fff;
}

td input,
td textarea {
  background: transparent;
  border: 0;
  padding: 2px;
}

.invoice-table th:first-child,
.invoice-table td:first-child {
  width: 52px;
}

.invoice-table th:nth-child(3),
.invoice-table th:nth-child(4),
.invoice-table th:nth-child(5),
.invoice-table th:nth-child(6) {
  width: 120px;
}

.line-total {
  color: var(--navy);
  font-weight: 900;
}

.totals-section {
  border-top: 1px solid var(--line);
  grid-template-columns: 1fr 360px;
}

.totals-card {
  display: grid;
  gap: 12px;
}

.totals-card div {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding-bottom: 10px;
}

.totals-card span {
  color: var(--muted);
}

.totals-card strong {
  color: var(--navy);
}

.totals-card .grand-total {
  background: var(--green-soft);
  border: 0;
  border-radius: 12px;
  margin-top: 4px;
  padding: 14px;
}

.grand-total strong {
  font-size: 1.35rem;
}

#amountWords {
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
  margin: 0;
}

.payment-grid {
  border-top: 1px solid var(--line);
}

.payment-grid textarea {
  background: transparent;
  border: 0;
  line-height: 1.55;
  min-height: 130px;
  padding: 0;
}

.signature-box {
  align-content: end;
}

.signature-line {
  border-bottom: 1px solid var(--navy);
  height: 92px;
  margin-bottom: 14px;
}

.proposal-document[hidden] {
  display: none;
}

.list-editor {
  display: grid;
  gap: 9px;
}

.list-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.list-row input {
  background: var(--paper);
}

.list-row button {
  border-radius: 999px;
  font-size: 0.78rem;
  padding: 5px 8px;
}

.auth-screen,
.modal-backdrop {
  align-items: center;
  background: rgba(8, 30, 52, 0.72);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 24px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 20;
}

.auth-screen[hidden],
.modal-backdrop[hidden] {
  display: none;
}

.auth-card,
.modal-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 540px;
  padding: 28px;
  width: 100%;
}

.modal-card {
  max-height: 88vh;
  max-width: 760px;
  overflow: auto;
}

.auth-card h1,
.modal-card h2 {
  color: var(--navy);
  margin: 0;
}

.auth-card p,
.modal-card p,
.status-message {
  color: var(--muted);
  margin: 0;
}

.status-message {
  font-size: 0.86rem;
  min-height: 1.2em;
}

.status-message.error {
  color: var(--danger);
}

.status-message.success {
  color: #376315;
}

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

.ai-preview {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  max-height: 260px;
  overflow: auto;
  padding: 14px;
  white-space: pre-wrap;
}

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

  .control-panel {
    height: auto;
    position: static;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 14px;
  }

  .invoice-hero,
  .invoice-meta-grid,
  .party-grid,
  .payment-grid,
  .totals-section,
  .two-col {
    grid-template-columns: 1fr;
  }

  .invoice-hero,
  .section-block,
  .party-grid,
  .payment-grid,
  .totals-section {
    padding: 22px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }

  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #edf3f7 !important;
  }

  .control-panel,
  .auth-screen,
  .modal-backdrop,
  .screen-only,
  button,
  .inline-action,
  .file-button {
    display: none !important;
  }

  .app-shell {
    display: block;
    min-height: 0;
  }

  body.print-final #proposalForm,
  body.print-proforma #proposalForm,
  body.print-proposal #invoiceForm {
    display: none !important;
  }

  .workspace {
    overflow: visible;
    padding: 0;
  }

  .invoice-page {
    border-radius: 20px;
    box-shadow: var(--shadow);
    margin: 0 auto;
    max-width: 1020px;
    overflow: hidden;
    width: 100%;
  }

  input,
  textarea,
  select {
    appearance: none;
    -webkit-appearance: none;
    border-color: transparent !important;
    box-shadow: none !important;
    color: inherit !important;
    overflow: hidden;
    resize: none;
  }

  .table-wrap {
    overflow: visible;
  }

  tr,
  .company-box,
  .client-box,
  .notes-card,
  .totals-card,
  .payment-grid > div,
  .section-block,
  .party-grid,
  .totals-section,
  .payment-grid {
    break-inside: avoid;
  }
}
