:root {
  --primary: #008fbe;
  --primary-dark: #00739a;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 10px 30px rgba(2, 8, 23, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

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

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

.brand-logo {
  height: 44px;
  width: auto;
}

/* Nav */
.nav {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-link {
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 12px;
  border-radius: 12px;
}

.nav-link:hover {
  background: rgba(2, 8, 23, 0.04);
  text-decoration: none;
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-top: 22px;
}

.card h1 {
  margin: 0 0 14px 0;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.card p { color: var(--muted); }

/* Buttons */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.04s ease, background 0.15s ease;
}

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

button:active,
.button:active {
  transform: translateY(1px);
}

.button.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.button.secondary:hover {
  background: rgba(2, 8, 23, 0.03);
}

/* Forms */
form { margin-top: 14px; }
label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

input, select {
  width: 100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  background: #fff;
  outline: none;
}

input:focus, select:focus {
  border-color: rgba(0, 143, 190, 0.45);
  box-shadow: 0 0 0 4px rgba(0, 143, 190, 0.12);
}

form > button {
  margin-top: 20px;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form input, .inline-form select {
  flex: 1;
  min-width: 220px;
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 720px) {
  .container { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .brand { min-width: auto; }
}

/* Table */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.table thead th {
  text-align: left;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  background: #f8fafc;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.table tbody tr:hover {
  background: rgba(2, 8, 23, 0.02);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* Status pill */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  border: 1px solid var(--border);
  background: #fff;
}

/* Muted */
.muted { color: var(--muted); }

/* Alerts */
.alert {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text);
  margin-bottom: 12px;
}

.alert.success { border-color: rgba(22,163,74,0.25); background: rgba(22,163,74,0.08); }
.alert.warning { border-color: rgba(217,119,6,0.25); background: rgba(217,119,6,0.08); }
.alert.error   { border-color: rgba(220,38,38,0.25); background: rgba(220,38,38,0.08); }

/* Footer */
.footer {
  margin-top: 28px;
  padding: 18px 0 10px 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

/* Link-like button */
.link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
}
.link-button:hover { text-decoration: underline; }

/* Make tables fill available width nicely */
.table {
  table-layout: fixed;           /* key: distribute width across columns */
}

.table th, .table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Column sizing for invoices table */
.table th:nth-child(1), .table td:nth-child(1) { width: 16%; } /* Date */
.table th:nth-child(2), .table td:nth-child(2) { width: 22%; } /* Invoice */
.table th:nth-child(3), .table td:nth-child(3) { width: 18%; } /* Status */
.table th:nth-child(4), .table td:nth-child(4) { width: 14%; } /* Total */
.table th:nth-child(5), .table td:nth-child(5) { width: 14%; } /* Paid */
.table th:nth-child(6), .table td:nth-child(6) { width: 14%; } /* Due */
.table th:nth-child(7), .table td:nth-child(7) { width: 12%; } /* Action */

/* Right align numeric columns */
.table th:nth-child(4),
.table th:nth-child(5),
.table th:nth-child(6),
.table td:nth-child(4),
.table td:nth-child(5),
.table td:nth-child(6) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Push the action column content to the right */
.table th:last-child,
.table td:last-child {
  text-align: right;
}

.table a.link {
  display: inline-flex;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-weight: 700;
  text-decoration: none;
  background: #fff;
}

.table a.link:hover {
  background: rgba(2, 8, 23, 0.03);
  text-decoration: none;
}
.filters { margin-top: 12px; }
.filters-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.8fr 0.8fr 0.6fr 0.5fr;
  gap: 12px;
  align-items: end;
  margin-bottom: 10px;
}
.filters-actions { display: flex; }
@media (max-width: 980px) {
  .filters-grid { grid-template-columns: 1fr 1fr; }
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.pager-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pager-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
}

.pager-page:hover { background: rgba(2, 8, 23, 0.03); }

.pager-page.active {
  border-color: rgba(0, 143, 190, 0.35);
  box-shadow: 0 0 0 4px rgba(0, 143, 190, 0.10);
}

.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.btn-chip:hover {
  background: rgba(2, 8, 23, 0.03);
  text-decoration: none;
}

/* Contact search dropdown */
.contact-search-wrap {
  position: relative;
}

.contact-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 100;
  background: #f0f6fa;
  border: 2px solid rgba(0, 143, 190, 0.40);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(2, 8, 23, 0.14);
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}

.contact-result {
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 143, 190, 0.15);
  transition: background 0.12s ease;
  background: #f0f6fa;
}

.contact-result:last-child {
  border-bottom: none;
}

.contact-result:hover {
  background: rgba(0, 143, 190, 0.14);
}

.contact-result-name {
  font-weight: 700;
  font-size: 0.97rem;
  color: var(--text);
}

.contact-result-meta {
  font-size: 0.83rem;
  color: var(--muted);
  margin-top: 4px;
}

.contact-result-empty {
  color: var(--muted);
  font-size: 0.9rem;
  cursor: default;
  padding: 16px;
  background: #f0f6fa;
}

.contact-result-empty:hover {
  background: #f0f6fa;
}

/* ============================================================
   Mobile / responsive
   ============================================================ */

/* Hamburger toggle button — hidden on desktop */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  margin: 0;
  cursor: pointer;
  color: var(--text);
  border-radius: 10px;
  line-height: 0;
}
.nav-toggle:hover { background: rgba(2,8,23,0.04); }

@media (max-width: 640px) {

  /* --- Nav --- */
  .nav-toggle { display: flex; align-items: center; }

  .topbar { position: relative; }

  .nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 8px 16px 16px;
    gap: 4px;
    z-index: 50;
    box-shadow: 0 8px 24px rgba(2,8,23,0.08);
  }

  .nav.open { display: flex; }

  .nav-link {
    padding: 12px 14px;
    font-size: 1rem;
    border-radius: 10px;
  }

  /* --- Card --- */
  .card {
    padding: 16px;
    margin-top: 12px;
    border-radius: 12px;
  }

  .card h1 { font-size: 1.5rem; }

  /* --- Buttons / actions --- */
  form > button { width: 100%; }

  .actions {
    flex-direction: column;
  }

  .actions .button,
  .actions button {
    width: 100%;
    justify-content: center;
  }

  /* --- Filters --- */
  .filters-grid { grid-template-columns: 1fr; }

  /* --- Invoice table — card stack layout --- */
  .table-stack,
  .table-stack tbody,
  .table-stack tr,
  .table-stack td {
    display: block;
    width: 100%;
  }

  .table-stack thead { display: none; }

  .table-stack tbody tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(2,8,23,0.05);
  }

  .table-stack tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    text-align: left !important;
  }

  .table-stack tbody td:last-child { border-bottom: none; }

  /* Column label from data-label attribute */
  .table-stack tbody td::before {
    content: attr(data-label);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    margin-right: 12px;
    white-space: nowrap;
  }

  /* Override fixed column widths for card-stack */
  .table-stack td:nth-child(n) { width: auto; }

  /* --- Pager --- */
  .pager { flex-direction: column; align-items: center; }

}

/* Audit log detail rows */
.detail-row td {
  background: #f8fafc;
  padding: 12px 16px;
}

.detail-json {
  margin: 0;
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-all;
}
