/* style.css
   Percentage Calculator — Final fix for mobile inline % label + full stylesheet
   Replace your existing CSS with this file and hard-refresh the browser.
*/

/* -------------------------
   Theme variables
   ------------------------- */
:root{
  --bg: #f8fafc;
  --surface: #ffffff;
  --muted: #6b7280;
  --text: #0f172a;
  --accent: #0f62fe;
  --accent-700: #0b52d6;
  --danger: #e11d48;
  --positive: #0b803a;
  --radius: 10px;
  --container-max: 980px;
  --card-padding: 20px;
  --focus-ring: 3px;
  --shadow: 0 6px 20px rgba(12, 18, 30, 0.06);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  font-size: 16px;
  color-scheme: light;
}

/* -------------------------
   Reset / base
   ------------------------- */
* { box-sizing: border-box; -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale; }
html,body { height: 100%; margin: 0; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
img, svg { max-width: 100%; height: auto; display: block; }

/* Defensive: stop rogue widths from other CSS */
html, body { max-width: 100%; overflow-x: hidden; }
*[style*="width:"] { max-width: 100% !important; }

/* Container */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 18px;
  box-sizing: border-box;
  overflow: visible;
}

/* Hero */
.tool-hero { padding: 28px 0 8px; }
.tool-hero h1 { margin: 0 0 6px; font-size: 30px; line-height: 1.05; }
.tool-hero .lead { margin: 0; color: var(--muted); font-size: 15px; }

/* Card layout */
.tool-card {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--card-padding);
  box-shadow: var(--shadow);
  align-items: start;
  max-width: 100%;
  overflow: visible;
}
.tool-card, .calc-block, .tool-aside { max-width: 100vw; }

/* Calc block */
.calc-block {
  background: #fbfdff;
  border-radius: 10px;
  padding: 14px;
  border: 1px solid #eef3ff;
  margin-bottom: 14px;
}
.calc-block h3 { margin: 0 0 10px; font-size: 16px; color: var(--text); }

/* Row layout - desktop baseline */
.calc-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: nowrap;
  width: 100%;
}

/* Inputs */
.calc-row input[type="number"],
.calc-row input[type="text"] {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #e6e9ee;
  background: #fff;
  font-size: 15px;
  line-height: 1;
  flex: 1 1 180px;
  min-width: 100px;
  max-width: none;
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  height: 44px;
}
.calc-row input::placeholder { color: #99a0b3; }
.calc-row input:focus {
  outline: none;
  border-color: var(--accent-700);
  box-shadow: 0 0 0 var(--focus-ring) rgba(11,82,214,0.08);
}
/* Remove spinner space on webkit */
.calc-row input::-webkit-inner-spin-button,
.calc-row input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Labels between inputs */
.calc-label {
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f3f6fb;
  border: 1px solid #e6e9ee;
  font-weight: 600;
  color: var(--muted);
  font-size: 14px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.calc-text {
  color: var(--muted);
  font-size: 14px;
  margin: 0 6px;
  flex: 0 0 auto;
}

/* Calculate button (desktop) */
.calc-btn {
  flex: 0 0 120px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15,98,254,0.12);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
  font-weight: 700;
  font-size: 15px;
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  align-self: center;
}
.calc-btn:hover { transform: translateY(-2px); background: var(--accent-700); box-shadow: 0 10px 28px rgba(11,82,214,0.12); }
.calc-btn:active { transform: translateY(0); box-shadow: 0 6px 18px rgba(11,82,214,0.08); }
.calc-btn:focus { outline: none; box-shadow: 0 0 0 var(--focus-ring) rgba(11,82,214,0.12); }

/* Result area */
.calc-result {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #e9f0ff;
  font-weight: 700;
  color: var(--text);
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  overflow: visible;
}
.calc-result .result-left {
  display:flex;
  flex-direction: column;
  gap:6px;
  align-items: flex-start;
  flex: 1 1 auto;
  min-width: 0;
}
.calc-result .result-left .main {
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-interpretation {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  margin-left: 0;
}
.result-positive .result-left .main { color: var(--positive); }
.result-negative .result-left .main { color: var(--danger); }

/* Actions (copy/swap) */
.result-actions { display: flex; gap: 8px; align-items: center; flex: 0 0 auto; }
.copy-result-btn, .swap-btn-inline {
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid #e6e9ee;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  box-shadow: none;
  transition: background .12s ease, color .12s ease, transform .08s ease;
}
.copy-result-btn:hover, .swap-btn-inline:hover { background: #fbfdff; color: var(--text); transform: translateY(-1px); }
.copy-result-btn:focus, .swap-btn-inline:focus { outline: none; box-shadow: 0 0 0 var(--focus-ring) rgba(11,82,214,0.08); }
.copy-result-btn { margin-left: 12px; }

/* Aside / examples */
.tool-aside {
  padding: 12px;
  border-radius: 8px;
  background: linear-gradient(180deg,#ffffff,#fbfdff);
  border: 1px solid #eef3ff;
}
.tool-aside h3 { margin: 0 0 8px; font-size: 16px; }
.examples { list-style: none; padding: 0; margin: 6px 0 0; display:flex; flex-direction:column; gap:8px; }
.examples li { list-style: none; }
.examples .example, .examples .example-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(6,10,20,0.06);
  background: #fff;
  color: var(--accent-700);
  cursor: pointer;
  font-weight: 600;
  text-align: left;
  max-width: 220px;
}
.examples .example:hover, .examples .example-btn:hover { background: rgba(15,98,254,0.04); transform: translateY(-1px); }

/* -------------------------
   MOBILE FIX: key changes to avoid the big gap around the % pill
   - Use a 3-column grid for rows that have a center label (like %)
   - Keep fallback to stacked layout for other rows if not enough width
*/

/* Force single-column earlier to avoid sidebar overflow */
@media (max-width: 900px) {
  .tool-card {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
    padding: 12px !important;
  }
  .tool-aside { order: 2 !important; margin-top: 12px !important; }
}

/* Mobile grid for calc-row when it contains a center label */
@media (max-width: 520px) {
  .container { padding-left: 12px; padding-right: 12px; }

  /* If developer added .has-center-label use inline grid so % pill sits between inputs */
  .calc-row.has-center-label {
    display: grid;
    grid-template-columns: 1fr auto 1fr; /* input - label - input inline */
    gap: 8px;
    align-items: center;
    width: 100%;
  }

  /* Fallback: generic rows stack vertically */
  .calc-row:not(.has-center-label) {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  /* Inputs: fixed height, full width in grid cells */
  .calc-row.has-center-label input[type="number"],
  .calc-row.has-center-label input[type="text"],
  .calc-row:not(.has-center-label) input[type="number"],
  .calc-row:not(.has-center-label) input[type="text"] {
    flex: none !important;
    width: 100%;
    max-width: 100%;
    height: 44px;
    padding: 10px 12px;
    line-height: 1.2;
  }

  /* Label pill styling when inline */
  .calc-row.has-center-label .calc-label {
    justify-self: center;
    align-self: center;
    padding: 8px 10px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    border-radius: 8px;
  }

  /* Button becomes full width under the row */
  .calc-row.has-center-label .calc-btn,
  .calc-row:not(.has-center-label) .calc-btn {
    grid-column: 1 / -1;
    width: 100% !important;
    margin-top: 6px;
    flex: none;
    align-self: stretch;
    height: 44px;
    border-radius: 8px;
  }

  /* Result stacks neatly */
  .calc-result {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .calc-result .result-actions { order: 1; display:flex; justify-content:flex-end; gap:8px; }
  .calc-result .result-left { order: 0; }

  /* Examples adjust */
  .examples .example, .examples .example-btn { max-width: 100%; width: 140px; }
}

/* Ensure that if you cannot add .has-center-label in HTML, this fallback will still improve visuals:
   make .calc-label inline and small instead of block, so it won't push layout as much */
@media (max-width: 520px) {
  .calc-row .calc-label {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 6px 8px;
    height: 36px;
  }
}

/* Very small screens */
@media (max-width: 420px) {
  .calc-row { gap: 8px; }
  .calc-btn { width: 100%; padding: 12px; border-radius: 10px; box-shadow: 0 6px 12px rgba(15,98,254,0.08); }
  .copy-result-btn { padding: 8px 10px; }
}

/* Inline errors / seo / accessibility */
.inline-error { color: var(--danger); font-size: 13px; margin-top: 6px; }
.seo-section { margin-top: 18px; padding: 18px; background: transparent; color: var(--muted); }
.seo-section h2 { margin-top: 0; font-size: 18px; color: var(--text); }
.visually-hidden { position: absolute !important; height: 1px; width: 1px; overflow: hidden; clip: rect(1px,1px,1px,1px); white-space: nowrap; border: 0; padding: 0; margin: -1px; }
[aria-invalid="true"] { box-shadow: 0 0 0 var(--focus-ring) rgba(225,29,72,0.06); border-color: var(--danger); }

/* Print */
@media print {
  .tool-aside, .examples, .calc-btn, .copy-result-btn, .swap-btn-inline { display: none !important; }
  .calc-block { border: none; box-shadow: none; background: transparent; }
}
