:root {
  --roxo: #5B2E90;
  --roxo-2: #7C3AED;
  --roxo-3: #9D5CE6;
  --ciano: #12BEC4;
  --ciano-2: #06B6D4;
  --grad: linear-gradient(120deg, #5B2E90 0%, #7C3AED 45%, #12BEC4 120%);

  --bg: #F5F2EC;
  --bg-2: #EFEAE1;
  --card: #FFFFFF;
  --ink: #241B36;
  --ink-2: #6B6577;
  --line: #E7E1D6;

  --green: #16A34A;
  --green-bg: #16A34A18;
  --amber: #D9822B;
  --amber-bg: #D9822B18;
  --red: #DC2626;
  --red-bg: #DC262618;

  --radius: 16px;
  --shadow: 0 1px 2px rgba(36,27,54,.04), 0 8px 24px rgba(36,27,54,.06);
}

:root[data-theme="dark"] {
  --roxo: #9D7BE8;
  --roxo-2: #A88BF0;
  --roxo-3: #7C5FD0;
  --ciano: #22D3D8;
  --ciano-2: #2DD4DE;

  --bg: #14121C;
  --bg-2: #201C2C;
  --card: #1C1929;
  --ink: #ECE9F3;
  --ink-2: #9E98AE;
  --line: #302B40;

  --green: #34D07A;
  --green-bg: #34D07A1f;
  --amber: #F0A857;
  --amber-bg: #F0A8571f;
  --red: #F26D6D;
  --red-bg: #F26D6D1f;

  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
}

:root[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #241F32 25%, #2E2940 50%, #241F32 75%);
  background-size: 200% 100%;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}
.card, .kpi, .panel, .banner, header, .theme-toggle, .date-picker, table, th, td {
  transition: background-color .25s ease, border-color .25s ease, color .25s ease;
}

/* ---------- Header ---------- */
header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 16px 28px;
  display: flex; align-items: center; gap: 18px;
  flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.logo { display: flex; align-items: center; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; flex-shrink: 0; }
.brand-img { height: 40px; width: auto; display: block; flex-shrink: 0; }
.brand-txt { display: flex; flex-direction: column; }
.brand-name { font-size: 1.12rem; font-weight: 800; color: var(--ink);
  letter-spacing: -.02em; line-height: 1.1; }
.brand-sub { font-size: .72rem; color: var(--ink-2); margin-top: 3px; }

.theme-toggle {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  font-size: 1.05rem; display: inline-flex; align-items: center; justify-content: center;
  transition: filter .15s, transform .1s;
}
.theme-toggle:hover { filter: brightness(1.05); }
.theme-toggle:active { transform: scale(.94); }

/* ---------- Alerts bell ---------- */
.bell-wrap { position: relative; }
.bell-ic { width: 20px; height: 20px; display: block; }
.bell-head .bell-ic { width: 17px; height: 17px; }
.bell-btn {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--ink);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  font-size: 1.05rem; display: inline-flex; align-items: center; justify-content: center;
  position: relative; transition: filter .15s, transform .1s;
}
.bell-btn:hover { filter: brightness(1.05); }
.bell-btn:active { transform: scale(.94); }
.bell-btn.has-alert { border-color: var(--red); color: var(--red); }
.bell-badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px;
  padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff;
  font-size: .68rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px var(--card);
}
.bell-panel {
  position: absolute; top: 48px; right: 0; width: 340px; max-width: 88vw;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); z-index: 40; overflow: hidden;
}
.bell-head { padding: 13px 16px; font-weight: 700; font-size: .9rem;
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.bell-list { max-height: 360px; overflow-y: auto; }
.bell-item { display: block; padding: 12px 16px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit; transition: background .12s; }
.bell-item:last-child { border-bottom: none; }
.bell-item:hover { background: var(--bg-2); }
.bell-item-top { display: flex; justify-content: space-between; font-size: .86rem; }
.bell-item-top b { text-transform: capitalize; }
.bell-item-top span { color: var(--ink-2); font-size: .76rem; }
.bell-item-sub { font-size: .78rem; color: var(--red); margin-top: 3px; }
.bell-empty { padding: 26px 16px; text-align: center; color: var(--green); font-size: .85rem; }

/* ---------- Inverter detail modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,15,30,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal-box {
  background: var(--card); border-radius: 18px; width: 100%; max-width: 620px;
  max-height: 86vh; overflow-y: auto; box-shadow: 0 30px 70px rgba(0,0,0,.35);
  border: 1px solid var(--line);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0;
  background: var(--card); z-index: 1;
}
.modal-head h3 { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  border: none; background: var(--bg-2); color: var(--ink); width: 30px; height: 30px;
  border-radius: 8px; cursor: pointer; font-size: 1rem; display: flex;
  align-items: center; justify-content: center;
}
.modal-body { padding: 20px 22px; }
.modal-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; margin-bottom: 20px; }
.modal-kpi { background: var(--bg-2); border-radius: 12px; padding: 12px 14px; }
.modal-kpi .v { font-size: 1.15rem; font-weight: 800; }
.modal-kpi .k { font-size: .68rem; color: var(--ink-2); text-transform: uppercase; margin-top: 2px; }
.modal-status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 20px; font-size: .72rem; font-weight: 700; background: var(--green-bg); color: var(--green); }
.modal-section-title { font-size: .74rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--ink-2); margin: 18px 0 8px; }
.str-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.str-cell { background: var(--bg-2); border-radius: 8px; padding: 6px 4px; text-align: center; }
.str-cell .u { font-size: .72rem; font-weight: 700; color: var(--roxo-2); }
.str-cell .i { font-size: .68rem; color: var(--ciano-2); }
.str-cell .n { font-size: .6rem; color: var(--ink-2); }
.phase-row { display: flex; gap: 10px; }
.phase-cell { flex: 1; background: var(--bg-2); border-radius: 10px; padding: 10px 12px; text-align: center; }
.phase-cell .u { font-size: .9rem; font-weight: 700; color: var(--roxo-2); }
.phase-cell .i { font-size: .78rem; color: var(--ciano-2); margin-top: 2px; }
.phase-cell .n { font-size: .65rem; color: var(--ink-2); margin-top: 2px; }
.btn-detail {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--ink-2);
  border-radius: 7px; padding: 3px 9px; font-size: .72rem; cursor: pointer;
  font-family: inherit; transition: filter .12s;
}
.btn-detail:hover { filter: brightness(1.1); color: var(--ink); }

.header-tools { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.date-picker {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 12px;
}
.date-picker label { font-size: .78rem; color: var(--ink-2); font-weight: 600; }
.date-picker input {
  border: none; background: transparent; font-family: inherit;
  font-size: .85rem; color: var(--ink); font-weight: 600; cursor: pointer;
}
.date-picker input:focus { outline: none; }
.btn {
  border: none; border-radius: 10px; padding: 8px 14px; cursor: pointer;
  font-family: inherit; font-size: .82rem; font-weight: 600;
  background: var(--roxo); color: #fff; transition: filter .15s, transform .1s;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--bg-2); color: var(--ink); border: 1px solid var(--line); }

.live {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .78rem; font-weight: 600; color: var(--green);
}
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 0 0 rgba(22,163,74,.5); animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(22,163,74,.45); }
  70% { box-shadow: 0 0 0 8px rgba(22,163,74,0); }
  100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); }
}

/* ---------- Layout ---------- */
main { padding: 24px 28px 48px; max-width: 1400px; margin: 0 auto; }
.section-title {
  font-size: .8rem; font-weight: 700; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .06em; margin: 28px 0 14px;
}

/* ---------- Status banner ---------- */
.banner {
  display: flex; align-items: center; gap: 16px;
  border-radius: var(--radius); padding: 18px 22px; margin-bottom: 22px;
  border: 1px solid transparent;
}
.banner.ok { background: var(--green-bg); border-color: #16A34A33; }
.banner.warn { background: var(--amber-bg); border-color: #D9822B33; }
.banner .icon {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.banner.ok .icon { background: var(--green); color: #fff; }
.banner.warn .icon { background: var(--amber); color: #fff; }
.banner h2 { font-size: 1.15rem; font-weight: 700; }
.banner p { font-size: .85rem; color: var(--ink-2); margin-top: 2px; }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--grad); }
.kpi .val { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; }
.kpi .val small { font-size: .9rem; font-weight: 600; color: var(--ink-2); }
.kpi .lbl { font-size: .74rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; font-weight: 600; }

/* ---------- Chart panel ---------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow); margin-top: 16px;
}
.panel h3 { font-size: .95rem; font-weight: 700; margin-bottom: 4px; }
.panel .sub { font-size: .78rem; color: var(--ink-2); margin-bottom: 16px; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap.sm { height: 210px; }

/* ---------- Usina grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); text-decoration: none; color: inherit;
  display: block; transition: transform .15s, box-shadow .15s, border-color .15s;
}
.card:hover { transform: translateY(-3px); border-color: var(--roxo-3);
  box-shadow: 0 10px 30px rgba(91,46,144,.14); }
.card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-name { font-size: 1.02rem; font-weight: 700; text-transform: capitalize; }
.card-name .num { color: var(--ink-2); font-weight: 500; font-size: .85rem; }

.badge { font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .03em; }
.badge.online { background: var(--green-bg); color: var(--green); }
.badge.offline { background: var(--red-bg); color: var(--red); }
.chip { font-size: .66rem; font-weight: 600; padding: 2px 8px; border-radius: 6px;
  background: var(--bg-2); color: var(--ink-2); }
.chip.huawei { background: rgba(124,58,237,.14); color: var(--roxo-2); }
.chip.sungrow { background: rgba(18,190,196,.16); color: var(--ciano-2); }

.card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.m .v { font-size: 1.28rem; font-weight: 800; letter-spacing: -.02em; }
.m .v.roxo { color: var(--roxo-2); }
.m .v.ciano { color: var(--ciano-2); }
.m .v small { font-size: .72rem; font-weight: 600; color: var(--ink-2); }
.m .k { font-size: .68rem; color: var(--ink-2); text-transform: uppercase; margin-top: 2px; }
.card-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; font-size: .72rem; color: var(--ink-2); }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 6px; }
th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-2); font-weight: 700; padding: 9px 12px; border-bottom: 2px solid var(--line); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-2); }
.val-roxo { color: var(--roxo-2); font-weight: 700; }
.val-ciano { color: var(--ciano-2); font-weight: 700; }
.val-amber { color: var(--amber); font-weight: 600; }
.tag-inv { background: var(--bg-2); padding: 2px 9px; border-radius: 6px; font-weight: 600; font-size: .78rem; }

/* ---------- Skeleton / loading ---------- */
.skeleton { background: linear-gradient(90deg, #EDE8DF 25%, #F5F2EC 50%, #EDE8DF 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.sk-kpi { height: 92px; border-radius: var(--radius); }
.sk-card { height: 200px; border-radius: var(--radius); }
.sk-chart { height: 300px; border-radius: var(--radius); }

.spinner { width: 18px; height: 18px; border: 2px solid #ffffff66; border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; color: var(--ink-2); padding: 50px 20px; font-size: .9rem; }
.error { background: var(--red-bg); border: 1px solid #DC262633; color: #991B1B;
  border-radius: 12px; padding: 14px 18px; font-size: .85rem; }

.skid-block { margin-top: 22px; }
.skid-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.skid-head .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.skid-head h3 { font-size: 1rem; font-weight: 700; text-transform: capitalize; }

@media (max-width: 560px) {
  header { padding: 12px 16px; }
  main { padding: 16px 16px 40px; }
  .header-tools { width: 100%; }
}
