/* =========================================================
   DESIGN TOKENS
   ========================================================= */
:root {
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Size scale */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 15px;
  --text-lg: 18px;
  --text-xl: 22px;
  --text-2xl: 28px;

  /* Text colors (deep sea navy) */
  --text-primary: #0f2a3a;
  --text-secondary: #46606f;
  --text-muted: #7a909c;

  /* Surfaces (sea mist) */
  --bg-page: #eef6f9;
  --bg-card: #ffffff;
  --bg-input: #f6fafc;
  --border-soft: #d8e6ec;
  --border-input: #c5d8e0;

  /* Accent (ocean teal) */
  --accent: #0e7490;
  --accent-dark: #0b5a70;
  --accent-soft: #e0f2f7;
  --accent-ring: rgba(14, 116, 144, .18);

  /* Status */
  --success: #1f8a70;
  --success-soft: #dff3ec;
  --warning: #b45309;
  --danger: #b42318;

  --shadow-card: 0 1px 3px rgba(15, 60, 90, .07);
  --shadow-hover: 0 6px 16px rgba(14, 116, 144, .15);
}

/* =========================================================
   BASE TYPOGRAPHY
   ========================================================= */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text-primary);
  background: var(--bg-page);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4 {
  margin: 0 0 .5em;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
h1 { font-size: var(--text-2xl); font-weight: 700; }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }

p { margin: 0 0 1em; color: var(--text-secondary); }
small, .text-sm { font-size: var(--text-sm); }
.text-muted { color: var(--text-muted); }

input, button, select, textarea {
  font-family: inherit;
  font-size: inherit;
}
input[type="checkbox"] { accent-color: var(--accent); }

.num, table td, .amount { font-variant-numeric: tabular-nums; }

.page-title { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.02em; margin-bottom: 4px; }
.page-subtitle { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: 24px; }

/* =========================================================
   LAYOUT
   ========================================================= */
.content { max-width: 1400px; margin: 0 auto; }
.billing-container { padding: 30px; }

/* =========================================================
   NAVBAR
   ========================================================= */
.nav {
  height: 64px;
  padding: 0 30px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.nav-left, .nav-right { display: flex; align-items: center; gap: 24px; }

.nav-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); }
.nav-logo-icon { font-size: 22px; }
.nav-logo-text { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  font-size: var(--text-sm); font-weight: 500;
  color: var(--text-primary); text-decoration: none;
  border-radius: 8px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--accent-soft); color: var(--accent); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  position: relative;
}
.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}
.nav-chevron { color: var(--text-muted); }

.nav-badge {
  background: var(--accent-soft); color: var(--accent);
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px;
}

.nav-search {
  display: flex; align-items: center; gap: 10px;
  width: 260px; padding: 0 16px; height: 40px;
  background: #f3eee7; border-radius: 999px;
  border: 1px solid transparent;
}
.nav-search:focus-within { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.nav-search input {
  flex: 1; border: 0; outline: 0; background: transparent;
  font-size: var(--text-sm); color: var(--text-primary);
}

.nav-login { font-size: var(--text-sm); color: var(--text-primary); text-decoration: none; }
.nav-login:hover { color: var(--accent); }
.nav-signup {
  padding: 9px 16px; font-size: var(--text-sm); font-weight: 500;
  color: var(--accent); text-decoration: none;
  border: 1px solid var(--accent); border-radius: 8px;
  transition: background .15s, color .15s;
}
.nav-signup:hover { background: var(--accent); color: #fff; }

.btn-primary {
  background: var(--accent); color: #fff;
  padding: 9px 16px; border-radius: 8px;
  text-decoration: none; font-weight: 600; font-size: var(--text-sm);
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-dark); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: var(--text-sm);
}

@media (max-width: 1100px) { .nav-links { display: none; } }
@media (max-width: 700px)  { .nav-search { display: none; } }

/* =========================================================
   BILLING
   ========================================================= */
.bl-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  align-items: start;
}

.bl-card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}
.bl-card-title {
  font-size: var(--text-xs); font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); margin-bottom: 12px;
}
.bl-row { display: flex; gap: 12px; }

.bl-input, .bl-select {
  width: 100%; padding: 10px 12px; font-size: var(--text-sm);
  color: var(--text-primary);
  border: 1px solid var(--border-input); border-radius: 8px;
  background: var(--bg-input);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.bl-input::placeholder { color: var(--text-muted); }
.bl-input:focus, .bl-select:focus {
  outline: none; background: #fff;
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.bl-input.small { width: 90px; }
.bl-select { width: auto; padding: 8px 10px; }
.bl-select.warn { border-color: #e0a33a; }

.bl-chips, .bl-pay { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.bl-chip {
  padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border-soft); background: #fff;
  border-radius: 999px; color: var(--text-secondary);
  transition: background .15s, color .15s, border-color .15s;
}
.bl-chip:hover { background: var(--accent-soft); color: var(--accent); }
.bl-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.bl-services { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.bl-service {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 14px; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid var(--border-soft); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s, transform .05s;
}
.bl-service:hover { border-color: var(--accent); box-shadow: var(--shadow-hover); }
.bl-service:active { transform: scale(.98); }
.bl-service-name { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.bl-service-cat { font-size: var(--text-xs); color: var(--text-muted); }
.bl-service-price { font-size: var(--text-base); font-weight: 700; color: var(--accent); margin-top: 4px; }

.bl-bill { position: sticky; top: 16px; }
.bl-empty { text-align: center; padding: 24px 0; }
.bl-item { padding: 10px 0; border-bottom: 1px solid #f1ebe0; }
.bl-item-top { display: flex; justify-content: space-between; font-size: var(--text-sm); margin-bottom: 8px; }
.bl-item-bottom { display: flex; align-items: center; gap: 10px; }
.bl-qty { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.bl-qty button {
  width: 26px; height: 26px; border: 1px solid var(--border-input); background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--text-primary);
}
.bl-qty button:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.bl-remove { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: var(--text-sm); }
.bl-remove:hover { color: var(--danger); }

.bl-divider { height: 1px; background: var(--border-soft); margin: 14px 0; }
.bl-line {
  display: flex; justify-content: space-between; align-items: center;
  font-size: var(--text-sm); padding: 5px 0; color: var(--text-secondary);
}
.bl-check { cursor: pointer; }
.bl-discount { display: flex; gap: 8px; align-items: center; }
.bl-total { font-size: 20px; font-weight: 700; color: var(--text-primary); padding-top: 10px; }
.bl-warn { color: var(--warning); font-size: 13px; margin: 8px 0 0; }

.bl-save {
  width: 100%; margin-top: 12px; padding: 14px;
  font-size: var(--text-base); font-weight: 600;
  color: #fff; background: var(--accent);
  border: 0; border-radius: 10px; cursor: pointer;
  transition: background .15s;
}
.bl-save:hover:not(:disabled) { background: var(--accent-dark); }
.bl-save:disabled { background: var(--accent); cursor: not-allowed; opacity: 0.65;}

@media (max-width: 1000px) {
  .bl-grid { grid-template-columns: 1fr; }
  .bl-bill { position: static; }
}
@media (max-width: 600px) {
  .bl-row { flex-direction: column; }
  .billing-container { padding: 16px; }
  .nav { padding: 0 16px; }
}

.bl-field {
  flex: 1;
  display: flex;
  flex-direction: column;
}

label.bl-error-text {
  color: #ef4444;
  font-size: 12px;
  font-weight: 500;
  margin-top: 5px;
  display: block;
}

input.bl-error-text, select.bl-error-text {
  border-color: #ef4444 !important;
  background-color: #fff5f5 !important;
}


/* =========================================================
   PRINT BILL BUTTON
   ========================================================= */
.bl-print-btn {
  width: 100%; margin-top: 10px; padding: 12px;
  font-size: var(--text-sm); font-weight: 600;
  color: var(--accent); background: var(--accent-soft);
  border: 1.5px solid var(--accent); border-radius: 10px;
  cursor: pointer; transition: background .15s, color .15s;
}
.bl-print-btn:hover { background: var(--accent); color: #fff; }

/* =========================================================
   THERMAL PRINT STYLES — 80mm Receipt
   ========================================================= */

/* Hide receipt on screen */
.print-receipt { display: none; }

@media print {
  /* Hide everything on the page except the receipt */
  body * { visibility: hidden !important; }
  .print-receipt,
  .print-receipt * { visibility: visible !important; }

  /* Position the receipt */
  .print-receipt {
    display: block !important;
    position: fixed;
    top: 0; left: 0;
    width: 72mm;
    font-family: 'Courier New', Courier, monospace;
    font-size: 10.5pt;
    color: #000;
    background: #fff;
    padding: 4mm 4mm 10mm 4mm;
  }

  /* 80mm paper, auto height — no margins */
  @page {
    size: 80mm auto;
    margin: 0;
  }

  /* Header */
  .rcp-header    { text-align: center; margin-bottom: 6px; }
  .rcp-logo      { font-size: 14pt; font-weight: 900; letter-spacing: 1px; margin-bottom: 3px; }
  .rcp-sub       { font-size: 8.5pt; color: #333; line-height: 1.5; }

  /* Divider line */
  .rcp-divider   { font-size: 8pt; color: #555; margin: 5px 0; }

  /* Bill meta info */
  .rcp-meta      { font-size: 9pt; margin: 6px 0; }
  .rcp-meta div  { display: flex; justify-content: space-between; padding: 1px 0; }

  /* Items table */
  .rcp-table     { width: 100%; border-collapse: collapse; font-size: 9pt; margin: 4px 0; }
  .rcp-table th  {
    text-align: left;
    border-bottom: 1px dashed #000;
    padding: 3px 0;
    font-size: 8.5pt;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  .rcp-table td  { padding: 4px 0; vertical-align: top; }
  .rcp-table td:nth-child(2) { text-align: center; }
  .rcp-table td:last-child,
  .rcp-table th:last-child   { text-align: right; }

  /* Totals */
  .rcp-totals     { font-size: 9.5pt; margin: 4px 0; }
  .rcp-totals div { display: flex; justify-content: space-between; padding: 2px 0; }
  .rcp-total-line {
    font-size: 13pt !important;
    font-weight: 900;
    border-top: 1.5px solid #000;
    border-bottom: 3px double #000;
    padding: 5px 0 !important;
    margin-top: 4px;
  }

  /* Footer */
  .rcp-footer { text-align: center; font-size: 9pt; margin-top: 10px; }
}

.bill-history-btn {
  display: block;
  margin-left: auto;

  background: #2563eb;
  color: #ffffff;

  padding: 10px 18px;
  border: none;
  border-radius: 8px;

  font-size: 14px;
  font-weight: 600;
  cursor: pointer;

  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  position: relative;
  top: 4px;
}

.bill-history-btn:hover {
  background: #1d4ed8;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
  transform: translateY(-1px);
}

.bill-history-btn:active {
  transform: translateY(0);
}

.bill-history-btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.billing-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.billing-title-row .page-title {
  margin: 0;
}

.history-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.5);
}

.history-modal {
  width: 100%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-card, #fff);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-soft, #e2e8f0);
}

.history-header h2 {
  margin: 0;
  font-size: 22px;
}

.history-header button {
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #f1f5f9;
  color: #334155;
  cursor: pointer;
}

.history-header button:hover {
  background: #e2e8f0;
}

.history-header button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}

.history-body {
  min-height: 0;
  overflow-y: auto;
  padding: 8px 24px 24px;
}

.history-group {
  padding-top: 20px;
}

.history-group + .history-group {
  margin-top: 20px;
  border-top: 1px solid var(--border-soft, #e2e8f0);
}

.history-group h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted, #64748b);
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 70px;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid var(--border-soft, #e2e8f0);
  border-radius: 10px;
}

.history-item + .history-item {
  margin-top: 8px;
}

.history-item span:first-child {
  overflow-wrap: anywhere;
  font-weight: 500;
}

.history-item span:nth-child(2) {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history-item .history-payment {
  text-align: right;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--text-muted, #64748b);
}

@media (max-width: 480px) {
  .history-overlay {
    padding: 12px;
  }

  .history-header {
    padding: 16px;
  }

  .history-body {
    padding: 8px 16px 16px;
  }

  .history-item {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 12px;
  }

  .history-item .history-payment {
    grid-column: 1 / -1;
    text-align: left;
  }
}

.history-item {
  grid-template-columns: minmax(0, 1fr) auto 70px auto;
}

.history-edit-btn {
  padding: 8px 14px;
  border: 1px solid var(--accent, #087e9b);
  border-radius: 8px;
  background: #fff;
  color: var(--accent, #087e9b);
  font-weight: 600;
  cursor: pointer;
}

.history-edit-btn:hover {
  background: var(--accent-soft, #e0f2fe);
}

.history-edit-btn:focus-visible {
  outline: 2px solid var(--accent, #087e9b);
  outline-offset: 3px;
}

.history-edit-btn:disabled,
.bl-save:disabled {
  opacity: 0.6;
  cursor: wait;
}

@media (max-width: 480px) {
  .history-item {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .history-item .history-payment {
    grid-column: 1;
  }

  .history-edit-btn {
    grid-column: 2;
  }
}
