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

html {
  overflow-x: hidden;
}

body {
  font-family: 'Inter', sans-serif;
  background: #f4f6f9;
  color: #1a1a2e;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header { background: #1a1a2e; padding: 14px 20px; }
.header-inner { display: flex; align-items: center; gap: 16px; }
.logo { font-size: 1.2rem; font-weight: 700; color: #fff; white-space: nowrap; }
.header-sub { color: #a0aec0; font-size: 0.8rem; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
main {
  max-width: 1350px;
  margin: 0 auto;
  padding: 20px 16px;
  width: 100%;
}

/* ── Card base ───────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  padding: 20px;
  width: 100%;
  min-width: 0;   /* critical: prevents flex/grid children from overflowing */
}

/* ── Summary cards ───────────────────────────────────────────────────────── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.summary-card { text-align: center; padding: 18px 12px; }
.card-label { font-size: 0.78rem; color: #718096; font-weight: 500; margin-bottom: 6px; }
.card-value { font-size: 1.35rem; font-weight: 700; margin-bottom: 4px; word-break: break-word; }
.card-sub   { font-size: 0.72rem; color: #a0aec0; }
.green  { color: #38a169; }
.blue   { color: #3182ce; }
.orange { color: #dd6b20; }

/* ── Desktop grid ────────────────────────────────────────────────────────── */
.content-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
  min-width: 0;
}
.right-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;       /* prevents chart overflow */
}
.tab-content {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Params ──────────────────────────────────────────────────────────────── */
.params-panel h2 { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.subtitle { font-size: 0.78rem; color: #718096; margin-bottom: 16px; }
.section-title { font-size: 0.78rem; font-weight: 700; color: #4a5568; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
hr { border: none; border-top: 1px solid #e2e8f0; margin: 14px 0; }
.param-group { margin-bottom: 14px; }
.param-group > label { display: flex; justify-content: space-between; font-size: 0.82rem; font-weight: 500; margin-bottom: 5px; color: #4a5568; }
.field-hint { font-size: 0.72rem; color: #a0aec0; margin-top: 4px; }

.input-row { display: flex; align-items: center; gap: 8px; }
.input-row input[type="range"] { flex: 1; min-width: 0; }

input[type="range"] {
  -webkit-appearance: none; width: 100%; height: 5px;
  border-radius: 3px; background: #e2e8f0; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: #1a1a2e; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.num-input {
  width: 68px; padding: 5px 6px; border: 1px solid #e2e8f0; border-radius: 6px;
  font-size: 0.82rem; font-family: 'Inter', sans-serif; font-weight: 600;
  text-align: right; color: #1a1a2e; background: #f7fafc; outline: none;
  -moz-appearance: textfield;
}
.num-input:focus { border-color: #3182ce; background: #fff; }
.num-input::-webkit-outer-spin-button,
.num-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.unit { font-size: 0.78rem; color: #718096; font-weight: 500; min-width: 20px; }

.toggle-group { margin-bottom: 10px; }
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.82rem; font-weight: 500; color: #4a5568; }
.toggle-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: #1a1a2e; flex-shrink: 0; }

.tax-section { margin-top: 4px; }
.tax-info { background: #f0f4ff; border-left: 3px solid #3182ce; border-radius: 6px; padding: 10px 12px; margin-top: 10px; font-size: 0.78rem; }
.tax-info ul { list-style: none; }
.tax-info li { margin-bottom: 3px; color: #4a5568; }
.tax-table-mini { margin-top: 8px; border-top: 1px solid #bee3f8; padding-top: 8px; }
.ttm-row { display: flex; justify-content: space-between; font-size: 0.74rem; padding: 2px 0; color: #4a5568; }
.ttm-row.header { font-weight: 700; color: #2b6cb0; font-size: 0.7rem; text-transform: uppercase; }
.tax-note { font-size: 0.68rem; color: #a0aec0; margin-top: 6px; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 9px 20px; border: none; border-radius: 8px; font-family: 'Inter', sans-serif;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  background: #e2e8f0; color: #718096; transition: all 0.15s; flex: 1; text-align: center;
}
.tab.active { background: #1a1a2e; color: #fff; }
.tab:hover:not(.active) { background: #cbd5e0; }

/* ── Buckets ─────────────────────────────────────────────────────────────── */
.buckets-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 8px; }
.buckets-header h2 { font-size: 0.95rem; font-weight: 700; }
.btn-add {
  background: #ebf8ff; color: #2b6cb0; border: 1px solid #bee3f8;
  padding: 6px 14px; border-radius: 6px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; font-family: 'Inter', sans-serif; white-space: nowrap;
}
.btn-add:hover { background: #bee3f8; }
.bucket-item {
  border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px;
  margin-bottom: 12px; background: #fafafa;
}
.bucket-item:last-child { margin-bottom: 0; }
.bucket-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.bucket-color { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.bucket-type-select {
  flex: 1; padding: 7px 10px; border: 1px solid #e2e8f0; border-radius: 6px;
  font-family: 'Inter', sans-serif; font-size: 0.85rem; font-weight: 600;
  color: #1a1a2e; background: #fff; cursor: pointer; outline: none; min-width: 0;
}
.btn-remove {
  background: none; border: none; color: #a0aec0; font-size: 1.1rem;
  cursor: pointer; padding: 2px 6px; border-radius: 4px;
}
.btn-remove:hover { color: #e53e3e; }
.bucket-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.bucket-field label { font-size: 0.72rem; font-weight: 700; color: #718096; display: block; margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.03em; }
.bucket-field .num-input { width: 100%; text-align: right; }
.bucket-tax-badge { font-size: 0.72rem; color: #718096; margin-top: 10px; }
.bucket-tax-badge span { font-weight: 600; }
.bucket-notes {
  font-size: 0.72rem; color: #718096; margin-top: 5px;
  padding: 5px 8px; background: #f7fafc; border-radius: 5px;
  border-left: 3px solid #e2e8f0; display: none;
}
.bucket-notes.visible  { display: block; }
.bucket-notes.tax-free { border-left-color: #38a169; color: #276749; background: #f0fff4; }
.bucket-notes.has-tf   { border-left-color: #3182ce; color: #2c5282; background: #ebf8ff; }

/* ── Chart ───────────────────────────────────────────────────────────────── */
.chart-card { padding: 20px 16px 14px; }
.chart-card h2 { font-size: 0.95rem; font-weight: 700; margin-bottom: 16px; }
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 290px;
  min-width: 0;    /* prevent overflow */
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.table-header h2 { font-size: 0.95rem; font-weight: 700; }
.btn-export {
  background: #1a1a2e; color: #fff; border: none; padding: 7px 14px;
  border-radius: 6px; font-size: 0.78rem; cursor: pointer;
  font-family: 'Inter', sans-serif; font-weight: 500;
}
.btn-export:hover { background: #2d3748; }
.table-scroll { overflow: auto; max-height: 320px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
thead th {
  background: #f7fafc; color: #718096; font-weight: 600; text-align: right;
  padding: 9px 12px; position: sticky; top: 0; z-index: 1;
  border-bottom: 2px solid #e2e8f0; white-space: nowrap;
}
thead th:first-child { text-align: left; }
tbody tr { border-bottom: 1px solid #f0f0f0; }
tbody tr:hover { background: #f7fafc; }
tbody td { padding: 8px 12px; text-align: right; white-space: nowrap; }
tbody td:first-child { text-align: left; font-weight: 600; }
.td-gain     { color: #38a169; }
.td-tax      { color: #e53e3e; }
.td-after    { color: #3182ce; font-weight: 600; }
.td-real     { color: #dd6b20; font-weight: 600; }
.td-depleted { color: #e53e3e; font-style: italic; }

.depletion-banner {
  background: #fff5f5; border-left: 4px solid #e53e3e; border-radius: 6px;
  padding: 10px 14px; font-size: 0.82rem; color: #c53030; font-weight: 600; margin-top: 12px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 1100px) {
  .content-grid { grid-template-columns: 260px 1fr; }
}

/* ── Single column ──────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  main { padding: 14px 12px; }

  .summary-cards { grid-template-columns: 1fr 1fr; }
  #real-card { grid-column: 1 / -1; }

  .content-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
  .right-col    { order: 2; width: 100%; }
  .params-panel { order: 1; width: 100%; }

  .bucket-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Phone ──────────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  header { padding: 10px 12px; }
  .logo { font-size: 1rem; }
  .header-sub { font-size: 0.7rem; display: none; }

  main { padding: 10px 8px; }

  /* Summary 2x2 */
  .summary-cards { gap: 6px; margin-bottom: 12px; }
  .summary-card { padding: 10px 6px; }
  .card-value { font-size: 0.95rem; }
  .card-label { font-size: 0.66rem; }
  .card-sub   { font-size: 0.62rem; }

  /* Cards compact */
  .card { padding: 12px 10px; border-radius: 10px; }

  /* Tabs */
  .tab { padding: 9px 6px; font-size: 0.78rem; }

  /* Mobile content order inside tab */
  .tab-content { gap: 12px; }
  .chart-card   { order: 1; }
  .buckets-card { order: 2; }
  .table-card   { order: 3; }

  /* Chart - must not overflow */
  .chart-card { padding: 10px 8px 8px; }
  .chart-card h2 { font-size: 0.88rem; margin-bottom: 10px; }
  .chart-wrapper { height: 200px; }

  /* Buckets stacked */
  .bucket-grid { grid-template-columns: 1fr; gap: 8px; }
  .bucket-item { padding: 10px 8px; }

  /* Hide sliders — number inputs only */
  .input-row input[type="range"] { display: none; }
  .num-input {
    width: 100%; text-align: left; font-size: 0.88rem;
    padding: 8px 10px; border-radius: 8px; background: #fff;
    border: 1.5px solid #e2e8f0;
  }
  .unit { font-size: 0.8rem; min-width: 24px; }

  /* Table */
  .table-scroll { max-height: 220px; }
  table { font-size: 0.7rem; }
  thead th { padding: 6px 8px; font-size: 0.66rem; }
  tbody td { padding: 5px 8px; }
  .btn-export { font-size: 0.76rem; padding: 7px 10px; }

  /* Params */
  .params-panel h2 { font-size: 0.88rem; }
  .tax-table-mini { display: none; }
}

@media (max-width: 360px) {
  .summary-cards { grid-template-columns: 1fr; }
  #real-card { grid-column: unset; }
  .card-value { font-size: 0.88rem; }
  .tab { font-size: 0.72rem; padding: 8px 4px; }
}
