:root {
  --color-black: #111111;
  --color-black-soft: #1c1c1c;
  --color-yellow: #f2df1a;
  --color-yellow-soft: #f7ec7a;
  --color-sky-light: #dff4ff;
  --color-white: #ffffff;
  --color-bg: #f5f5f2;
  --color-border: #e2e0d8;
  --color-text-muted: #6b6b64;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-black);
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  line-height: 1.4;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* ---------- Layout shell ---------- */

.topbar {
  background: var(--color-yellow-soft);
  color: var(--color-black);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.topbar__brand img {
  height: 36px;
  width: auto;
}

.topbar__brand span {
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.topbar__user .username {
  color: var(--color-black);
  font-weight: 700;
}

.btn-logout {
  border: 1px solid var(--color-black);
  color: var(--color-black);
  background: transparent;
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

/* ---------- Flash ---------- */

.flash {
  background: #3a1f1f;
  color: #ffd7d7;
  border: 1px solid #7a3a3a;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

/* ---------- Login ---------- */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #1c1c1c, var(--color-black) 70%);
  padding: 1.25rem;
}

.login-card {
  background: var(--color-white);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-card img.logo {
  width: 140px;
  margin: 0 auto 1.25rem;
}

.login-card h1 {
  font-size: 1.2rem;
  margin: 0 0 1.25rem;
  color: var(--color-black);
}

.field {
  text-align: left;
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--color-black);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-white);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--color-yellow);
  border-color: var(--color-yellow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
}

.btn-primary {
  background: var(--color-yellow);
  color: var(--color-black);
  width: 100%;
}

.btn-primary:active {
  background: var(--color-yellow-soft);
}

.btn-secondary {
  background: var(--color-black);
  color: var(--color-white);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--color-black);
  color: var(--color-black);
}

/* ---------- Dashboard ---------- */

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-top: 1.5rem;
}

.icon-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.75rem 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.icon-card:active {
  transform: scale(0.97);
  border-color: var(--color-yellow);
}

.icon-card .icon-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-black);
  color: var(--color-yellow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
}

.icon-card .icon-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.icon-card .icon-sub {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 0.5rem 0 0;
}

/* ---------- Document list ---------- */

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.doc-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.doc-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.doc-card__main {
  min-width: 0;
}

.doc-card__number {
  font-weight: 700;
  color: var(--color-black);
}

.doc-card__customer {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-card__meta {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.15rem;
}

.doc-card__net {
  font-weight: 700;
  white-space: nowrap;
  text-align: right;
}

.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: 2.5rem 1rem;
  background: var(--color-white);
  border-radius: var(--radius);
  border: 1px dashed var(--color-border);
}

/* ---------- Document form ---------- */

.form-section {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.form-section h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 0.8rem;
  color: var(--color-text-muted);
}

.item-row {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  position: relative;
}

.item-row__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

.item-row__qty-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
}

.item-row__total {
  text-align: right;
  font-weight: 700;
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

.item-row__remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: #b33;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  cursor: pointer;
}

.add-item-btn {
  width: 100%;
  border: 1.5px dashed var(--color-black);
  background: transparent;
  border-radius: var(--radius);
  padding: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 46px;
}

.totals-box {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.95rem;
}

.totals-row.net {
  border-top: 2px solid var(--color-black);
  margin-top: 0.3rem;
  padding-top: 0.6rem;
  font-weight: 700;
  font-size: 1.1rem;
}

.form-actions {
  position: sticky;
  bottom: 0;
  background: var(--color-bg);
  padding: 0.75rem 0 1rem;
}

/* ================================================================
   Print / view document — designed to match the reference invoice
   ================================================================ */

.doc-page-wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 0.75rem;
}

.print-toolbar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.doc-sheet {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  padding: 1.25rem 0.85rem;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.doc-header img.logo {
  width: 110px;
}

.doc-header__title {
  text-align: right;
}

.doc-header__title h1 {
  font-size: 1.8rem;
  letter-spacing: 0.12em;
  margin: 0 0 0.5rem;
  font-weight: 800;
}

.doc-header__meta {
  font-size: 0.85rem;
  display: grid;
  grid-template-columns: max-content max-content;
  justify-content: end;
  column-gap: 0.75rem;
  row-gap: 0.2rem;
}

.doc-header__meta strong {
  text-align: right;
}

.doc-header__meta div {
  display: contents;
}

.doc-header__meta span {
  min-width: 7.5rem;
  text-align: left;
}

.items-table-wrap {
  overflow-x: auto;
  border-radius: 7px;
  margin-bottom: 1.5rem;
}

.items-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  margin-bottom: 0;
  font-size: 0.72rem;
}

.items-table thead th {
  background: var(--color-yellow);
  color: var(--color-black);
  text-transform: uppercase;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  padding: 0.5rem 0.3rem;
  text-align: left;
  word-break: break-word;
}

.items-table thead th.sl,
.items-table tbody td.sl {
  background: var(--color-black);
  color: var(--color-white);
  text-align: center;
  width: 1.6rem;
  padding-left: 0.2rem;
  padding-right: 0.2rem;
}

.items-table th.num,
.items-table td.num {
  text-align: right;
}

.items-table tbody td {
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid var(--color-border);
  word-break: break-word;
}

@media (min-width: 480px) {
  .items-table {
    font-size: 0.85rem;
  }

  .items-table thead th {
    font-size: 0.72rem;
    padding: 0.55rem 0.5rem;
  }

  .items-table tbody td {
    padding: 0.55rem 0.5rem;
  }
}

.doc-bottom {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.payment-info h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  margin: 0 0 0.5rem;
}

.payment-info div {
  font-size: 0.82rem;
  margin-bottom: 0.2rem;
}

.doc-totals {
  min-width: 220px;
  flex: 1 1 220px;
  max-width: 320px;
  margin-left: auto;
}

.doc-totals .totals-row {
  font-size: 0.88rem;
}

.doc-totals .totals-row.net {
  background: var(--color-yellow);
  border: none;
  padding: 0.6rem 0.6rem;
  border-radius: 4px;
}

.doc-footer {
  margin-top: 1.5rem;
}

.doc-footer-note {
  border-top: 1px solid var(--color-border);
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.signature-line {
  text-align: center;
  min-width: 160px;
  width: 180px;
  margin-left: auto;
  margin-bottom: 0.75rem;
}

.signature-line .line {
  height: 2rem;
  border-bottom: 1px solid var(--color-black);
  margin-top: 0.25rem;
}

.company-strip {
  background: var(--color-sky-light);
  color: var(--color-black);
  border-radius: 7px;
  text-align: center;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding: 0.6rem;
  margin-top: 0.6rem;
}

/* ---------- Responsive: tablet / desktop ---------- */

@media (min-width: 640px) {
  .item-row__grid {
    grid-template-columns: 2fr 1fr 1fr 1fr;
  }

  .item-row__qty-grid {
    display: contents;
  }

  .form-actions {
    display: flex;
    gap: 0.75rem;
  }

  .form-actions .btn {
    width: auto;
    min-width: 160px;
  }
}

@media (min-width: 768px) {
  .doc-sheet {
    padding: 2.5rem;
  }
}

/* ---------- Print ---------- */

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  html,
  body {
    width: 100%;
    margin: 0;
    padding: 0;
  }

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

  .topbar,
  .print-toolbar,
  .no-print {
    display: none !important;
  }

  body {
    background: var(--color-white);
  }

  .doc-page-wrap {
    max-width: none;
    padding: 0;
  }

  .doc-sheet {
    display: flex;
    flex-direction: column;
    min-height: 273mm;
    box-shadow: none;
    border: none;
    padding: 0;
  }

  .items-table thead th,
  .doc-totals .totals-row.net {
    background-color: #f2df1a !important;
    color: #111111 !important;
  }

  .items-table thead th.sl,
  .items-table tbody td.sl {
    background-color: #111111 !important;
  }

  .items-table thead th.sl,
  .items-table tbody td.sl {
    color: #ffffff !important;
  }

  .doc-footer {
    margin-top: auto;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .doc-footer-note {
    flex-wrap: nowrap;
    align-items: flex-end;
  }

  .signature-line {
    flex: 0 0 180px;
    margin-left: auto;
  }

  .company-strip {
    background-color: #dff4ff !important;
    color: #111111 !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
