.cm-tool {
  --brand-orange: #FF6B35;
  --brand-orange-dark: #e85d26;
  --brand-navy: #1A1A2E;
  --brand-blue: #16213E;
  --text-primary: #333333;
  --text-secondary: #666666;
  --bg-white: #FFFFFF;
  --bg-light: #F8F9FA;
  --border: #E5E7EB;
  --success: #10B981;
  --warning: #F59E0B;
  --error: #EF4444;
  --input-border: #D1D5DB;
  --input-focus: #FF6B35;
}

.cm-tool * { box-sizing: border-box; margin: 0; padding: 0; }
.cm-tool { font-family: 'DM Sans', -apple-system, sans-serif; font-size: 16px; line-height: 1.7; color: var(--text-primary); background: transparent; padding: 0; }

/* ===== MOBILE-SAFE CONTRACT — DO NOT REMOVE ===== */
.cm-tool {
  max-width: 100%;
  overflow-x: hidden;
}

.cm-tool .calc-wrapper {
  width: min(720px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 24px;
}

.cm-tool .calc-wrapper * {
  min-width: 0;
}

.cm-tool input, .cm-tool select, .cm-tool textarea, .cm-tool button {
  max-width: 100%;
}

.cm-tool .action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.cm-tool .action-row > * {
  flex: 1 1 220px;
  min-width: 0;
}

.cm-tool .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.cm-tool .table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.cm-tool .calc-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 16px; min-width: 560px; }
.cm-tool .calc-table th { background: var(--brand-navy); color: white; padding: 10px 12px; text-align: left; font-weight: 600; }
.cm-tool .calc-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.cm-tool .calc-table tr:nth-child(even) td { background: var(--bg-light); }

.cm-tool pre, .cm-tool code, .cm-tool textarea, .cm-tool .output-box, .cm-tool .token-output {
  max-width: 100%;
  overflow-x: auto;
}

.cm-tool canvas, .cm-tool svg, .cm-tool img {
  max-width: 100%;
  height: auto;
}

.cm-tool .tab-bar {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
  background: var(--bg-light);
  padding: 4px;
  border-radius: 10px;
}

.cm-tool .tab-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  min-height: 44px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  font-family: inherit;
}

.cm-tool .tab-btn.active {
  background: white;
  color: var(--brand-orange);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.cm-tool .result-big {
  font-size: clamp(28px, 8vw, 48px);
  font-weight: 700;
  color: var(--brand-orange);
  line-height: 1.1;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 600px) {
  .cm-tool .calc-wrapper { padding: 16px; }

  .cm-tool .action-row {
    flex-direction: column;
  }

  .cm-tool .action-row > * {
    width: 100%;
  }

  .cm-tool .calc-btn {
    width: 100%;
    min-height: 44px;
  }

  .cm-tool .form-grid {
    grid-template-columns: 1fr;
  }
}
/* ===== END MOBILE-SAFE CONTRACT ===== */

/* Tool-specific styles */
.cm-tool input[type="number"], .cm-tool input[type="text"], .cm-tool select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--input-border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.cm-tool input:focus, .cm-tool select:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.cm-tool .calc-btn {
  background: var(--brand-orange);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  font-family: inherit;
  min-height: 48px;
}
.cm-tool .calc-btn:hover { background: var(--brand-orange-dark); }
.cm-tool .calc-btn:active { transform: scale(0.98); }
.cm-tool .calc-btn:disabled { background: #9CA3AF; cursor: not-allowed; }

.cm-tool .result-card {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-top: 20px;
}

.cm-tool .result-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.cm-tool .field-group {
  margin-bottom: 16px;
}

.cm-tool .field-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.cm-tool .field-hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
  line-height: 1.4;
}

.cm-tool .slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cm-tool .slider-row input[type="range"] {
  flex: 1;
}

.cm-tool .slider-row input[type="number"] {
  width: 90px;
  flex: 0 0 auto;
}

.cm-tool input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
}
.cm-tool input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--brand-orange);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.cm-tool .toggle-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: inherit;
  margin-top: 12px;
}
.cm-tool .toggle-btn:hover {
  border-color: var(--brand-orange);
  color: var(--brand-orange);
}
.cm-tool .toggle-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cm-tool .toggle-btn:disabled:hover { border-color: var(--border); color: var(--text-secondary); }

.cm-tool h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--brand-navy);
  margin-bottom: 20px;
}

/* Standardized textarea */
.cm-tool textarea {
  width: 100%;
  padding: 12px;
  border: 1.5px solid var(--input-border);
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.6;
  transition: border-color 0.2s;
  box-sizing: border-box;
  resize: vertical;
  min-height: 120px;
}
.cm-tool textarea:focus {
  outline: none;
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

/* ===== IMAGE-COMPRESSOR SPECIFIC ===== */

.cm-tool .drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  border: 2px dashed var(--input-border);
  border-radius: 12px;
  background: var(--bg-light);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}
.cm-tool .drop-zone.dragover {
  border-color: var(--brand-orange);
  background: #FFF5F0;
}
.cm-tool .drop-zone-icon {
  font-size: 40px;
  margin-bottom: 8px;
  color: var(--text-secondary);
  line-height: 1;
}
.cm-tool .drop-zone-text {
  font-size: 15px;
  color: var(--text-primary);
  margin-bottom: 4px;
  font-weight: 500;
}
.cm-tool .drop-zone-hint {
  font-size: 13px;
  color: var(--text-secondary);
}
.cm-tool .drop-zone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}
.cm-tool .drop-zone:focus-within { border-color: var(--brand-orange); }

/* Settings panel */
.cm-tool .settings-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  overflow: hidden;
}
.cm-tool .settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-light);
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-navy);
}
.cm-tool .settings-toggle {
  font-size: 14px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}
.cm-tool .settings-panel.open .settings-toggle {
  transform: rotate(180deg);
}
.cm-tool .settings-body {
  display: none;
  padding: 16px;
}
.cm-tool .settings-panel.open .settings-body {
  display: block;
}

.cm-tool .quality-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.cm-tool .quality-slider-row input[type="range"] {
  flex: 1;
}
.cm-tool .quality-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-orange);
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* File list */
.cm-tool .file-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cm-tool .file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  flex-wrap: wrap;
}

.cm-tool .file-thumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.cm-tool .file-thumb {
  width: 60px;
  height: 60px;
  border-radius: 6px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--bg-light);
  display: block;
}
.cm-tool .file-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-secondary);
}
.cm-tool .thumb-arrow {
  color: var(--text-secondary);
  font-size: 18px;
  flex: 0 0 auto;
}

.cm-tool .file-info {
  flex: 1 1 180px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cm-tool .file-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cm-tool .file-sizes {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}
.cm-tool .file-size-new {
  color: var(--brand-navy);
  font-weight: 600;
}

.cm-tool .file-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}
.cm-tool .file-status.error {
  color: var(--error);
}
.cm-tool .file-status.done {
  color: var(--success);
}

.cm-tool .reduction-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #FEF3C7;
  color: #92400E;
  margin-left: 6px;
}
.cm-tool .reduction-badge.good {
  background: #D1FAE5;
  color: #065F46;
}
.cm-tool .reduction-badge.negative {
  background: #FEE2E2;
  color: #991B1B;
}

.cm-tool .file-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.cm-tool .icon-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: inherit;
  min-height: 32px;
}
.cm-tool .icon-btn:hover {
  border-color: var(--brand-orange);
  color: var(--brand-orange);
}
.cm-tool .icon-btn.primary {
  background: var(--brand-orange);
  color: white;
  border-color: var(--brand-orange);
}
.cm-tool .icon-btn.primary:hover {
  background: var(--brand-orange-dark);
  color: white;
}
.cm-tool .icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.cm-tool .icon-btn:disabled:hover {
  border-color: var(--border);
  color: var(--text-secondary);
  background: none;
}
.cm-tool .icon-btn.primary:disabled:hover {
  background: var(--brand-orange);
  color: white;
}

/* Status message */
.cm-tool .status-msg {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  display: none;
}
.cm-tool .status-msg.success {
  display: block;
  background: #ECFDF5;
  color: #065F46;
  border: 1px solid #10B981;
}
.cm-tool .status-msg.error {
  display: block;
  background: #FEF2F2;
  color: #991B1B;
  border: 1px solid #EF4444;
}
.cm-tool .status-msg.info {
  display: block;
  background: #EFF6FF;
  color: #1E40AF;
  border: 1px solid #3B82F6;
}

.cm-tool .privacy-note {
  margin-top: 16px;
  padding: 10px 14px;
  background: #F0FDF4;
  border-left: 4px solid var(--success);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  color: #065F46;
  line-height: 1.5;
}

.cm-tool .summary-bar {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--bg-light);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  display: none;
}
.cm-tool .summary-bar.visible {
  display: block;
}
.cm-tool .summary-bar strong {
  color: var(--brand-navy);
  font-weight: 600;
}

@media (max-width: 600px) {
  .cm-tool .file-row {
    gap: 10px;
  }
  .cm-tool .file-info {
    flex: 1 1 100%;
    order: 3;
  }
  .cm-tool .file-actions {
    flex: 1 1 100%;
    order: 4;
  }
  .cm-tool .file-thumbs {
    order: 1;
  }
  .cm-tool .file-thumb {
    width: 48px;
    height: 48px;
  }
}
/* ===== UX ENHANCEMENT CLASSES (v1 retrofit — Apr 2026) ===== */
.cm-tool .ymyl-disclaimer {
  background: #FFFBEB;
  border-left: 4px solid var(--warning, #F79009);
  border-radius: 0 8px 8px 0;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  line-height: 1.5;
  color: #92400E;
}
.cm-tool .result-hero {
  text-align: center;
  padding: 24px;
}
.cm-tool .result-hero .result-big {
  font-size: clamp(32px, 10vw, 56px);
}
.cm-tool .result-hero .result-label {
  font-size: 14px;
  margin-bottom: 8px;
}
.cm-tool .result-secondary .result-big {
  font-size: 20px;
  color: var(--text-primary, #1F2330);
}
.cm-tool .field-hint {
  font-size: 13px;
  color: var(--text-secondary, #6B7280);
  margin-top: 4px;
  line-height: 1.4;
}
.cm-tool .live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--success, #0E8A46);
  font-weight: 500;
  margin: 16px 0;
}
.cm-tool .live-indicator::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success, #0E8A46);
  flex-shrink: 0;
}
/* ---- Respect prefers-reduced-motion: strip all animations + smooth
   transitions for users who've opted out at the OS level. Zero bytes
   to anyone who hasn't. ---- */
@media (prefers-reduced-motion: reduce) {
  .cm-tool *, .cm-tool *::before, .cm-tool *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Keyboard focus: visible outlines only for keyboard users (not for
   mouse clicks). Uses :focus-visible (supported in all browsers since 2022). ---- */
.cm-tool :focus { outline: none; }
.cm-tool :focus-visible {
  outline: 3px solid var(--input-focus);
  outline-offset: 2px;
  border-radius: 4px;
}
.cm-tool .calc-btn:focus-visible { outline-offset: 3px; }

/* ---- Print stylesheet: clean results for paper/PDF. Hide buttons, show
   full-width content, use standard black text. ---- */
@media print {
  .cm-tool { background: white !important; color: black !important; font-size: 12pt; }
  .cm-tool .calc-btn, .cm-tool .toggle-btn, .cm-tool button { display: none !important; }
  .cm-tool .calc-wrapper { padding: 0; max-width: 100%; }
  .cm-tool .result-card, .cm-tool .result-big, .cm-tool .result-hero {
    background: transparent !important;
    color: black !important;
    page-break-inside: avoid;
  }
  .cm-tool a { color: black !important; text-decoration: underline; }
  .cm-tool .data-stamp { border: 1px solid #999; page-break-inside: avoid; }
  .cm-tool input, .cm-tool select, .cm-tool textarea {
    border: 1px solid #999 !important;
    background: white !important;
    color: black !important;
  }
}

/* ===== SHARED ADDITIONS FOR THE IMAGE TOOL FAMILY ===== */
.cm-tool .file-dims { font-size: 12px; color: var(--text-secondary); }
.cm-tool .file-status { overflow-wrap: anywhere; }
.cm-tool .opt-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.cm-tool .opt-row > .field-group { flex: 1 1 200px; margin-bottom: 8px; }
.cm-tool .check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.cm-tool .check-row input[type="checkbox"] { width: 20px; height: 20px; flex: 0 0 auto; accent-color: var(--brand-orange); }
.cm-tool .check-row label { margin: 0; font-weight: 500; }
.cm-tool input[type="color"] { width: 56px; height: 44px; padding: 2px; border: 1.5px solid var(--input-border); border-radius: 8px; background: var(--bg-white); cursor: pointer; }
.cm-tool .file-actions .icon-btn { min-height: 40px; padding: 8px 14px; font-size: 13px; }
.cm-tool .panel { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-white); }
.cm-tool .panel-title { font-size: 14px; font-weight: 600; color: var(--brand-navy); margin-bottom: 12px; }

/* ===== IMAGE RESIZER ===== */
.cm-tool .stage-wrap { text-align: center; margin-top: 12px; }
.cm-tool .stage { position: relative; display: inline-block; line-height: 0; max-width: 100%; user-select: none; -webkit-user-select: none; background: var(--bg-light); border-radius: 6px; overflow: hidden; }
.cm-tool .stage img { display: block; max-width: 100%; max-height: 60vh; width: auto; height: auto; pointer-events: none; }
.cm-tool .crop-box { position: absolute; border: 2px solid #ffffff; outline: 1px solid rgba(0,0,0,0.45); box-shadow: 0 0 0 9999px rgba(0,0,0,0.5); cursor: move; touch-action: none; box-sizing: border-box; }
.cm-tool .crop-box:focus-visible { outline: 3px solid var(--brand-orange); }
.cm-tool .crop-handle { position: absolute; width: 28px; height: 28px; touch-action: none; }
.cm-tool .crop-handle::after { content: ""; position: absolute; width: 14px; height: 14px; background: #ffffff; border: 2px solid var(--brand-orange); border-radius: 3px; }
.cm-tool .crop-handle[data-h="nw"] { left: -14px; top: -14px; cursor: nwse-resize; }
.cm-tool .crop-handle[data-h="nw"]::after { left: 7px; top: 7px; }
.cm-tool .crop-handle[data-h="ne"] { right: -14px; top: -14px; cursor: nesw-resize; }
.cm-tool .crop-handle[data-h="ne"]::after { right: 7px; top: 7px; }
.cm-tool .crop-handle[data-h="sw"] { left: -14px; bottom: -14px; cursor: nesw-resize; }
.cm-tool .crop-handle[data-h="sw"]::after { left: 7px; bottom: 7px; }
.cm-tool .crop-handle[data-h="se"] { right: -14px; bottom: -14px; cursor: nwse-resize; }
.cm-tool .crop-handle[data-h="se"]::after { right: 7px; bottom: 7px; }
.cm-tool .file-line { font-size: 13px; color: var(--text-secondary); margin-top: 8px; overflow-wrap: anywhere; }
.cm-tool .dim-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.cm-tool .dim-row .field-group { flex: 1 1 120px; margin-bottom: 8px; }
.cm-tool .dim-x { padding-bottom: 18px; color: var(--text-secondary); }
.cm-tool .result-panel { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-light); }
.cm-tool .result-panel img { display: block; margin: 12px auto; max-height: 280px; width: auto; border: 1px solid var(--border); border-radius: 6px; background: repeating-conic-gradient(#e9e9e9 0% 25%, #ffffff 0% 50%) 50% / 16px 16px; }
.cm-tool .result-info { font-size: 14px; font-weight: 500; color: var(--brand-navy); overflow-wrap: anywhere; }


.cm-tool {
  --brand-orange: #17645f;
  --brand-orange-dark: #11524e;
  --brand-navy: #10302d;
  --brand-blue: #17645f;
  --text-primary: #10302d;
  --text-secondary: #4b5f5b;
  --bg-white: #fffdfa;
  --bg-light: #f6f2ec;
  --border: #e0d8cd;
  --input-border: #cfc5b8;
  --input-focus: #17645f;
  font-family: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text-primary);
}
.cm-tool .calc-wrapper { width: 100%; padding: 0; }
.cm-tool .calc-wrapper > h2:first-child { display: none; }
/* Result numbers were sized by screen width (8-10vw) inside half-width cards, so long figures
   like "₹1,98,88,715" overflowed and split mid-number. Size them to fit the card instead. */
.cm-tool .result-big { font-size: clamp(22px, 3.6vw, 42px); overflow-wrap: break-word; word-break: normal; font-variant-numeric: tabular-nums; }
.cm-tool .result-hero .result-big { font-size: clamp(26px, 4.4vw, 50px); }
