* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --ink: #18201d;
  --muted: #68726d;
  --line: #d7dfda;
  --line-strong: #aebbb4;
  --paper: #fff;
  --paper-soft: #f8faf8;
  --wash: #eef2ef;
  --gold: #dca93b;
  --gold-soft: #fff4d5;
  --green: #0a6457;
  --green-strong: #073f38;
  --green-soft: #e7f2ee;
  --blue-soft: #eaf0f8;
  --danger-soft: #fff1ee;
  --shadow: 0 20px 60px rgb(20 38 31 / 10%);
  --shadow-soft: 0 12px 32px rgb(20 38 31 / 7%);
}

html {
  background: var(--wash);
  overflow-x: hidden;
}

body {
  background: linear-gradient(135deg, #f7faf8 0%, var(--wash) 54%, #e7eeea 100%);
  color: var(--ink);
  font-family: Tahoma, "Segoe UI", sans-serif;
  letter-spacing: 0;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

a,
button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgb(220 169 59 / 45%);
  outline-offset: 3px;
}

.workspace {
  display: grid;
  gap: 18px;
  margin: 22px auto;
  width: min(1480px, calc(100% - 40px));
}

.topbar {
  align-items: center;
  background: rgb(255 255 255 / 88%);
  border: 1px solid rgb(255 255 255 / 74%);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  display: flex;
  justify-content: space-between;
  gap: 18px;
  min-height: 92px;
  padding: 18px 22px;
}

.status-strip {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.date-panel {
  align-items: end;
  background: rgb(255 255 255 / 88%);
  border: 1px solid rgb(255 255 255 / 80%);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(180px, 260px)) auto minmax(180px, 1fr);
  padding: 16px 18px;
}

.date-panel label {
  display: grid;
  gap: 8px;
}

.date-panel span,
#invoice-fetch-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.date-panel input {
  background: #fff;
  border: 1px solid #bac8c0;
  border-radius: 8px;
  min-height: 44px;
  padding: 0 12px;
}

#invoice-fetch-status {
  line-height: 1.7;
  margin: 0;
}

.status-strip article {
  background: rgb(255 255 255 / 88%);
  border: 1px solid rgb(255 255 255 / 82%);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  display: grid;
  gap: 5px;
  min-height: 96px;
  padding: 15px 16px;
}

.status-strip span,
.status-strip small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
}

.status-strip strong {
  color: var(--green-strong);
  direction: rtl;
  font-size: 21px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.brand {
  align-items: center;
  display: flex;
  gap: 14px;
  min-width: 0;
}

.brand span:last-child {
  display: grid;
  gap: 5px;
}

.brand strong {
  font-size: clamp(24px, 2.2vw, 32px);
  line-height: 1.25;
}

.brand small,
.list-head p,
#invoice-id {
  color: var(--muted);
}

.brand small {
  font-size: 14px;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(145deg, #f2c765, #c38c20);
  border: 1px solid rgb(255 255 255 / 55%);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 42%), 0 10px 24px rgb(140 98 17 / 20%);
  color: #fff;
  direction: ltr;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 22px;
  font-weight: 700;
  height: 64px;
  justify-content: center;
  width: 72px;
}

.top-actions,
.view-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.solid-button,
.ghost-button {
  align-items: center;
  border-radius: 8px;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease;
}

.solid-button {
  background: linear-gradient(180deg, var(--green), var(--green-strong));
  border: 1px solid var(--green);
  box-shadow: 0 10px 24px rgb(10 100 87 / 18%);
  color: #fff;
}

.ghost-button {
  background: rgb(255 255 255 / 72%);
  border: 1px solid #bed1c8;
  color: var(--green);
}

.solid-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.solid-button:hover {
  box-shadow: 0 14px 30px rgb(10 100 87 / 24%);
}

.ghost-button:hover {
  background: var(--green-soft);
  border-color: #91afa3;
}

.dashboard {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
}

.invoice-list,
.invoice-view {
  background: rgb(255 255 255 / 92%);
  border: 1px solid rgb(255 255 255 / 80%);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.invoice-list {
  align-content: start;
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 138px);
  padding: 20px;
  position: sticky;
  top: 20px;
}

.list-head {
  align-items: end;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.list-head p,
.list-head h1,
#invoice-id,
#invoice-number {
  margin: 0;
}

.list-head h1 {
  font-size: 26px;
  line-height: 1.25;
  margin-top: 6px;
}

.list-head strong {
  align-items: center;
  background: linear-gradient(180deg, var(--gold-soft), #ffe8a8);
  border: 1px solid #e0bd63;
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 65%);
  color: #6b4a04;
  display: inline-flex;
  font-size: 28px;
  height: 62px;
  justify-content: center;
  min-width: 62px;
  padding: 0 10px;
}

.search {
  display: grid;
  gap: 8px;
}

.search span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search input {
  background: #fff;
  border: 1px solid #bac8c0;
  border-radius: 8px;
  box-shadow: inset 0 1px 2px rgb(20 38 31 / 5%);
  min-height: 48px;
  padding: 0 14px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
  width: 100%;
}

.search input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgb(10 100 87 / 10%);
  outline: 0;
}

.scope-tabs {
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
  padding: 5px;
}

.scope-tab {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  min-height: 40px;
  padding: 0 10px;
  transition: background 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.scope-tab.is-active {
  background: #fff;
  box-shadow: 0 8px 18px rgb(20 38 31 / 8%);
  color: var(--green-strong);
}

.list-scroll {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding-inline-end: 2px;
  scrollbar-color: #b4c1bb transparent;
}

.invoice-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 7px;
  min-height: 96px;
  padding: 14px;
  text-align: right;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
  width: 100%;
}

.invoice-row:hover {
  border-color: #aec3b9;
  box-shadow: 0 10px 24px rgb(20 38 31 / 8%);
  transform: translateY(-1px);
}

.row-top {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-width: 0;
}

.invoice-row strong {
  color: var(--green-strong);
  direction: ltr;
  font-size: 13px;
  justify-self: end;
}

.invoice-row em {
  background: var(--green-soft);
  border: 1px solid #cfe0d8;
  border-radius: 999px;
  color: var(--green);
  flex: 0 1 auto;
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 1.4;
  max-width: 44%;
  overflow: hidden;
  padding: 4px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-row span {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.6;
}

.invoice-row small {
  color: var(--muted);
  line-height: 1.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-row.is-active {
  background: linear-gradient(90deg, rgb(10 100 87 / 10%), #fff 68%);
  border-color: var(--green);
  box-shadow: inset -4px 0 0 var(--green), 0 12px 26px rgb(10 100 87 / 11%);
}

.invoice-view {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.invoice-view > *,
#invoice-detail,
#delivery-detail,
.invoice-view-head > div {
  min-width: 0;
}

.invoice-view-head {
  align-items: end;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding-bottom: 18px;
}

#invoice-number,
#delivery-title {
  color: var(--green-strong);
  line-height: 1.25;
}

#invoice-number {
  direction: ltr;
  font-size: clamp(28px, 3vw, 38px);
  margin-top: 8px;
  text-align: right;
}

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

.party-panel {
  background: linear-gradient(180deg, #fff, var(--paper-soft));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgb(20 38 31 / 5%);
  padding: 20px;
}

.party-panel h3 {
  align-items: center;
  display: flex;
  font-size: 21px;
  gap: 10px;
  margin: 0 0 16px;
}

.party-panel h3::before {
  background: var(--gold);
  border-radius: 99px;
  content: "";
  height: 10px;
  width: 10px;
}

.party-panel p,
.settlement p {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  line-height: 1.9;
  margin: 8px 0;
}

.party-panel span,
.settlement span {
  color: var(--muted);
}

.party-panel strong,
.settlement strong {
  overflow-wrap: anywhere;
}

.field-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-grid p {
  background: #fff;
  border: 1px solid #edf1ee;
  border-radius: 8px;
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 10px 12px;
}

.line-items {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  width: 100%;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 860px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 15px 12px;
  text-align: center;
}

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

th:first-child,
td:first-child {
  text-align: right;
}

thead th {
  background: #f0f5f2;
  color: #30443c;
  font-size: 13px;
  position: sticky;
  top: 0;
  white-space: nowrap;
  z-index: 1;
}

tbody td {
  background: #fff;
}

.settlement {
  background: linear-gradient(180deg, #fbfdfb, #f3f7f4);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 14px 18px;
}

.settlement p {
  background: #fff;
  border: 1px solid #edf1ee;
  border-radius: 8px;
  margin: 0;
  padding: 10px 12px;
}

.empty {
  background: var(--paper-soft);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  margin: 0;
  padding: 18px;
  text-align: center;
}

@media (max-width: 1020px) {
  .workspace {
    margin: 12px auto;
    width: min(100% - 24px, 100%);
  }

  .topbar,
  .invoice-view-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .view-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .top-actions .solid-button,
  .view-actions .solid-button {
    grid-column: 1 / -1;
  }

  .dashboard,
  .date-panel,
  .status-strip,
  .party-grid,
  .field-grid,
  .settlement {
    grid-template-columns: 1fr;
  }

  .invoice-list {
    max-height: none;
    position: static;
  }

  .invoice-view {
    padding: 16px;
  }
}

@media (max-width: 560px) {
  .brand-mark {
    height: 54px;
    width: 58px;
  }

  .topbar,
  .invoice-list,
  .invoice-view {
    padding: 14px;
  }

  .top-actions,
  .view-actions {
    grid-template-columns: 1fr;
  }

  .invoice-row small {
    white-space: normal;
  }

  .row-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .invoice-row em {
    max-width: 100%;
  }
}
