:root {
  --cw-blue: #026ccf;
  --cw-text: #212121;
  --cw-border: #cccccc;
  --cw-bg-gray: #f2f2f2;
  --cw-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);
  --brand-green: #29ad10;
  --error-red: #d32f2f;
}

/* --- GLOBAL RESET --- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: "Roboto", sans-serif;
  font-size: 13px;
  color: var(--cw-text);
  background-color: #ffffff;
  overflow-x: hidden;
}

/* --- MAIN CONTAINER --- */
.container {
  padding: 12px;
  max-width: 100%;
  position: relative;
}

/* --- HEADER --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e0e0e0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  height: 18px;
  width: auto;
  object-fit: contain;
}

.ticket-badge {
  font-size: 11px;
  color: #666;
  font-weight: 500;
  background-color: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
}

/* --- CONTEXT STRIP --- */
.context-strip {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  background: #fafbfc;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 14px;
}
.context-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.context-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #888;
}
.context-value {
  font-size: 12px;
  font-weight: 500;
  color: var(--cw-text);
}

/* --- MODE TABS --- */
.mode-tabs {
  display: flex;
  border-bottom: 1px solid var(--cw-border);
  margin-bottom: 12px;
}
.mode-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: all 0.15s;
  font-family: "Roboto", sans-serif;
}
.mode-tab:hover {
  color: var(--cw-text);
}
.mode-tab.active {
  color: var(--cw-blue);
  border-bottom-color: var(--cw-blue);
}

/* --- POD SECTIONS --- */
.pod-section {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e0e0e0;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: #616161;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- FORM ELEMENTS --- */
.grid-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}
.input-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}
label {
  display: block;
  font-weight: 500;
  margin-bottom: 3px;
  font-size: 11px;
  color: var(--cw-blue);
}
.std-input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--cw-border);
  border-radius: 2px;
  font-size: 12px;
  color: var(--cw-text);
  background-color: #ffffff;
  height: 28px;
  transition: border-color 0.2s;
  font-family: "Roboto", sans-serif;
}
.std-input:focus {
  outline: none;
  border-color: var(--cw-blue);
}
textarea.std-input {
  height: auto;
  min-height: 54px;
  resize: vertical;
}
.charge-readonly {
  background: #f5f7fa;
  color: #555;
}

/* --- LINK BUTTON --- */
.link-btn {
  background: none;
  border: none;
  color: var(--cw-blue);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}
.link-btn:hover {
  text-decoration: underline;
}

/* --- CHARGE BLOCKS --- */
.charge-block {
  border: 1px solid #e6e8eb;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #fff;
}
.charge-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.charge-block-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--cw-text);
}
.charge-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin: 0;
}
.charge-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  accent-color: var(--cw-blue);
}
.charge-toggle label {
  margin: 0;
}
.charge-hint {
  font-size: 10px;
  color: #888;
  line-height: 1.4;
  margin-top: 6px;
}
.charge-empty {
  font-size: 11px;
  color: #999;
  font-style: italic;
  padding: 8px 0;
  text-align: center;
}

/* --- PULLED PRODUCT ROWS --- */
.product-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.product-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #eee;
  border-radius: 4px;
  background: #fafbfc;
}
.product-row input[type="checkbox"] {
  accent-color: var(--cw-blue);
  cursor: pointer;
  flex-shrink: 0;
}
.product-row.excluded {
  opacity: 0.5;
}
.product-info {
  flex: 1;
  min-width: 0;
}
.product-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--cw-text);
}
.product-meta {
  font-size: 10px;
  color: #888;
}
.product-amount {
  font-size: 12px;
  font-weight: 600;
  color: var(--cw-text);
  white-space: nowrap;
}

/* --- MANUAL LINE ITEMS --- */
.line-item-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.line-item-row {
  display: grid;
  grid-template-columns: 1fr 48px 80px 20px;
  gap: 6px;
  align-items: center;
}
.line-item-row .std-input {
  margin: 0;
}
.line-item-remove {
  background: none;
  border: none;
  color: #888;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  font-weight: 700;
  padding: 0;
}
.line-item-remove:hover {
  color: var(--error-red);
}
.line-item-head {
  display: grid;
  grid-template-columns: 1fr 48px 80px 20px;
  gap: 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #999;
  margin-bottom: 2px;
}

/* --- HOURLY / FLAT FIELDS --- */
.hourly-fields,
.flat-fields {
  margin-top: 10px;
}
.hourly-row {
  display: flex;
  gap: 8px;
}
.hourly-row .input-group {
  flex: 1;
  margin-bottom: 8px;
}

/* --- TOTALS --- */
.totals-box {
  background: #fafbfc;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 4px;
}
.totals-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--cw-text);
}
.totals-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--brand-green);
}
.totals-note {
  font-size: 10px;
  color: #888;
  margin-top: 4px;
  line-height: 1.4;
}

/* --- EMAIL PREVIEW --- */
.email-preview-box {
  margin-top: 4px;
  background: #f8fafc;
  border: 1px dashed var(--cw-border);
  border-radius: 6px;
  padding: 12px;
  font-size: 11px;
  color: #666;
  line-height: 1.5;
}
.email-preview-title {
  color: var(--cw-text);
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
}
.preview-accent {
  color: var(--cw-blue);
  font-weight: 500;
}
.preview-muted {
  color: #444;
}
.preview-charges {
  margin: 4px 0;
}
.preview-charge-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  border-bottom: 1px dotted #e0e0e0;
  color: #444;
}
.preview-total-line {
  margin-top: 6px;
  color: var(--cw-text);
  font-size: 12px;
}

/* --- BUTTONS & STATUS --- */
.footer-actions {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.btn-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}
.status-msg {
  margin-top: 6px;
  font-size: 11px;
  min-height: 16px;
  text-align: right;
  width: 100%;
  font-weight: 500;
}
.status-error {
  color: var(--error-red);
}
.status-success {
  color: var(--brand-green);
}
.btn-base {
  height: 30px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 20px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  transition: all 0.2s ease;
}
.secondary-btn {
  background-color: #ffffff;
  color: var(--cw-text);
  border: 1px solid var(--cw-border);
}
.secondary-btn:hover {
  background-color: #f9f9f9;
  border-color: #999;
}
.primary-btn {
  background-color: var(--brand-green);
  color: white;
  border: 1px solid transparent;
}
.primary-btn:hover {
  background-color: #ffffff;
  color: var(--brand-green);
  border: 1px solid var(--brand-green);
}
.primary-btn:disabled {
  background-color: #b0b0b0;
  border-color: transparent;
  color: white;
  cursor: not-allowed;
}

/* --- IN-BUTTON LOADING SPINNER --- */
.btn-loading {
  pointer-events: none;
  opacity: 0.9;
}
.btn-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
  flex-shrink: 0;
}

/* --- HISTORY LOG --- */
.history-container {
  margin-top: 15px;
  border-top: 1px solid #e0e0e0;
  padding-top: 10px;
}
.history-header {
  font-size: 11px;
  font-weight: 700;
  color: #616161;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 12px;
}
.history-item:last-child {
  border-bottom: none;
}
.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.history-service {
  font-weight: 500;
  color: var(--cw-text);
  font-size: 12px;
  line-height: 1.3;
}
.history-line {
  font-size: 10px;
  color: #888;
  line-height: 1.4;
}
.history-amount {
  font-size: 12px;
  font-weight: 600;
  color: var(--cw-text);
  white-space: nowrap;
}
.history-status {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}
.status-sent {
  background-color: #e3f2fd;
  color: var(--cw-blue);
}
.status-approved {
  background-color: #e8f5e9;
  color: #2e7d32;
}
.status-declined {
  background-color: #fee2e2;
  color: #b91c1c;
}
.status-recorded {
  background-color: #ede9fe;
  color: #6d28d9;
}
.empty-history {
  font-size: 11px;
  color: #999;
  font-style: italic;
  padding: 8px 0;
  text-align: center;
}

/* --- MODAL --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-box {
  width: 90%;
  max-width: 340px;
  background-color: #ffffff;
  box-shadow: var(--cw-shadow);
  border: 1px solid var(--cw-border);
  padding: 20px 20px 12px 20px;
  display: flex;
  flex-direction: column;
}
.modal-header {
  font-size: 14px;
  color: var(--cw-blue);
  margin-bottom: 12px;
  font-weight: 500;
}
.modal-body {
  font-size: 13px;
  color: var(--cw-text);
  margin-bottom: 20px;
  line-height: 1.4;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-summary {
  background: #f8fafc;
  border: 1px solid #e6e8eb;
  border-radius: 6px;
  padding: 10px;
  margin-top: 10px;
  font-size: 12px;
}
.modal-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
}
.modal-summary-total {
  border-top: 1px solid #e0e0e0;
  margin-top: 4px;
  padding-top: 6px;
  font-weight: 700;
}

/* --- BRANDED SUCCESS VIEW --- */
.success-view {
  display: none;
  text-align: center;
  padding: 30px 15px;
  animation: fadeIn 0.4s ease;
}
.brand-success-icon {
  width: 64px;
  height: 64px;
  background: rgba(41, 173, 16, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  color: var(--brand-green);
}
.brand-success-icon svg {
  width: 32px;
  height: 32px;
}
.success-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--cw-text);
  margin: 0 0 8px 0;
  letter-spacing: -0.5px;
}
.success-desc {
  color: #666;
  font-size: 13px;
  margin-bottom: 24px;
  line-height: 1.5;
}
.progress-bar-container {
  width: 100%;
  height: 4px;
  background: #e0e0e0;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--brand-green);
  width: 100%;
}
#successView[style*="display: block"] .progress-bar-fill {
  animation: shrinkBar 4s linear forwards;
}
@keyframes shrinkBar {
  from {
    width: 100%;
  }
  to {
    width: 0%;
  }
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* --- TICKET-CLOSED MODAL --- */
.ticket-closed-box {
  max-width: 360px;
  padding-top: 24px;
}
.ticket-closed-icon {
  width: 56px;
  height: 56px;
  background: rgba(211, 47, 47, 0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  color: var(--error-red);
}
.ticket-closed-icon svg {
  width: 30px;
  height: 30px;
}

/* --- ELEGANT LOADER --- */
.pod-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 250px;
  height: 100vh;
  background-color: #ffffff;
}
.pod-loader .spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #f2f2f2;
  border-top-color: var(--cw-blue);
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  margin-bottom: 16px;
}
.pod-loader .loader-text {
  font-size: 12px;
  font-weight: 500;
  color: #666;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 420px) {
  .line-item-row,
  .line-item-head {
    grid-template-columns: 1fr 40px 70px 18px;
  }
}
