/* =========================================================
   T&T Cleaning Services — Invoice Generator & Archive
   Clean, friendly UI + Exact A4 Invoice Print Layout
   ========================================================= */

:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --border: #dde5ef;
  --text: #1b2838;
  --muted: #5f7085;
  --blue: #4a8bd1;
  --blue-dark: #3470b5;
  --blue-soft: #eaf2fb;
  --amber: #f0a818;
  --amber-soft: #fff6e0;
  --green: #1d9a5b;
  --green-soft: #e6f7ee;
  --red: #d64545;
  --red-soft: #fdecec;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(24, 48, 78, 0.06);
}

*, *::before, *::after {
  box-sizing: border-box;
}

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

/* ==================== Top Navigation ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(20, 40, 70, 0.04);
}

.topbar-inner {
  max-width: 1520px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-logo {
  height: 38px;
  width: auto;
  object-fit: contain;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 9px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.15s, color 0.15s;
}

.nav-tab:hover {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.nav-tab.active {
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.badge {
  background: #dce9f8;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-sm {
  font-size: 13px;
  padding: 6px 11px;
  border-radius: 7px;
}

.btn-lg {
  font-size: 15px;
  padding: 11px 18px;
}

.btn-primary {
  background: var(--blue);
  color: #ffffff;
}
.btn-primary:hover {
  background: var(--blue-dark);
}

.btn-secondary {
  background: #1b2838;
  color: #ffffff;
}
.btn-secondary:hover {
  background: #2c3e55;
}

.btn-accent {
  background: var(--amber-soft);
  color: #9e6500;
  border-color: #f3c86b;
}
.btn-accent:hover {
  background: #ffebc0;
}

.btn-outline {
  background: #ffffff;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover {
  border-color: #b5c6dc;
  background: #f8fafd;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover {
  background: #eef2f7;
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
}
.btn-danger-ghost:hover {
  background: var(--red-soft);
}

.btn-icon {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  background: #eef2f7;
  color: var(--text);
}

.btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==================== Layout & Cards ==================== */
.app-main {
  max-width: 1520px;
  margin: 0 auto;
  padding: 20px;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

/* ==================== Editor Split Layout ==================== */
.editor-layout {
  display: grid;
  grid-template-columns: minmax(420px, 560px) 1fr;
  gap: 24px;
  align-items: start;
}

.editor-banner {
  background: var(--amber-soft);
  border: 1px solid #f2c86a;
  color: #7c4f00;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
}

.form-row {
  margin-bottom: 12px;
}

.form-row:last-child {
  margin-bottom: 0;
}

.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #36475c;
  margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid #cdd8e6;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(74, 139, 209, 0.15);
}

textarea {
  resize: vertical;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

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

.grid-3 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.9fr;
  gap: 10px;
}

.quick-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 6px 0 12px;
}

.chips-label {
  font-size: 12px;
  color: var(--muted);
  margin-right: 2px;
}

.chip {
  border: 1px solid var(--border);
  background: #f7fafe;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover {
  background: var(--blue-soft);
  border-color: var(--blue);
}

/* Weekly Generator Drawer */
.weekly-box {
  background: #fffaf0;
  border: 1px dashed #e9b141;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}

.weekly-box-title {
  font-weight: 700;
  font-size: 14px;
  color: #8a5600;
}

.weekly-box-sub {
  margin: 2px 0 12px;
  font-size: 12.5px;
  color: #7c5c22;
}

.weekly-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* Preset Bar */
.preset-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.preset-bar select {
  flex: 1;
}

/* Line Items */
.items-header {
  display: grid;
  grid-template-columns: 1fr 96px 64px;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0 2px 6px;
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 96px 64px;
  gap: 8px;
  align-items: center;
}

.item-row-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.items-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.total-pill {
  font-size: 15px;
  background: var(--amber-soft);
  border: 1px solid #f0c259;
  color: #5b3b00;
  padding: 7px 14px;
  border-radius: 9px;
}

.total-pill strong {
  font-size: 18px;
  margin-left: 4px;
}

.action-bar {
  position: sticky;
  bottom: 12px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(20, 40, 70, 0.12);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==================== Live A4 Preview Pane ==================== */
.preview-pane {
  position: sticky;
  top: 78px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.preview-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.paper-wrap {
  display: flex;
  justify-content: center;
  padding-bottom: 24px;
}

/* ==================== EXACT A4 INVOICE SHEET ==================== */
.invoice-sheet {
  width: 100%;
  max-width: 794px;
  min-height: 1080px;
  background: #ffffff;
  color: #000000;
  font-family: Arial, Helvetica, sans-serif;
  padding: 58px 66px 54px;
  border: 1px solid #d7e0ea;
  box-shadow: 0 12px 34px rgba(18, 38, 63, 0.11);
  border-radius: 4px;
}

.inv-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.inv-logo-box img {
  max-width: 215px;
  max-height: 112px;
  width: auto;
  height: auto;
  display: block;
}

.inv-contact {
  text-align: right;
  font-weight: 700;
  font-size: 15.5px;
  line-height: 1.42;
  color: #000000;
  padding-top: 6px;
}

.inv-addresses {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
  font-size: 14.5px;
  line-height: 1.38;
}

.inv-client-block {
  max-width: 58%;
}

.inv-for-label {
  margin-bottom: 1px;
}

.inv-client-lines,
.inv-biz-address {
  white-space: pre-line;
}

.inv-biz-address {
  text-align: right;
  padding-top: 18px;
}

.inv-date-block {
  text-align: center;
  margin: 22px 0 24px;
}

.inv-date {
  font-size: 17px;
  font-weight: 400;
  color: #000000;
}

.inv-num-sub {
  font-size: 12.5px;
  color: #444444;
  margin-top: 3px;
}

/* Two-column separated table matching exact PDF layout */
.inv-table-head {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 18px;
  margin-bottom: 12px;
}

.inv-th {
  background: #9ec0e6;
  color: #ffffff;
  font-size: 14.5px;
  font-weight: 400;
  padding: 8px 10px;
  line-height: 1.3;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.inv-th-cost {
  text-align: center;
}

.inv-table-body {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 18px;
}

.inv-col-box {
  border: 2.5px solid #f0a818;
  background: #ffffff;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.inv-cell {
  min-height: 35px;
  padding: 8px 10px;
  font-size: 13.5px;
  line-height: 1.35;
  display: flex;
  align-items: center;
  word-break: break-word;
}

.inv-cell-alt {
  background: #efefef;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.inv-cell-cost {
  justify-content: center;
  text-align: center;
}

/* Total row */
.inv-total-row {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 18px;
  align-items: center;
  margin-top: 14px;
}

.inv-total-label {
  text-align: right;
  font-weight: 700;
  font-size: 15px;
  padding-right: 6px;
}

.inv-total-box {
  border: 2.5px solid #f0a818;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14.5px;
  font-weight: 400;
  background: #ffffff;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* Footer / Bank Details */
.inv-footer {
  margin-top: 38px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.48;
  color: #000000;
}

.inv-due-line {
  margin-top: 22px;
}

.inv-thanks {
  margin-top: 22px;
}

/* ==================== Archive, Clients & Settings ==================== */
.page-container {
  max-width: 1180px;
  margin: 0 auto;
}

.page-container.narrow {
  max-width: 760px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0;
  font-size: 24px;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

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

.kpi-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  margin: 4px 0 2px;
}

.kpi-amber {
  color: #b56f00;
}

.kpi-green {
  color: var(--green);
}

.kpi-sub {
  font-size: 12.5px;
  color: var(--muted);
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
}

.filter-bar input[type="search"] {
  flex: 1;
  min-width: 220px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-pill {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
}

.table-card {
  padding: 0;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f8fafd;
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: middle;
}

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

.data-table tr:hover td {
  background: #fafcff;
}

.data-table .num {
  text-align: right;
  font-weight: 700;
  white-space: nowrap;
}

.data-table .actions-col {
  text-align: right;
  white-space: nowrap;
}

.service-summary {
  max-width: 300px;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  border: none;
}

.status-paid {
  background: var(--green-soft);
  color: var(--green);
}

.status-unpaid {
  background: var(--amber-soft);
  color: #9e6200;
}

.status-overdue {
  background: var(--red-soft);
  color: var(--red);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 15px;
}

/* Clients Grid */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
}

.client-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.client-card-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.client-card-address {
  font-size: 13px;
  color: var(--muted);
  white-space: pre-line;
  margin-bottom: 8px;
}

.client-card-meta {
  font-size: 12.5px;
  color: #3d526b;
  background: #f6f9fd;
  border-radius: 8px;
  padding: 8px 10px;
}

.client-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid #eef2f7;
}

/* Settings */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.checkbox-row {
  display: flex;
  align-items: flex-end;
  padding-bottom: 8px;
}

.checkbox-label {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 0 !important;
}

.checkbox-label input {
  width: 17px;
  height: 17px;
}

.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.settings-logo-preview {
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: #ffffff;
}

.form-actions {
  margin-top: 20px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 28, 46, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: #ffffff;
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  padding: 20px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1b2838;
  color: #ffffff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
  z-index: 200;
}

/* ==================== Auth Overlay ==================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: linear-gradient(155deg, #eef4fc 0%, #f8fafd 55%, #fff8eb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-overlay[hidden] {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 28px;
  box-shadow: 0 18px 48px rgba(24, 48, 78, 0.12);
  text-align: center;
}

.auth-logo {
  height: 62px;
  width: auto;
  object-fit: contain;
  margin-bottom: 14px;
}

.auth-title {
  margin: 0 0 6px;
  font-size: 21px;
  font-weight: 800;
  color: var(--text);
}

.auth-sub {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--muted);
}

.auth-card form {
  text-align: left;
}

.auth-submit {
  width: 100%;
  margin-top: 10px;
}

.auth-error {
  background: var(--red-soft);
  color: var(--red);
  border: 1px solid #f5c2c2;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 14px;
  text-align: left;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ==================== Responsive ==================== */
@media (max-width: 1120px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }
  .preview-pane {
    position: static;
  }
}

@media (max-width: 700px) {
  .kpi-grid,
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .invoice-sheet {
    padding: 28px 20px;
    min-height: auto;
  }
  .inv-table-head,
  .inv-table-body,
  .inv-total-row {
    grid-template-columns: 1fr 84px;
    gap: 10px;
  }
}

/* ==================== EXACT A4 PRINT STYLES ==================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  body {
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .no-print,
  .topbar,
  .editor-form,
  .preview-toolbar,
  .modal-backdrop,
  .toast {
    display: none !important;
  }

  .app-main {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #tab-editor {
    display: block !important;
  }

  .editor-layout {
    display: block !important;
  }

  .preview-pane,
  .paper-wrap {
    position: static !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }

  .invoice-sheet {
    width: 210mm !important;
    max-width: none !important;
    min-height: 297mm !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 18mm 20mm 18mm 20mm !important;
    margin: 0 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
