:root {
  color-scheme: light;
  --bg: #eef4ff;
  --shell: #f5f7fb;
  --surface: #ffffff;
  --surface-alt: #f7faff;
  --border: #dfe9f5;
  --border-strong: #ccd9ef;
  --text: #122033;
  --muted: #5e7495;
  --primary: #1d64ff;
  --primary-soft: #eaf1ff;
  --primary-deep: #0f4ad8;
  --primary-ink: #0e2f81;
  --teal: #0ec7b7;
  --success: #1a9a73;
  --danger: #d25858;
  --shadow: 0 18px 50px rgba(15, 38, 77, 0.08);
  --shadow-soft: 0 10px 24px rgba(19, 36, 64, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(29, 100, 255, 0.10), transparent 28%),
    linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
  color: var(--text);
}

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

.app-shell {
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
  padding: 26px 32px 40px;
}

.workspace {
  width: 100%;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 26px;
  padding: 0 4px;
}

.topbar-breadcrumbs {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(29, 100, 255, 0.08);
  color: var(--muted);
  font-size: 0.96rem;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(20, 63, 120, 0.04);
}

.crumb-pill {
  background: var(--primary-soft);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--primary);
  font-weight: 700;
}

.crumb-separator {
  opacity: 0.5;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 30px;
  padding: 0 4px;
}

.workspace-kicker,
.surface-kicker {
  margin: 0 0 10px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: #2575ff;
  font-weight: 900;
}

.topbar h1,
.workspace-header h1 {
  margin: 0;
  letter-spacing: -0.06em;
}

.workspace-header h1 {
  font-size: clamp(2.4rem, 4vw, 4.4rem);
  line-height: 0.96;
  max-width: 700px;
}

.workspace-insights {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.insight-pill {
  min-width: 200px;
  padding: 18px 22px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(166, 188, 227, 0.7);
  box-shadow: 0 10px 24px rgba(39, 74, 130, 0.06);
}

.insight-label {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.insight-pill strong {
  font-size: 1.4rem;
  letter-spacing: -0.04em;
}

.topbar-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

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

.metric-card,
.surface {
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(174, 195, 231, 0.8);
  border-radius: 26px;
  box-shadow: 0 12px 28px rgba(36, 74, 128, 0.06);
}

.metric-card {
  position: relative;
  overflow: hidden;
  padding: 22px 22px 18px;
  border-left: 5px solid #1a7efb;
  min-height: 170px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(180deg, #3cc3cd 0%, #1d7efb 100%);
}

.metric-card p {
  margin: 0 0 12px;
  color: #5d738e;
  font-size: 1.08rem;
  letter-spacing: 0.01em;
}

.metric-card strong {
  display: block;
  margin-top: 0;
  font-size: clamp(2.1rem, 3.4vw, 3.1rem);
  letter-spacing: -0.05em;
  color: #101d2d;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(400px, 0.88fr);
  gap: 24px;
  align-items: start;
}

.editor-stack {
  display: grid;
  gap: 20px;
}

.surface {
  padding: 22px;
}

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

.surface-header h2,
.inner-panel h3 {
  margin: 0;
  letter-spacing: -0.02em;
}

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

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

.expense-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.expense-note-field {
  grid-column: auto;
}

.expense-form > button {
  justify-self: start;
}

.expense-month-field {
  min-width: 150px;
}

.expense-total {
  margin: 0 0 12px;
  font-size: 1.1rem;
  font-weight: 700;
}

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

.expense-table {
  min-width: 700px;
  table-layout: fixed;
}

.expense-description {
  max-width: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.time-plan-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
}

.time-plan-task {
  grid-column: span 2;
}

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

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

.inner-panel {
  padding: 18px;
  background: linear-gradient(180deg, #f9fbff 0%, #f3f7ff 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.inner-panel h3 {
  margin-bottom: 14px;
  font-size: 1.04rem;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.94rem;
}

label span {
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #bfd1ef;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 100, 255, 0.12);
}

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

.full-width {
  grid-column: 1 / -1;
}

.button,
.icon-button {
  border: none;
  cursor: pointer;
}

.button {
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%);
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.01em;
  box-shadow: 0 12px 24px rgba(29, 100, 255, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(29, 100, 255, 0.22);
  filter: saturate(1.08);
}

.button-secondary {
  background: linear-gradient(135deg, #edf4ff 0%, #e4eeff 100%);
  color: var(--primary);
  box-shadow: none;
}

.button-secondary:hover {
  background: linear-gradient(135deg, #e4eeff 0%, #dfeafc 100%);
}

.items-head {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) 100px 140px 140px 44px;
  gap: 12px;
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.items-editor {
  display: grid;
  gap: 12px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) 100px 140px 140px 44px;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: linear-gradient(180deg, #f9fbff 0%, #f4f8ff 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.item-row label {
  gap: 0;
}

.description-field input {
  font-weight: 600;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #fff0f0;
  color: var(--danger);
  font-size: 1.3rem;
  transition: background 0.15s ease, transform 0.15s ease;
}

.icon-button:hover {
  background: #ffe1e1;
  transform: scale(1.04);
}

.preview-column {
  position: sticky;
  top: 24px;
}

.preview-surface {
  padding: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f5f8ff 100%);
}

.preview-toolbar,
.preview-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-toolbar {
  padding: 6px 8px 16px;
  color: var(--muted);
}

.preview-status p,
.preview-hint {
  margin: 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(26, 154, 115, 0.12);
  color: var(--success);
  font-size: 0.76rem;
  font-weight: 800;
}

.document-preview {
  background: #ffffff;
  border: 1px solid #e8eef7;
  border-radius: 24px;
  padding: 32px;
  min-height: 920px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.document-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  padding-bottom: 18px;
  border-bottom: 1px solid #edf2fb;
}

.document-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.76rem;
}

.document-title {
  margin: 14px 0 6px;
  font-size: 2.1rem;
  letter-spacing: -0.04em;
}

.document-copy,
.document-meta p,
.document-card p,
.document-footer p {
  margin: 4px 0;
  color: var(--muted);
  line-height: 1.6;
}

.document-meta {
  min-width: 220px;
}

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

.document-card {
  padding: 18px;
  background: linear-gradient(180deg, #f7faff 0%, #f3f7ff 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.document-card h3,
.document-notes h3 {
  margin: 0 0 12px;
  font-size: 1.02rem;
}

.document-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 26px;
}

.document-table th,
.document-table td {
  padding: 14px 10px;
  border-bottom: 1px solid #edf2fb;
  text-align: left;
  vertical-align: top;
}

.document-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.document-table th:last-child,
.document-table td:last-child,
.numeric {
  text-align: right;
}

.line-subtitle {
  margin-top: 4px;
  font-size: 0.92rem;
  color: var(--muted);
}

.totals-panel {
  margin-left: auto;
  width: min(360px, 100%);
  display: grid;
  gap: 8px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  color: var(--muted);
}

.total-row.grand-total {
  border-bottom: none;
  padding-top: 16px;
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--text);
}

.document-notes {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid #edf2fb;
}

.document-footer {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1320px) {
  .summary-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .preview-column {
    position: static;
  }
}

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

  .sidebar {
    display: none;
  }
}

@media (max-width: 820px) {
  .workspace {
    padding: 6px 0;
  }

  .topbar,
  .workspace-header,
  .surface-header,
  .preview-toolbar,
  .preview-status,
  .document-header,
  .document-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .three-columns,
  .two-columns,
  .expense-form,
  .time-plan-form,
  .split-panels,
  .document-columns,
  .summary-cards {
    grid-template-columns: 1fr;
  }

  .expense-note-field {
    grid-column: auto;
  }

  .time-plan-task {
    grid-column: auto;
  }

  .items-head {
    display: none;
  }

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

  .document-preview {
    padding: 22px 18px;
  }
}

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

  .sidebar,
  .topbar,
  .summary-cards,
  .editor-column,
  .preview-toolbar {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .workspace-grid {
    display: block;
    padding: 0;
  }

  .surface,
  .preview-surface,
  .document-preview {
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    min-height: auto;
  }
}

.client-picker { display: flex; gap: 8px; margin-bottom: 12px; }
.client-picker select { flex: 1; min-width: 0; }
.history-status { margin: 0 0 8px; color: #5e7495; font-size: 0.9rem; }
.history-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #edf2fb; }
.history-item span { color: #5e7495; font-size: 0.9rem; }
.history-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.unpaid-actions { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
@media print { #historyPanel, .client-picker { display: none; } }

.login-page {
  min-height: 100vh;
  background: linear-gradient(90deg, rgba(12, 28, 31, 0.76), rgba(12, 28, 31, 0.34) 55%, rgba(12, 28, 31, 0.18)),
    url("/login-background.jpg") center / cover no-repeat fixed;
  color: #142321;
  font-family: "DM Sans", sans-serif;
}

.login-shell {
  width: min(100%, 1480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 88px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  align-items: center;
  gap: clamp(40px, 8vw, 120px);
}

.login-brand {
  max-width: 560px;
  color: #fff;
}

.login-mark {
  width: 50px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin-bottom: 52px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 14px;
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 1.8rem;
}

.login-overline,
.login-form-kicker {
  margin: 0 0 12px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.login-overline { color: #c0e5d9; }

.login-brand h1 {
  margin: 0;
  font-family: "DM Serif Display", Georgia, serif;
  font-size: clamp(3.4rem, 7vw, 6.8rem);
  font-weight: 400;
  line-height: 1;
}

.login-tagline {
  margin: 18px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 1.25rem;
}

.login-photo-credit {
  display: inline-block;
  margin-top: 34px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.75rem;
  text-decoration: none;
}

.login-photo-credit:hover { color: #fff; }

.login-card {
  width: 100%;
  display: grid;
  gap: 18px;
  padding: clamp(26px, 4vw, 42px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 28px 80px rgba(7, 22, 25, 0.24);
  backdrop-filter: blur(14px);
}

.login-card-heading { margin-bottom: 4px; }
.login-form-kicker { color: #387769; }
.login-card h2 { margin: 0; color: #142321; font-size: 1.8rem; }
.login-card label { gap: 7px; color: #4d625e; font-size: 0.9rem; }
.login-card label span { font-weight: 600; }
.login-card input { min-height: 48px; border-radius: 6px; border-color: #d2ddd8; }
.login-card input:focus { border-color: #26796b; box-shadow: 0 0 0 3px rgba(38, 121, 107, 0.14); }
.login-card .button { min-height: 49px; border-radius: 6px; background: #216f62; }
.login-card .button:hover { background: #19594f; }
.login-card .login-toggle { color: #28675d; font-size: 0.9rem; font-weight: 700; }
.login-error { color: #b13e3e; min-height: 1.2em; margin: 0; font-size: 0.86rem; }

@media (max-width: 760px) {
  .login-page { background-position: 58% center; background-attachment: scroll; }
  .login-shell { grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: center; gap: 28px; padding: 30px 22px; }
  .login-brand { width: min(100%, 440px); text-align: center; }
  .login-mark { margin: 0 auto 20px; }
  .login-brand h1 { font-size: clamp(3rem, 12vw, 4.6rem); }
  .login-tagline { margin-top: 10px; font-size: 1rem; }
  .login-photo-credit { margin-top: 12px; }
  .login-card { width: min(100%, 440px); }
}

[hidden] { display: none !important; }
.link-button { background: none; border: 0; color: #1d64ff; cursor: pointer; font: inherit; padding: 0; text-align: center; }

.admin-shell { max-width: 900px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }
.check-field { flex-direction: row; align-items: center; gap: 8px; }
.admin-users .history-actions input { width: 170px; }
.admin-invoices { overflow-x: auto; }
.admin-invoices .report-table { min-width: 760px; }
.admin-invoice-dialog { width: min(860px, 94vw); }
.admin-invoice-dialog .surface-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-invoice-dialog .surface-header h2 { margin: 0; }
@media print { #adminLink { display: none; } }

.main-nav { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 20px; padding: 6px; background: #fff; border: 1px solid #dfe9f5; border-radius: 12px; }
.main-nav a { padding: 8px 14px; border-radius: 8px; color: #5e7495; text-decoration: none; font-weight: 600; font-size: 0.92rem; }
.main-nav a:hover { background: #f1f6ff; color: #122033; }
.main-nav a.active { background: #e9f1ff; color: #1d64ff; }
.history-list.tall { max-height: none; }
[data-view] > .surface + .surface { margin-top: 20px; }
@media print { .main-nav { display: none; } }

.month-row { display: grid; grid-template-columns: 44px 1fr 110px; align-items: center; gap: 10px; padding: 4px 0; font-size: 0.9rem; color: #5e7495; }
.month-track { background: #edf2fb; border-radius: 6px; height: 12px; overflow: hidden; }
.month-bar { background: #1d64ff; height: 100%; border-radius: 6px; }
.month-amount { text-align: right; color: #122033; }

.line-actions { display: flex; gap: 8px; align-items: center; }
.line-actions select { max-width: 240px; }
.status-badge { display: inline-block; margin: 0 6px; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: #edf2fb; color: #5e7495; }
.status-badge:empty { display: none; }
.status-sent { background: #e9f1ff; color: #1d64ff; }
.status-partial { background: #fff4e0; color: #b26a00; }
.status-paid { background: #e3f6ea; color: #1f8a4c; }
.status-overdue { background: #fde8e6; color: #c0392b; }
.status-cancelled { background: #eee; color: #777; text-decoration: line-through; }

.editor-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog { border: 1px solid #dfe9f5; border-radius: 14px; padding: 0; width: min(520px, 92vw); }
.dialog::backdrop { background: rgba(18, 32, 51, 0.45); }
.dialog-form { display: grid; gap: 12px; padding: 22px; }
.dialog-form h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.report-table th, .report-table td { padding: 8px 10px; border-bottom: 1px solid #edf2fb; text-align: left; }
.report-table th:not(:first-child), .report-table td.numeric { text-align: right; }
.report-table.expense-table th,
.report-table.expense-table td { vertical-align: top; text-align: left; }
.report-table.expense-table th:nth-child(1), .report-table.expense-table td:nth-child(1) { width: 14%; }
.report-table.expense-table th:nth-child(2), .report-table.expense-table td:nth-child(2) { width: 18%; overflow-wrap: anywhere; }
.report-table.expense-table th:nth-child(3), .report-table.expense-table td:nth-child(3) { width: 38%; }
.report-table.expense-table th:nth-child(4), .report-table.expense-table td:nth-child(4) { width: 20%; text-align: right; }
.report-table.expense-table th:nth-child(5), .report-table.expense-table td:nth-child(5) { width: 10%; text-align: center; }
.report-total td { font-weight: 700; border-top: 2px solid #dfe9f5; }
@media print { dialog { display: none; } }

.contract-template { width: 100%; font-family: Consolas, "Courier New", monospace; font-size: 0.85rem; line-height: 1.5; }
.contract-preview { line-height: 1.5; font-size: 0.9rem; }
.contract-preview p { margin: 0 0 3px; }
.contract-preview .contract-title { text-align: center; font-size: 1.15rem; margin: 0 0 12px; }
.contract-preview .contract-article { margin: 16px 0 4px; font-size: 1rem; }
.contract-preview .contract-gap { height: 8px; }
.contract-preview hr { border: 0; border-top: 1px solid #dfe9f5; margin: 14px 0; }
mark.missing { background: #fff4cc; color: #8a5a00; padding: 0 3px; border-radius: 3px; }
