/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0f1e;
  --bg2:       #111827;
  --bg3:       #1f2937;
  --bg4:       #374151;
  --accent:    #e85d26;
  --accent2:   #f97316;
  --accent-soft: rgba(232,93,38,.12);
  --blue:      #3b82f6;
  --green:     #22c55e;
  --yellow:    #eab308;
  --red:       #ef4444;
  --text:      #f9fafb;
  --text2:     #9ca3af;
  --text3:     #6b7280;
  --border:    #1f2937;
  --border2:   #374151;
  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.5);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --transition: .18s ease;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Typography ───────────────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.2; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: .95rem; font-weight: 600; }
p  { line-height: 1.6; color: var(--text2); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ── Nav ──────────────────────────────────────────────────────────────────── */
nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.25rem;
  background: rgba(10,15,30,.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}

.nav-logo {
  display: flex; align-items: center; gap: .6rem;
  font-weight: 800; font-size: 1.1rem; color: var(--text);
  text-decoration: none; letter-spacing: -.02em;
}

.nav-logo .logo-icon {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; box-shadow: 0 2px 8px rgba(232,93,38,.4);
}

.nav-logo .logo-trend {
  color: var(--accent); font-style: italic;
}

.nav-tabs {
  display: flex; gap: .2rem;
  background: var(--bg2); border-radius: 10px; padding: 3px;
  border: 1px solid var(--border);
}

.nav-tab {
  padding: .38rem .85rem; border-radius: 7px; border: none;
  background: transparent; color: var(--text2);
  font-size: .82rem; font-weight: 500; cursor: pointer;
  transition: var(--transition);
}

.nav-tab:hover { color: var(--text); background: var(--bg3); }
.nav-tab.active { background: var(--accent); color: #fff; font-weight: 600;
  box-shadow: 0 2px 8px rgba(232,93,38,.35); }

/* ── Main content ─────────────────────────────────────────────────────────── */
main { flex: 1; padding: 1.25rem 1rem; max-width: 680px; margin: 0 auto; width: 100%; }

/* ── Views ────────────────────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ── Hero ─────────────────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 2rem 0 1.5rem; }

.hero-badge {
  display: inline-flex; align-items: center; gap: .4rem;
  background: rgba(232,93,38,.1); border: 1px solid rgba(232,93,38,.25);
  color: var(--accent2); border-radius: 999px;
  padding: .28rem .85rem; font-size: .75rem; font-weight: 600;
  margin-bottom: 1rem; letter-spacing: .02em;
}

.hero h1 { margin-bottom: .5rem; }
.hero h1 span { color: var(--accent); }
.hero p { font-size: .95rem; margin-bottom: 1.75rem; }

/* ── Search ───────────────────────────────────────────────────────────────── */
.search-wrap { position: relative; margin-bottom: .5rem; }

.search-wrap .search-icon {
  position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
  color: var(--text3); pointer-events: none; font-size: 1rem;
}

#search-input {
  width: 100%; padding: .9rem 1rem .9rem 2.75rem;
  background: var(--bg2); border: 1.5px solid var(--border2);
  border-radius: var(--radius); color: var(--text);
  font-size: 1rem; outline: none; transition: var(--transition);
}

#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,93,38,.15); }
#search-input::placeholder { color: var(--text3); }

/* ── Autocomplete ─────────────────────────────────────────────────────────── */
#autocomplete {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); z-index: 200; display: none;
  max-height: 280px; overflow-y: auto;
}
#autocomplete.open { display: block; }

.ac-item {
  padding: .7rem 1rem; cursor: pointer;
  display: flex; align-items: center; gap: .75rem;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.focused { background: var(--bg3); }

.ac-item .ac-badge {
  background: var(--accent-soft); color: var(--accent2);
  border-radius: 5px; padding: .15rem .45rem;
  font-size: .7rem; font-weight: 700; flex-shrink: 0;
}
.ac-item .ac-name { font-weight: 600; font-size: .92rem; }
.ac-item .ac-region { font-size: .75rem; color: var(--text3); }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem 1.15rem;
  margin-bottom: .85rem;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .85rem;
}

/* ── Zone list ────────────────────────────────────────────────────────────── */
.zone-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1.1rem;
  margin-bottom: .6rem; cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem;
}
.zone-item:hover { border-color: var(--accent); background: rgba(232,93,38,.04); }
.zone-item .zone-info { flex: 1; min-width: 0; }
.zone-item .zone-info h3 {
  margin-bottom: .15rem; font-size: .92rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.zone-item .zone-info p { font-size: .78rem; margin: 0; }

.zone-badge {
  background: var(--bg3); color: var(--text2);
  border-radius: var(--radius-xs); padding: .18rem .5rem;
  font-size: .72rem; font-weight: 700; flex-shrink: 0;
}
.fascia-B { background: rgba(59,130,246,.15); color: #60a5fa; }
.fascia-C { background: rgba(34,197,94,.12); color: var(--green); }
.fascia-D { background: rgba(234,179,8,.12); color: var(--yellow); }
.fascia-E { background: rgba(239,68,68,.12); color: var(--red); }
.fascia-R { background: rgba(156,163,175,.1); color: var(--text2); }

/* ── Section title ────────────────────────────────────────────────────────── */
.section-title {
  font-size: .68rem; font-weight: 700; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text3); margin-bottom: .7rem;
}

/* ── Input row ────────────────────────────────────────────────────────────── */
.input-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; margin-bottom: .65rem;
}
.input-group { display: flex; flex-direction: column; gap: .3rem; }
.input-group label { font-size: .78rem; color: var(--text2); font-weight: 500; }
.input-group input {
  background: var(--bg3); border: 1.5px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  padding: .55rem .8rem; font-size: .95rem; outline: none;
  transition: border-color var(--transition);
}
.input-group input:focus { border-color: var(--accent); }

/* ── Condition items ──────────────────────────────────────────────────────── */
.condition-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 0; border-bottom: 1px solid var(--border);
  gap: .5rem;
}
.condition-item:last-child { border-bottom: none; }
.condition-left { display: flex; align-items: center; gap: .65rem; flex-shrink: 0; }
.condition-icon { font-size: 1.2rem; width: 1.8rem; text-align: center; }
.condition-label { font-size: .85rem; font-weight: 500; }
.condition-weight { font-size: .7rem; color: var(--text3); }

.condition-buttons { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }

.cond-btn {
  padding: .32rem .65rem; border-radius: var(--radius-xs);
  border: 1.5px solid var(--border2);
  background: transparent; color: var(--text2); font-size: .75rem;
  font-weight: 600; cursor: pointer; transition: var(--transition);
  white-space: nowrap;
}
.cond-btn:hover { border-color: var(--text2); color: var(--text); }
.cond-btn.ok   { background: rgba(34,197,94,.12);  border-color: var(--green);  color: var(--green); }
.cond-btn.bad  { background: rgba(239,68,68,.12);  border-color: var(--red);    color: var(--red); }
.cond-btn.na   { background: rgba(156,163,175,.08); border-color: var(--text3); color: var(--text3); }
.cond-btn.warn { background: rgba(234,179,8,.12);  border-color: var(--yellow); color: var(--yellow); }

/* Energy class buttons */
.energy-btn { padding: .28rem .4rem; min-width: 30px; font-size: .7rem; font-weight: 700; }

/* ── Result card ──────────────────────────────────────────────────────────── */
.result-card {
  background: linear-gradient(135deg, rgba(232,93,38,.12), rgba(249,115,22,.06));
  border: 1.5px solid rgba(232,93,38,.3);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: .85rem;
  text-align: center;
}
.result-label {
  font-size: .72rem; color: var(--text2); font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; margin-bottom: .4rem;
}
.result-value {
  font-size: 2.6rem; font-weight: 900; letter-spacing: -.04em;
  background: linear-gradient(135deg, #fff 30%, var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.result-range { font-size: .8rem; color: var(--text2); margin-top: .3rem; }

/* ── Range bar ────────────────────────────────────────────────────────────── */
.range-bar-wrap { margin: .85rem 0; }
.range-bar-track {
  height: 7px; background: var(--bg3); border-radius: 999px;
  position: relative; overflow: visible;
}
.range-bar-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--red), var(--yellow), var(--green));
  transition: width .5s cubic-bezier(.4,0,.2,1);
}
.range-bar-thumb {
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  transition: left .5s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.range-labels {
  display: flex; justify-content: space-between;
  font-size: .7rem; color: var(--text3); margin-top: .35rem;
}

/* ── Breakdown ────────────────────────────────────────────────────────────── */
.breakdown-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .45rem 0; border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-label { color: var(--text2); }
.breakdown-value { font-weight: 600; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .7rem 1.4rem; border-radius: var(--radius-sm); border: none;
  font-size: .88rem; font-weight: 600; cursor: pointer; transition: var(--transition);
  text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 3px 12px rgba(232,93,38,.35);
}
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover { background: var(--bg4); }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { background: rgba(239,68,68,.12); color: var(--red); border: 1px solid rgba(239,68,68,.25); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-full { width: 100%; }
.btn-sm { padding: .38rem .8rem; font-size: .78rem; }

/* ── Portfolio ────────────────────────────────────────────────────────────── */
.portfolio-empty { text-align: center; padding: 3rem 1rem; }
.portfolio-empty .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.portfolio-empty h2 { margin-bottom: .5rem; }

.portfolio-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: .7rem;
}
.portfolio-item-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: .7rem;
}
.portfolio-item-name { font-weight: 700; font-size: .95rem; margin-bottom: .15rem; }
.portfolio-item-meta { font-size: .75rem; color: var(--text2); }
.portfolio-item-value {
  font-size: 1.35rem; font-weight: 800;
  background: linear-gradient(135deg, #fff, var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.portfolio-trend {
  display: flex; align-items: center; gap: .3rem;
  font-size: .75rem; font-weight: 600; margin-top: .15rem;
}
.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }
.trend-flat { color: var(--text2); }
.chart-wrap { height: 180px; margin-top: .7rem; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: .65rem 1.1rem;
  font-size: .85rem; font-weight: 500; box-shadow: var(--shadow);
  transition: transform .3s cubic-bezier(.4,0,.2,1); z-index: 999;
  white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.success { border-color: var(--green); color: var(--green); }
#toast.error   { border-color: var(--red);   color: var(--red); }

/* ── Loading ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border2); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { text-align: center; padding: 2rem; }
.loading-wrap p { margin-top: .65rem; font-size: .85rem; }

/* ── Back button ──────────────────────────────────────────────────────────── */
.back-btn {
  display: inline-flex; align-items: center; gap: .35rem;
  color: var(--text2); font-size: .82rem; font-weight: 500;
  background: none; border: none; cursor: pointer; padding: 0;
  margin-bottom: 1.1rem; transition: color var(--transition);
}
.back-btn:hover { color: var(--accent); }

/* ── Semestre selector ────────────────────────────────────────────────────── */
.sem-select {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text);
  padding: .35rem .65rem; font-size: .82rem; outline: none; cursor: pointer;
}

/* ── Divider ──────────────────────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: .85rem 0; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ── Mobile touch ─────────────────────────────────────────────────────────── */
@media (hover: none) {
  * { -webkit-tap-highlight-color: transparent; }
  .zone-item:hover { background: var(--bg2); border-color: var(--border); }
  .btn-primary:hover { transform: none; }
  .cond-btn { min-height: 34px; }
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  h1 { font-size: 1.35rem; }
  .result-value { font-size: 2rem; }
  .input-row { grid-template-columns: 1fr; }
  nav { padding: .65rem .9rem; }
  .nav-tab { padding: .32rem .6rem; font-size: .76rem; }
  .hero { padding: 1.25rem 0 1rem; }
  .hero p { font-size: .88rem; margin-bottom: 1.25rem; }
  .condition-item { flex-wrap: wrap; }
  .condition-buttons { width: 100%; justify-content: flex-end; }
  .card { padding: .9rem; }
  #toast { bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); }
  #modal-overlay { align-items: flex-start; padding-top: 15vh; }
  .input-group input[type="number"] { font-size: 16px; }
}

@supports (padding: max(0px)) {
  nav { padding-top: max(.75rem, env(safe-area-inset-top)); }
  #toast { bottom: max(1.5rem, calc(env(safe-area-inset-bottom) + 1rem)); }
  main { padding-bottom: max(1.25rem, calc(env(safe-area-inset-bottom) + 1rem)); }
}
