:root {
  --ink: #0a2335;
  --navy: #003f68;
  --blue: #0096dc;
  --cyan: #70d6ff;
  --steel: #577080;
  --paper: #f6fafc;
  --panel: #ffffff;
  --line: #d7e7ef;
  --gold: #c7a35b;
  --green: #0d7a52;
  --red: #b94135;
  --shadow: 0 24px 70px rgba(4, 39, 65, .14);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(135deg, rgba(0, 63, 104, .08), rgba(112, 214, 255, .06) 42%, rgba(199, 163, 91, .08)),
    var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
}

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

button {
  cursor: pointer;
}

img {
  display: block;
}

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

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(480px, 100%);
  display: grid;
  gap: 16px;
  padding: 30px;
  border: 1px solid rgba(215, 231, 239, .94);
  border-radius: 8px;
  background: rgba(255, 255, 255, .97);
  box-shadow: var(--shadow);
}

.auth-card .brand-mark {
  width: 92px;
  height: 92px;
}

.auth-card .brand-mark img {
  width: 66px;
  height: 66px;
}

.auth-card h1 {
  font-size: clamp(2rem, 6vw, 3rem);
}

.auth-card p {
  margin-bottom: 0;
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(0, 50, 84, .98), rgba(3, 31, 49, .98)),
    var(--navy);
  color: #fff;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(112, 214, 255, .34);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .22);
}

.brand-mark img {
  width: 46px;
  height: 46px;
  object-fit: contain;
}

.brand strong {
  display: block;
  font-size: 1.25rem;
  letter-spacing: .04em;
}

.brand small,
.kicker,
label span,
.metric-card span,
.preview-block small {
  font-family: "Trebuchet MS", Verdana, sans-serif;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.brand small {
  color: rgba(255, 255, 255, .68);
  font-size: .72rem;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 8px;
  margin-top: 34px;
}

.nav-link {
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: rgba(255, 255, 255, .74);
  text-decoration: none;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.nav-link:hover,
.nav-link.active {
  border-color: rgba(112, 214, 255, .24);
  background: rgba(255, 255, 255, .1);
  color: #fff;
}

.nav-icon {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(112, 214, 255, .22);
  border-radius: 50%;
  color: var(--cyan);
  font-size: .78rem;
  font-weight: 900;
}

.side-panel {
  margin-top: 36px;
  padding-top: 22px;
  border-top: 1px solid rgba(255, 255, 255, .16);
}

.kicker {
  margin: 0 0 9px;
  color: var(--blue);
  font-size: .72rem;
  font-weight: 900;
}

.sidebar .kicker {
  color: var(--cyan);
}

.mini-list {
  display: grid;
  gap: 12px;
}

.mini-state {
  display: grid;
  gap: 5px;
}

.mini-state-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(255, 255, 255, .86);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .85rem;
  font-weight: 800;
}

.mini-track,
.bar-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
}

.mini-fill,
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

main {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  padding: 30px;
  border: 1px solid rgba(215, 231, 239, .85);
  border-radius: var(--radius);
  background:
    linear-gradient(110deg, rgba(255, 255, 255, .98), rgba(246, 250, 252, .94)),
    var(--panel);
  box-shadow: var(--shadow);
}

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

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4vw, 3.75rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.85rem, 3vw, 2.7rem);
  line-height: 1.06;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.topbar-actions,
.filter-row,
.form-actions,
.line-items-head,
.panel-head,
.section-head,
.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .82rem;
  font-weight: 900;
}

.section-head,
.panel-head {
  justify-content: space-between;
}

.section-head {
  margin-bottom: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.primary-action,
.ghost-action,
.icon-button {
  min-height: 43px;
  border-radius: 6px;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.primary-action {
  border: 1px solid #007fbd;
  padding: 0 17px;
  background: linear-gradient(135deg, var(--blue), #006da6);
  color: #fff;
  box-shadow: 0 14px 28px rgba(0, 150, 220, .23);
}

.ghost-action,
.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-action {
  padding: 0 15px;
}

.icon-button {
  width: 43px;
  padding: 0;
}

.primary-action:hover,
.ghost-action:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(4, 39, 65, .11);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cbdde7;
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}

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

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--steel);
  font-size: .7rem;
  font-weight: 900;
}

.select-label {
  min-width: 188px;
}

.toolbar-filters {
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 860px;
}

.toolbar-filters .select-label {
  min-width: 142px;
}

.toolbar-filters input {
  min-width: 150px;
}

.filter-row {
  width: min(760px, 100%);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-row input {
  flex: 1 1 210px;
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 43px;
  gap: 10px;
}

input[readonly] {
  color: var(--navy);
  background: #f1f7fa;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 900;
}

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

.metric-card,
.panel {
  border: 1px solid rgba(215, 231, 239, .94);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 14px 42px rgba(4, 39, 65, .08);
}

.metric-card {
  position: relative;
  overflow: hidden;
  min-height: 154px;
  padding: 22px;
}

.metric-card::after {
  content: "";
  position: absolute;
  right: -34px;
  bottom: -54px;
  width: 130px;
  height: 130px;
  border: 1px solid rgba(0, 150, 220, .22);
  transform: rotate(18deg);
}

.metric-card.total {
  background:
    linear-gradient(135deg, rgba(0, 63, 104, .96), rgba(0, 109, 166, .92)),
    var(--navy);
  color: #fff;
}

.metric-card span {
  display: block;
  margin-bottom: 14px;
  color: var(--steel);
  font-size: .68rem;
  font-weight: 900;
}

.metric-card.total span,
.metric-card.total small {
  color: rgba(255, 255, 255, .72);
}

.metric-card strong {
  display: block;
  margin-bottom: 7px;
  font-size: clamp(1.65rem, 3vw, 2.3rem);
  line-height: 1;
}

.metric-card small {
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 700;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 20px;
}

.state-bars {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.state-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) 122px;
  align-items: center;
  gap: 13px;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.state-row strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
}

.bar-track {
  height: 12px;
  background: #e7f0f5;
}

.chart-panel canvas {
  width: 100%;
  max-height: 330px;
  margin-top: 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid #e5eef3;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

td {
  color: #1d3a4c;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 700;
}

td small {
  color: var(--steel);
  font-weight: 800;
}

.numeric {
  text-align: right;
}

.actions-col {
  width: 246px;
}

.row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.row-actions .ghost-action,
.row-actions .danger-action {
  min-height: 36px;
  padding: 0 11px;
  font-size: .82rem;
}

.danger-action {
  border: 1px solid rgba(185, 65, 53, .32);
  border-radius: 6px;
  background: rgba(185, 65, 53, .08);
  color: var(--red);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.danger-action:hover {
  border-color: rgba(185, 65, 53, .58);
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(185, 65, 53, .1);
}

.empty-state,
.side-empty {
  margin: 0;
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.side-empty {
  color: rgba(255, 255, 255, .72);
  font-size: .88rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #edf6fb;
  color: var(--navy);
  font-size: .76rem;
  font-weight: 900;
  text-transform: capitalize;
}

.badge.paid {
  background: rgba(13, 122, 82, .12);
  color: var(--green);
}

.badge.overdue {
  background: rgba(185, 65, 53, .12);
  color: var(--red);
}

.badge.sent {
  background: rgba(0, 150, 220, .13);
  color: #006da6;
}

.invoice-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(330px, .65fr);
  gap: 16px;
  align-items: start;
}

.form-panel {
  display: grid;
  gap: 18px;
}

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

.line-items-head {
  justify-content: space-between;
}

.line-items {
  display: grid;
  gap: 10px;
}

.line-item {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 86px 118px 92px 43px;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid #e5eef3;
  border-radius: 8px;
  background: #fbfdfe;
}

.line-item .item-notes {
  grid-column: 1 / -1;
  min-height: 72px;
}

.item-paid-control {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #cbdde7;
  border-radius: 6px;
  background: #fff;
}

.item-paid-control input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--green);
}

.item-paid-control span {
  color: var(--ink);
  font-size: .72rem;
}

.invoice-preview {
  position: sticky;
  top: 24px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #fff, #f8fbfd),
    var(--panel);
}

.invoice-preview::before {
  content: "";
  display: block;
  height: 7px;
  margin: -20px -20px 20px;
  background: linear-gradient(90deg, var(--navy), var(--blue), var(--gold));
}

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

.preview-head img {
  width: 74px;
  height: 74px;
  object-fit: contain;
}

.preview-head p {
  margin: 0 0 4px;
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .82rem;
  font-weight: 800;
  text-align: right;
}

.preview-head strong {
  display: block;
  font-size: 1.85rem;
  text-align: right;
}

.preview-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 20px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 900;
}

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

.preview-dates span {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfd;
}

.preview-dates small,
.preview-line small {
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.preview-dates strong {
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .92rem;
}

.preview-block {
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.preview-block small {
  color: var(--steel);
  font-weight: 900;
}

.preview-block strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 1.22rem;
}

.preview-block em {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .88rem;
  font-style: normal;
  font-weight: 900;
}

.preview-block p {
  margin-bottom: 0;
  color: var(--steel);
  line-height: 1.45;
}

.preview-project {
  border-top: 0;
}

.preview-project strong {
  color: var(--navy);
}

.preview-lines {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.preview-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e9f0f4;
  color: #29495d;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.preview-line.paid-item strong {
  color: var(--green);
}

.preview-line em {
  display: inline-block;
  margin-top: 5px;
  color: var(--steel);
  font-size: .82rem;
  font-style: normal;
  font-weight: 700;
  line-height: 1.35;
}

.preview-totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.preview-totals span {
  display: grid;
  gap: 5px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fbfd;
}

.preview-totals small {
  color: var(--steel);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.preview-totals strong {
  font-size: 1.25rem;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: 340px;
  padding: 14px 16px;
  border: 1px solid rgba(112, 214, 255, .32);
  border-radius: var(--radius);
  background: rgba(0, 50, 84, .94);
  color: #fff;
  box-shadow: var(--shadow);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: relative;
    height: auto;
  }

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

  .side-panel {
    display: none;
  }

  .metric-grid,
  .dashboard-grid,
  .invoice-layout {
    grid-template-columns: 1fr 1fr;
  }

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

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

  .topbar,
  .section-head,
  .panel-head,
  .toolbar-filters,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

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

  .metric-grid,
  .dashboard-grid,
  .invoice-layout,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .state-row {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .state-row strong {
    grid-column: 1 / -1;
  }

  .line-item {
    grid-template-columns: 1fr 86px;
  }

  .line-item .item-desc,
  .line-item .item-rate,
  .line-item .item-paid-control,
  .line-item .item-notes {
    grid-column: 1 / -1;
  }
}

@media print {
  @page {
    size: letter;
    margin: .45in;
  }

  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .section-head,
  .form-panel,
  .toast {
    display: none !important;
  }

  .app-shell,
  main,
  .view.active,
  .invoice-layout {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .view:not(#new-invoice) {
    display: none;
  }

  .invoice-preview {
    position: static;
    width: 100%;
    max-width: 7.4in;
    margin: 0 auto;
    padding: 0;
    box-shadow: none;
    border: 0;
    background: #fff;
  }

  .invoice-preview::before {
    margin: 0 0 22px;
  }

  .preview-head img {
    width: 88px;
    height: 88px;
  }

  .preview-head strong {
    font-size: 2.2rem;
  }

  .preview-line,
  .preview-meta,
  .preview-dates span,
  .preview-totals span {
    break-inside: avoid;
  }
}
