:root {
  /* FROSTED Palette */
  --frost-navy: #29353C;
  --frost-steel: #44576D;
  --frost-slate: #768A96;
  --frost-ice: #AAC7D8;
  --frost-pale: #DFEBF6;
  --frost-mist: #E6E6E6;

  --bg-app: #F3F6F9;
  --surface: #FFFFFF;
  --border: #D5E0E8;
  --text: #1E272D;
  --text-muted: #5B6B76;
  --pos: #157347;
  --neg: #B02A37;
  --warn-bg: #FFF3CD;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--frost-navy);
  color: #FFFFFF;
  border-bottom: 3px solid var(--frost-ice);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-group { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 36px; height: 36px; border-radius: 9px; display: block; }
.brand-title-row { display: flex; align-items: baseline; gap: 7px; }
.brand-name { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.brand-by { font-size: 0.75rem; font-weight: 600; color: var(--frost-ice); }
.brand-sub { font-size: 0.72rem; color: var(--frost-pale); opacity: 0.85; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.privacy-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  background: rgba(223, 235, 246, 0.14);
  border: 1px solid rgba(170, 199, 216, 0.5);
  color: var(--frost-pale);
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}
.privacy-badge:hover { background: rgba(223, 235, 246, 0.24); }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: #4ADE80; }

.select-lang {
  background: rgba(255, 255, 255, 0.12) !important;
  color: #FFFFFF !important;
  border: 1px solid rgba(170, 199, 216, 0.45) !important;
  padding: 4px 8px !important;
  font-size: 0.74rem !important;
  font-weight: 600;
}
.select-lang option { color: var(--frost-navy); background: #FFFFFF; }

.plan-pill {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.plan-free { background: var(--frost-steel); color: var(--frost-pale); }
.plan-pro { background: var(--frost-ice); color: var(--frost-navy); }

.container {
  max-width: 1320px;
  width: 100%;
  margin: 14px auto 32px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  flex: 1;
}

.btn {
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 6px 10px; font-size: 0.76rem; }
.btn-primary { background: var(--frost-navy); color: #FFFFFF; }
.btn-primary:hover { background: var(--frost-steel); }
.btn-secondary { background: var(--frost-pale); color: var(--frost-navy); border: 1px solid var(--frost-ice); }
.btn-secondary:hover { background: var(--frost-ice); }
.btn-accent { background: var(--frost-ice); color: var(--frost-navy); }
.btn-accent:hover { background: #C3DCEB; }
.btn-ghost { background: transparent; color: var(--frost-steel); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--frost-pale); }
.btn-danger-ghost { background: transparent; color: var(--neg); border: 1px solid #F1C4C8; }
.btn-danger-ghost:hover { background: #FEE2E2; }

/* Upload Card (Full when empty, 1-row compact bar when loaded) */
.upload-card {
  background: var(--surface);
  border: 2px dashed var(--frost-slate);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}
.upload-card.dragover { border-color: var(--frost-navy); background: var(--frost-pale); }
.upload-icon {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--frost-pale);
  color: var(--frost-navy);
  font-weight: 700;
  font-size: 0.8rem;
  margin-bottom: 8px;
  border: 1px solid var(--frost-ice);
}
.upload-card h1 { margin: 0 0 4px; font-size: 1.12rem; color: var(--frost-navy); }
.upload-sub { margin: 0 auto 12px; max-width: 720px; font-size: 0.83rem; color: var(--text-muted); }
.upload-cta-row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.trust-strip {
  margin-top: 10px;
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--frost-steel);
}
.trust-strip span::before { content: "✓ "; color: var(--pos); font-weight: 700; }

.upload-card.compact {
  padding: 9px 14px;
  border-style: solid;
  border-width: 1px;
  border-color: var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  text-align: start;
}
.upload-card.compact .upload-icon,
.upload-card.compact h1,
.upload-card.compact .upload-sub,
.upload-card.compact .trust-strip {
  display: none;
}
.upload-card.compact .file-chips { margin-top: 0; }
.upload-card.compact .parse-status { margin-top: 0; min-height: 0; font-size: 0.78rem; }

.file-chips { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.file-chip {
  background: var(--frost-pale);
  color: var(--frost-navy);
  border: 1px solid var(--frost-ice);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.74rem;
  font-weight: 600;
}
.parse-status { margin-top: 6px; font-size: 0.79rem; color: var(--frost-steel); min-height: 16px; }
.parse-status.status-error { color: var(--neg); font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 960px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--frost-steel);
  border-radius: 9px;
  padding: 10px 13px;
}
.kpi-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; color: var(--frost-slate); }
.kpi-value { font-size: 1.28rem; font-weight: 700; color: var(--frost-navy); margin: 2px 0; }
.kpi-pos { color: var(--pos); }
.kpi-neg { color: var(--neg); }
.kpi-foot { font-size: 0.71rem; color: var(--text-muted); }

/* Category Breakdown Card */
.breakdown-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
}
.breakdown-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}
.breakdown-head h2 { margin: 0; font-size: 0.86rem; color: var(--frost-navy); }
.breakdown-sub { font-size: 0.72rem; color: var(--text-muted); }
.breakdown-bars { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 14px; }
.bar-item { display: flex; flex-direction: column; gap: 3px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 0.74rem; font-weight: 600; color: var(--frost-navy); }
.bar-track { height: 6px; border-radius: 999px; background: var(--frost-pale); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--frost-navy), var(--frost-steel)); }

.toolbar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.filters-row, .exports-row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }

.input, .select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 0.79rem;
  font-family: inherit;
  background: #FFFFFF;
  color: var(--text);
}
.input:focus, .select:focus { outline: 2px solid var(--frost-ice); border-color: var(--frost-steel); }
.checkbox-label { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; color: var(--text-muted); cursor: pointer; }
.export-label { font-size: 0.78rem; font-weight: 600; color: var(--frost-slate); }
.pro-tag { background: var(--frost-navy); color: var(--frost-pale); font-size: 0.62rem; padding: 1px 5px; border-radius: 4px; }

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.81rem; }
thead th {
  background: var(--frost-navy);
  color: #FFFFFF;
  text-align: start;
  padding: 9px 10px;
  font-weight: 600;
  font-size: 0.74rem;
  white-space: nowrap;
}
th.num, td.num { text-align: end; font-variant-numeric: tabular-nums; }
tbody td { padding: 7px 10px; border-bottom: 1px solid var(--frost-mist); vertical-align: middle; }
tbody tr:hover { background: #F8FAFC; }
tbody tr.dupe-row { background: var(--warn-bg); }
.empty-row td { text-align: center; padding: 32px 16px; color: var(--text-muted); }

.cell-input {
  width: 100%;
  min-width: 170px;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  color: inherit;
  padding: 3px 5px;
  border-radius: 5px;
}
.cell-input:focus { outline: none; border-color: var(--frost-ice); background: #FFFFFF; }
.cat-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.76rem;
  background: var(--frost-pale);
  color: var(--frost-navy);
  font-weight: 500;
}
.dupe-pill { display: inline-block; margin-inline-start: 6px; font-size: 0.65rem; font-weight: 700; background: #F59E0B; color: #FFFFFF; padding: 1px 5px; border-radius: 4px; }
.del-btn { background: transparent; border: none; color: var(--frost-slate); cursor: pointer; font-size: 1rem; padding: 2px 6px; border-radius: 4px; }
.del-btn:hover { background: #FEE2E2; color: var(--neg); }

.app-footer {
  background: var(--frost-navy);
  color: var(--frost-pale);
  padding: 12px 20px;
  font-size: 0.78rem;
  border-top: 2px solid var(--frost-steel);
}
.footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.footer-links { display: flex; gap: 16px; }
.footer-links a { color: var(--frost-ice); text-decoration: none; font-weight: 600; }
.footer-links a:hover { text-decoration: underline; }

/* Modals */
.modal-backdrop { position: fixed; inset: 0; background: rgba(25, 34, 40, 0.65); display: grid; place-items: center; padding: 20px; z-index: 50; }
.hidden { display: none !important; }
.modal-card {
  background: var(--surface);
  border-radius: 14px;
  border-top: 4px solid var(--frost-navy);
  max-width: 500px;
  width: 100%;
  padding: 20px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 1.06rem; color: var(--frost-navy); }
.icon-btn { background: none; border: none; font-size: 1.45rem; line-height: 1; color: var(--frost-slate); cursor: pointer; }
.modal-desc { margin: 0 0 10px; font-size: 0.85rem; color: var(--text-muted); }
.modal-list { margin: 0 0 14px; padding-inline-start: 18px; font-size: 0.83rem; }
.modal-list li { margin-bottom: 5px; }

.rules-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.rules-form .input { flex: 1; min-width: 160px; }
.rules-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.rule-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--frost-pale);
  border: 1px solid var(--frost-ice);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
}

.license-form label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--frost-navy); margin-bottom: 6px; }
.license-input-row { display: flex; gap: 8px; }
.license-input-row .input { flex: 1; }
.license-msg { margin-top: 8px; font-size: 0.8rem; min-height: 18px; }
.license-msg.ok { color: var(--pos); font-weight: 600; }
.license-msg.err { color: var(--neg); font-weight: 600; }
.modal-footer { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--frost-mist); display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* Styled Hover Tooltips */
[data-tip] {
  position: relative;
}
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 7px);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: #1B242A;
  color: #DFEBF6;
  border: 1px solid rgba(170, 199, 216, 0.45);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  padding: 6px 10px;
  border-radius: 7px;
  width: max-content;
  max-width: 240px;
  white-space: normal;
  z-index: 60;
  pointer-events: none;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}
[dir="rtl"] [data-tip]:hover::after {
  transform: translateX(50%);
}

/* Full Description Hover Popover */
.desc-wrap {
  position: relative;
  width: 100%;
}
.desc-popover {
  display: none;
  position: absolute;
  bottom: calc(100% + 4px);
  inset-inline-start: 0;
  background: #1B242A;
  color: #FFFFFF;
  border: 1px solid var(--frost-ice);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 0.78rem;
  line-height: 1.4;
  width: max-content;
  max-width: 420px;
  white-space: normal;
  word-break: break-word;
  z-index: 40;
  pointer-events: none;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
}
.desc-wrap:hover .desc-popover {
  display: block;
}
