:root {
  --ct-teal: #167c73;
  --ct-teal-dark: #0f5c54;
  --ct-mint-bg: #f4f9f7;
  --ct-card: #ffffff;
  --ct-border: #c5dcd4;
  --ct-ink: #15383f;
  --ct-muted: #52706d;
  --ct-ok: #15803d;
  --ct-ok-bg: #dcfce7;
  --ct-err: #b91c1c;
  --ct-err-bg: #fee2e2;
  --ct-amber: #b45309;
  --ct-amber-bg: #fef3c7;
}

* { box-sizing: border-box; }

html, body.ct-sw-body {
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body.ct-sw-body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top right, #e2f4ee 0%, var(--ct-mint-bg) 52%, #edf5f2 100%);
  color: var(--ct-ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
.ct-sw-header {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: linear-gradient(135deg, #167c73, #0f5c54);
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(15, 92, 84, 0.22);
}

.ct-sw-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #ffffff;
  text-decoration: none;
}

.ct-sw-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #ffffff;
  color: var(--ct-teal);
  font-size: 20px;
  font-weight: 800;
  flex-shrink: 0;
}

.ct-sw-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.ct-sw-brand-text strong { font-size: 17px; font-weight: 800; letter-spacing: -0.2px; }
.ct-sw-brand-text small { font-size: 10.5px; opacity: 0.86; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; }

.ct-sw-header-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.ct-sw-nav-btn {
  display: inline-flex;
  align-items: center;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 700;
  transition: background 0.15s ease;
}

.ct-sw-nav-btn:hover { background: rgba(255, 255, 255, 0.25); }

/* Container */
.ct-sw-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px clamp(12px, 2.8vw, 28px) 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Company Bar */
.ct-sw-company-bar {
  background: var(--ct-card);
  border: 1.8px solid var(--ct-border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 6px 18px rgba(17, 58, 52, 0.05);
}

.ct-sw-meta-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  flex: 1 1 560px;
}

.ct-sw-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 135px;
  flex: 1 1 150px;
}

.ct-sw-field label {
  font-size: 11px;
  font-weight: 800;
  color: var(--ct-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ct-sw-field input,
.ct-sw-field select,
.ct-sw-field textarea,
.ct-sw-input {
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid #bcd4cc;
  border-radius: 8px;
  background: #fbfefd;
  color: var(--ct-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}

.ct-sw-field input:focus,
.ct-sw-field select:focus,
.ct-sw-input:focus {
  outline: none;
  border-color: var(--ct-teal);
  box-shadow: 0 0 0 3px rgba(22, 124, 115, 0.14);
  background: #ffffff;
}

.ct-sw-company-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

/* Module Tabs */
.ct-sw-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: #e5f1ed;
  border: 1.5px solid var(--ct-border);
  border-radius: 13px;
  padding: 6px;
}

.ct-sw-tab {
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: #1f4d47;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ct-sw-tab:hover { background: rgba(255, 255, 255, 0.72); }
.ct-sw-tab.active {
  background: var(--ct-teal);
  color: #ffffff;
  border-color: var(--ct-teal-dark);
  box-shadow: 0 4px 12px rgba(22, 124, 115, 0.24);
}

/* Status Banner */
.ct-sw-toast {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  border: 1.5px solid;
}
.ct-sw-toast.ok { background: var(--ct-ok-bg); color: #14532d; border-color: #86efac; }
.ct-sw-toast.err { background: var(--ct-err-bg); color: #7f1d1d; border-color: #fca5a5; }
.ct-sw-toast[hidden] { display: none; }

/* Panels & Cards */
.ct-sw-panel { display: none; flex-direction: column; gap: 16px; }
.ct-sw-panel.active { display: flex; }

.ct-sw-card {
  background: var(--ct-card);
  border: 1.8px solid var(--ct-border);
  border-radius: 15px;
  padding: 18px 20px;
  box-shadow: 0 6px 20px rgba(17, 58, 52, 0.05);
}

.ct-sw-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1.5px solid #e1efea;
}

.ct-sw-card-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--ct-ink);
}

.ct-sw-subtext {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ct-muted);
}

/* Buttons */
.ct-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid #b5cfc6;
  background: #f1f8f5;
  color: var(--ct-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.14s ease, background 0.14s ease;
}
.ct-btn:hover { background: #dfefe9; }
.ct-btn.primary {
  background: var(--ct-teal);
  border-color: var(--ct-teal-dark);
  color: #ffffff;
}
.ct-btn.primary:hover { filter: brightness(1.06); background: var(--ct-teal); }
.ct-btn.danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}
.ct-btn.danger:hover { background: #fee2e2; }
.ct-btn.sm { padding: 5px 10px; font-size: 11.5px; }

/* Voucher Type Pills */
.ct-vtype-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.ct-vtype-btn {
  padding: 8px 14px;
  border-radius: 9px;
  border: 1.8px solid var(--ct-border);
  background: #f6fbf9;
  color: var(--ct-ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.ct-vtype-btn small {
  display: inline-block;
  margin-right: 5px;
  padding: 1px 6px;
  border-radius: 5px;
  background: #dff0ea;
  color: var(--ct-teal-dark);
  font-size: 11px;
  font-weight: 800;
}
.ct-vtype-btn.active {
  background: #167c73;
  border-color: #0e564e;
  color: #ffffff;
}
.ct-vtype-btn.active small {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

/* Badges */
.ct-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  border: 1.5px solid;
}
.ct-pill.ok { background: var(--ct-ok-bg); color: #14532d; border-color: #86efac; }
.ct-pill.err { background: var(--ct-err-bg); color: #7f1d1d; border-color: #fca5a5; }
.ct-pill.info { background: #e5f5f0; color: #0e5c52; border-color: #9ed8c8; }

/* Tables */
.ct-table-wrap { overflow-x: auto; border: 1.5px solid #d4e6df; border-radius: 10px; background: #ffffff; }
.ct-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.ct-tbl th {
  background: #e6f4ef;
  color: #124943;
  font-weight: 800;
  text-align: left;
  padding: 9px 11px;
  border-bottom: 1.5px solid #c5dcd4;
  white-space: nowrap;
}
.ct-tbl td {
  padding: 8px 11px;
  border-bottom: 1px solid #ebf4f0;
  vertical-align: middle;
}
.ct-tbl tbody tr:last-child td { border-bottom: 0; }
.ct-tbl tbody tr:hover td { background: #f8fcfa; }
.ct-tbl tfoot td,
.ct-tbl tr.ct-total-row td {
  background: #eef7f4;
  font-weight: 800;
  border-top: 2px solid #9ecbc0;
  color: #103d37;
}
.ct-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ct-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* Grids */
.ct-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

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

.ct-stat-box {
  background: #f5faf8;
  border: 1.5px solid var(--ct-border);
  border-radius: 12px;
  padding: 14px 16px;
}
.ct-stat-box small {
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: var(--ct-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ct-stat-box strong {
  display: block;
  margin-top: 4px;
  font-size: 21px;
  font-weight: 800;
  color: var(--ct-ink);
  font-variant-numeric: tabular-nums;
}

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

.ct-gst-summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  background: #f1f8f5;
  border: 1.5px solid #bde0d4;
  border-radius: 10px;
}

.ct-gst-summary-strip div small {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--ct-muted);
}
.ct-gst-summary-strip div strong {
  font-size: 15px;
  font-weight: 800;
  color: var(--ct-teal-dark);
  font-variant-numeric: tabular-nums;
}

/* Tax Invoice Modal */
.ct-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(15, 42, 38, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.ct-modal-backdrop[hidden] { display: none; }

.ct-invoice-sheet {
  width: min(860px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #ffffff;
  border-radius: 14px;
  border: 2px solid var(--ct-border);
  padding: 24px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.ct-inv-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 2px solid #167c73;
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.ct-inv-words {
  margin-top: 12px;
  padding: 10px 12px;
  background: #f4f9f7;
  border: 1px solid #cde0da;
  border-radius: 8px;
  font-size: 12.5px;
}

@media print {
  body.ct-sw-body { background: #ffffff !important; }
  .no-print, .ct-sw-header, .ct-sw-company-bar, .ct-sw-tabs, .ct-sw-toast { display: none !important; }
  .ct-sw-shell { max-width: 100%; padding: 0; }
  .ct-sw-card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
  .ct-modal-backdrop { position: static; background: transparent; padding: 0; }
  .ct-invoice-sheet { border: 1px solid #333; box-shadow: none; max-height: none; width: 100%; }
}

/* Shared Analytics / Chart / Matrix Components */
.ct-svg-box {
  background: #ffffff;
  border: 1.5px solid #d4e6df;
  border-radius: 10px;
  padding: 12px;
  min-width: 0;
  overflow: hidden;
}
.ct-svg-box h3 {
  margin: 0 0 8px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--ct-teal-dark);
}
.ct-svg-box svg {
  width: 100%;
  height: auto;
  display: block;
}
.ct-apa-box {
  background: #eff8f5;
  border: 1.5px solid #9fd8c8;
  border-left: 5px solid var(--ct-teal);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13.5px;
  color: var(--ct-ink);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.ct-matrix-cell {
  min-width: 68px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.ct-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.ct-grid-2 > *, .ct-grid-3 > *, .ct-grid-4 > *,
.ct-grid-2 .ct-sw-field, .ct-grid-3 .ct-sw-field, .ct-grid-4 .ct-sw-field {
  min-width: 0;
}
.ct-sw-field input, .ct-sw-field select, .ct-sw-field textarea, .ct-sw-input {
  min-width: 0;
  max-width: 100%;
}
.ct-table-wrap {
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1024px) {
  .ct-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 10px; }
}

@media (max-width: 860px) {
  .ct-grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px; }
  .ct-gst-summary-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .ct-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

@media (max-width: 640px) {
  .ct-grid-2, .ct-t-account { grid-template-columns: 1fr !important; }
  .ct-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .ct-gst-summary-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ct-sw-header { padding: 8px 12px; gap: 8px; }
  .ct-sw-brand-text strong { font-size: 14.5px; }
  .ct-sw-brand-text small { font-size: 9.5px; }
  .ct-sw-header-nav {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }
  .ct-sw-header-nav::-webkit-scrollbar, .ct-sw-tabs::-webkit-scrollbar { display: none; }
  .ct-sw-nav-btn { white-space: nowrap; flex-shrink: 0; padding: 6px 10px; font-size: 11.5px; }
  .ct-sw-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ct-sw-tab { white-space: nowrap; flex-shrink: 0; padding: 7px 12px; font-size: 12px; }
  .ct-sw-shell { padding: 10px 10px 32px; gap: 12px; }
  .ct-sw-card { padding: 13px 12px; }
  .ct-sw-card-head h2 { font-size: 15px; }
  .ct-sw-meta-fields { flex-basis: 100%; }
  .ct-sw-company-bar .ct-sw-field { max-width: none !important; min-width: 0; flex: 1 1 44%; }
  #db-search { width: 100% !important; max-width: 100%; }
  .ct-invoice-sheet { padding: 14px; }
  .ct-inv-head { flex-direction: column; gap: 8px; }
}

@media (max-width: 440px) {
  .ct-grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
  .ct-grid-4 { grid-template-columns: 1fr !important; }
}

/* Mobile & Compact Landscape Optimization */
@media (max-height: 540px) and (orientation: landscape), (max-width: 960px) and (orientation: landscape) {
  .ct-sw-header {
    padding: 5px 10px;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .ct-sw-brand {
    min-width: 0;
    flex: 0 1 auto;
    max-width: 38%;
    overflow: hidden;
    gap: 7px;
  }
  .ct-sw-mark { width: 26px; height: 26px; font-size: 14px; border-radius: 7px; flex-shrink: 0; }
  .ct-sw-brand-text {
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }
  .ct-sw-brand-text strong {
    display: block;
    width: 100%;
    max-width: 100%;
    font-size: 12.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ct-sw-brand-text small { display: none; }
  .ct-sw-header-nav {
    flex: 1 1 0;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 4px;
    justify-content: flex-start;
  }
  .ct-sw-header-nav > a:first-child { margin-left: auto; }
  .ct-sw-header-nav::-webkit-scrollbar, .ct-sw-tabs::-webkit-scrollbar { display: none; }
  .ct-sw-nav-btn { white-space: nowrap; flex-shrink: 0; padding: 4px 7px; font-size: 10.5px; }
  .ct-sw-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px;
    gap: 4px;
  }
  .ct-sw-tab { white-space: nowrap; flex-shrink: 0; padding: 5px 9px; font-size: 11.5px; }
  .ct-sw-shell { padding: 8px 12px 24px; gap: 10px; }
  .ct-sw-card { padding: 11px 13px; border-radius: 11px; }
  .ct-sw-card-head { padding-bottom: 8px; margin-bottom: 10px; gap: 6px; }
  .ct-sw-card-head h2 { font-size: 14.5px; }
  .ct-sw-field label { font-size: 10px; }
  .ct-sw-field input, .ct-sw-field select, .ct-sw-field textarea, .ct-sw-input { padding: 5px 8px; font-size: 12.5px; }
  .ct-btn { padding: 6px 11px; font-size: 12px; }
  .ct-apa-box { padding: 8px 11px; font-size: 12.5px; }
  .ct-svg-box { padding: 8px 10px; }
  .ct-svg-box h3 { font-size: 12px; margin-bottom: 5px; }
  .ct-svg-box svg { max-height: 60dvh; width: 100%; height: auto; }
  .ct-stat-box { padding: 9px 11px; }
  .ct-stat-box strong { font-size: 17px; }
  .ct-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
}

@media (max-width: 740px) and (max-height: 540px) and (orientation: landscape) {
  .ct-sw-brand { max-width: 34%; gap: 6px; }
  .ct-sw-brand-text strong { font-size: 12px; }
  .ct-sw-nav-btn { padding: 4px 6px; font-size: 10px; }
}

