:root {
  --ink: #1f2933;
  --muted: #667085;
  --line: #d7dde5;
  --bg: #f5f7fa;
  --panel: #fff;
  --primary: #0f5f64;
  --primary-dark: #084247;
  --primary-soft: #edf4f2;
  --site-header-bg: #f7f5ef;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  letter-spacing: 0;
}

a {
  color: #0b5cab;
  text-decoration: none;
}

img {
  max-width: 100%;
}

.app {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--site-header-bg);
  color: var(--ink);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--ink);
  font-weight: 700;
  margin-bottom: 18px;
}

.brand-logo {
  width: 88px;
  height: auto;
  background: white;
  padding: 3px 5px;
  border-radius: 6px;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar a {
  color: var(--ink);
  padding: 10px;
  border-radius: 6px;
}

.sidebar a:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.topbar {
  height: 64px;
  background: var(--site-header-bg);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
}

.topbar h1 {
  font-size: 20px;
  margin: 0;
  flex: 1;
}

.content {
  padding: 24px;
}

.user-pill {
  color: var(--muted);
}

.panel,
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

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

.panel h2 {
  font-size: 16px;
  margin: 0 0 12px;
}

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

.stats {
  grid-template-columns: repeat(7, 1fr);
}

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

.payments-summary {
  grid-template-columns: repeat(4, 1fr);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  font-size: 22px;
  margin-top: 8px;
}

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

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
}

.invoice-items-table .num,
.invoice-items-table .money-cell {
  text-align: right;
}

.badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #f8fafc;
}

.badge-overdue {
  border-color: #f3b7b1;
  background: #fff1f0;
  color: var(--danger);
  font-weight: 700;
  margin-left: 6px;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.readonly-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.readonly-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.readonly-grid strong {
  display: block;
  margin-top: 4px;
}

button,
.button {
  display: inline-block;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}

.primary,
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.primary:hover,
button.primary:hover {
  background: var(--primary-dark);
}

.danger {
  color: var(--danger);
  border-color: #f3b7b1;
}

.actions,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}

.actions form {
  display: inline;
}

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

.form-wide label,
.form-grid label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.check {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  font: inherit;
}

textarea {
  min-height: 88px;
}

.items input,
.items select {
  min-width: 100px;
}

.alert {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: #eef4ff;
}

.alert.error {
  background: #fff1f0;
  border-color: #f3b7b1;
}

.alert.success {
  background: #ecfdf3;
  border-color: #abefc6;
}

.alert.warning {
  background: #fffaeb;
  border-color: #fedf89;
}

.hidden {
  display: none;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 14px;
  background: linear-gradient(180deg, var(--primary-soft), #f8fafc);
}

.login-shell {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
}

.login-box {
  background: white;
  border: 1px solid var(--line);
  border-top: 5px solid var(--primary);
  border-radius: 8px;
  padding: 28px;
  display: grid;
  gap: 14px;
  box-shadow: 0 18px 50px rgba(24, 45, 48, .10);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-logo {
  width: 150px;
}

.login-box h1 {
  font-size: 22px;
  margin: 0;
}

.login-contact {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.pos-footer,
.login-footer {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.pos-footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.login-footer {
  padding: 0 4px;
  text-align: center;
}

.pos-footer p,
.login-footer p {
  margin: 0 0 6px;
}

.pos-footer strong,
.login-footer strong {
  color: var(--ink);
}

.company-links,
.legal-links {
  word-break: break-word;
}

.invoice-doc {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 16px;
}

.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 22px;
}

.invoice-logo {
  width: 150px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.summary {
  margin-left: auto;
  max-width: 330px;
}

.summary p {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  margin: 0;
}

.summary .grand {
  font-size: 18px;
  font-weight: 700;
}

.invoice-info-grid {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  gap: 16px;
  margin-top: 20px;
  clear: both;
}

.bank-transfer-details {
  clear: both;
  margin-top: 20px;
}

.bank-transfer-details h2 {
  margin-bottom: 14px;
}

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

.bank-account-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
  min-width: 0;
}

.bank-account-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.bank-account-card dl {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
}

.bank-account-card dt {
  color: var(--muted);
  font-weight: 700;
}

.bank-account-card dd {
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.payment-note {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.visa-terms {
  clear: both;
  margin-top: 20px;
  line-height: 1.55;
}

.visa-terms h2 {
  margin-bottom: 8px;
}

.visa-terms-intro {
  margin: 0 0 12px;
  color: var(--muted);
}

.visa-terms ol {
  margin: 0;
  padding-left: 22px;
  font-size: 13px;
}

.visa-terms li {
  margin-bottom: 9px;
  padding-left: 4px;
}

.company-info dl {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 7px 12px;
  margin: 0;
}

.company-info dt {
  color: var(--muted);
  font-weight: 700;
}

.company-info dd {
  margin: 0;
}

.terms-info ul,
.terms-info ol {
  margin: 8px 0 0;
  padding-left: 19px;
}

.terms-info li {
  margin-bottom: 6px;
}

.placeholder-note {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 8px;
}

.public-invoice {
  background: #f8fafc;
}

.public.invoice-doc,
.invoice-doc.public {
  max-width: 920px;
  margin: 24px auto;
}

.status-large {
  font-size: 22px;
  font-weight: 700;
  padding: 10px 0;
}

.status-large.paid {
  color: #067647;
}

.status-large.pending {
  color: #b54708;
}

.menu-btn {
  display: none;
}

@media (max-width: 900px) {
  .app {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .nav-open .sidebar {
    display: block;
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    width: 230px;
  }

  .menu-btn {
    display: inline-block;
  }

  .topbar {
    padding: 0 14px;
  }

  .content {
    padding: 14px;
  }

  .stats,
  .money-grid,
  .payments-summary,
  .form-grid,
  .readonly-grid,
  .details-grid,
  .invoice-info-grid,
  .bank-account-grid {
    grid-template-columns: 1fr;
  }

  .invoice-head {
    align-items: flex-start;
  }

  .company-info dl {
    grid-template-columns: 1fr;
  }

  .company-info dt {
    margin-top: 4px;
  }

  .bank-account-card dl {
    grid-template-columns: 1fr;
  }

  .visa-terms {
    padding: 14px;
  }

  .visa-terms ol {
    padding-left: 20px;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .user-pill {
    display: none;
  }
}

@media (max-width: 600px) {
  .invoice-head {
    flex-direction: column;
  }

  .invoice-head h1 {
    font-size: 28px;
    line-height: 1.15;
    margin: 0;
  }
}

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

  html,
  body {
    width: 100%;
    margin: 0;
    padding: 0;
    background: white;
    color: #111;
    font-size: 10pt;
  }

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

  .app,
  .content,
  .invoice-doc,
  .public.invoice-doc,
  .invoice-doc.public {
    display: block;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  .invoice-doc {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .invoice-head {
    gap: 12px;
    margin-bottom: 14px;
  }

  .invoice-logo {
    width: 120px;
  }

  .invoice-head h1,
  .invoice-head h2 {
    margin: 0;
    font-size: 18pt;
    line-height: 1.15;
  }

  .status-large {
    font-size: 14pt;
    padding: 6px 0;
  }

  .details-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
  }

  table {
    display: table;
    width: 100%;
    max-width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    overflow: visible;
    white-space: normal;
    font-size: 9pt;
    line-height: 1.3;
  }

  thead {
    display: table-header-group;
  }

  tbody {
    display: table-row-group;
  }

  tr {
    break-inside: avoid;
  }

  th,
  td {
    padding: 5px 6px;
    overflow-wrap: anywhere;
    word-break: normal;
    white-space: normal;
  }

  .invoice-items-table .col-service {
    width: 13%;
  }

  .invoice-items-table .col-description {
    width: 47%;
  }

  .invoice-items-table .col-qty {
    width: 8%;
  }

  .invoice-items-table .col-unit {
    width: 15%;
  }

  .invoice-items-table .col-total {
    width: 17%;
  }

  .invoice-items-table th:nth-child(3),
  .invoice-items-table th:nth-child(4),
  .invoice-items-table th:nth-child(5),
  .invoice-items-table td:nth-child(3),
  .invoice-items-table td:nth-child(4),
  .invoice-items-table td:nth-child(5) {
    text-align: right;
  }

  .summary {
    width: min(100%, 330px);
    max-width: 45%;
    margin: 10px 0 14px auto;
    font-size: 10pt;
  }

  .summary p {
    padding: 5px 0;
  }

  .summary .grand {
    font-size: 12pt;
  }

  .panel {
    border: 1px solid #ddd;
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 10px;
    padding: 10px;
  }

  .invoice-info-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 12px;
  }

  .bank-transfer-details,
  .bank-account-card {
    background: white;
  }

  .bank-account-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .bank-transfer-details,
  .bank-account-card,
  .company-info,
  .terms-info {
    break-inside: avoid;
  }

  .bank-account-card {
    padding: 10px;
  }

  .bank-account-card dl {
    grid-template-columns: 105px minmax(0, 1fr);
    gap: 4px 8px;
  }

  .payment-note {
    color: #333;
  }

  .visa-terms {
    background: white;
    line-height: 1.45;
    break-inside: auto;
  }

  .visa-terms h2 {
    font-size: 13pt;
  }

  .visa-terms ol {
    font-size: 9pt;
  }

  .visa-terms-intro {
    color: #333;
  }

  .visa-terms li {
    break-inside: avoid;
    margin-bottom: 7px;
  }

  .company-info dl {
    grid-template-columns: 78px minmax(0, 1fr);
  }

  a {
    color: inherit;
  }
}
