/* ── Variables ────────────────────────────────────────────── */
:root {
  --bg:          #0B0E1A;
  --sidebar-bg:  #0F1221;
  --surface:     #151929;
  --surface-2:   #1B2035;
  --border:      #242B42;
  --border-sub:  rgba(255,255,255,0.04);

  --text:        #EEF2FF;
  --muted:       #6B7A99;
  --muted-2:     #404A65;

  --accent:      #F97316;
  --accent-h:    #FB923C;
  --accent-dim:  rgba(249,115,22,0.12);

  --green:       #22C55E;
  --green-dim:   rgba(34,197,94,0.12);
  --red:         #EF4444;
  --red-dim:     rgba(239,68,68,0.12);
  --blue:        #3B82F6;
  --blue-dim:    rgba(59,130,246,0.12);
  --yellow:      #F59E0B;
  --yellow-dim:  rgba(245,158,11,0.12);
  --purple:      #A855F7;
  --purple-dim:  rgba(168,85,247,0.12);
  --teal:        #14B8A6;
  --teal-dim:    rgba(20,184,166,0.12);

  --sidebar-w:   222px;
  --topbar-h:    58px;
  --r:           12px;
  --r-sm:        8px;
  --r-lg:        18px;

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

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

body {
  height: 100vh;
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App Layout ───────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-brand {
  padding: 18px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -.5px;
}

.brand-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background .13s, color .13s;
  font-family: inherit;
}

.nav-item:hover {
  background: rgba(255,255,255,0.045);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: .7;
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: var(--r-sm);
  background: rgba(255,255,255,0.03);
  min-width: 0;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.user-email {
  font-size: 0.75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.logout-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
}

.logout-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ── Main area ────────────────────────────────────────────── */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  padding: 0 22px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}

.page-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

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

/* ── Alert wrap ───────────────────────────────────────────── */
.alert-wrap {
  padding: 0 22px;
  flex-shrink: 0;
}

.alert-wrap .alert-box:not(.hidden) {
  margin-top: 10px;
}

/* ── Content area ─────────────────────────────────────────── */
.content-area {
  flex: 1;
  overflow: hidden;
  padding: 16px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tab-content {
  display: none;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tab-content.active {
  display: flex;
}

/* ── Stats row ────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 11px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px 14px;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 16px; height: 16px; }

.si-green  { background: var(--green-dim);  color: var(--green); }
.si-orange { background: var(--accent-dim); color: var(--accent); }
.si-blue   { background: var(--blue-dim);   color: var(--blue); }
.si-purple { background: var(--purple-dim); color: var(--purple); }
.si-red    { background: var(--red-dim);    color: var(--red); }
.si-teal   { background: var(--teal-dim);   color: var(--teal); }

.stat-body {
  min-width: 0;
  flex: 1;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-meta {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Dashboard lower ──────────────────────────────────────── */
.dash-lower {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-fill {
  flex: 1;
  min-height: 0;
}

.card-grow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.card-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.card-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  padding: 14px 16px;
}

/* ── Badge ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.on  { background: var(--green-dim);  color: var(--green); }
.badge.off { background: var(--red-dim);    color: var(--red); }
.badge.run { background: var(--blue-dim);   color: var(--blue); }

/* ── Info list ────────────────────────────────────────────── */
.info-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-sub);
  font-size: 0.8rem;
  gap: 8px;
}

.info-row:last-child { border-bottom: none; }

.info-label {
  color: var(--muted);
  flex-shrink: 0;
}

.info-row span:last-child {
  text-align: right;
  color: var(--text);
  font-weight: 500;
}

/* ── Simple list ──────────────────────────────────────────── */
.simple-list {
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.list-item {
  padding: 9px 11px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-sub);
}

.list-title {
  font-weight: 500;
  font-size: 0.8rem;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-meta {
  color: var(--muted);
  font-size: 0.72rem;
}

/* log colors */
.log-erro   { border-left: 3px solid var(--red);    }
.log-sucesso{ border-left: 3px solid var(--green);  }
.log-aviso  { border-left: 3px solid var(--yellow); }
.log-info   { border-left: 3px solid var(--blue);   }

/* ── Buttons ──────────────────────────────────────────────── */
button { font-family: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border-radius: var(--r-sm);
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .13s ease;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  color: #fff;
}

.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger {
  background: var(--red-dim);
  border: 1px solid rgba(239,68,68,0.18);
  color: var(--red);
  padding: 3px 9px;
  font-size: 0.72rem;
}

/* legacy – used in channel chips rendered by JS */
.ghost-btn {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(239,68,68,0.2);
  background: var(--red-dim);
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .13s;
  font-family: inherit;
}

.ghost-btn:hover { opacity: .8; }

/* legacy – used in login page */
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 11px 20px;
  border-radius: var(--r-sm);
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-h));
  color: #fff;
  transition: filter .13s;
  font-family: inherit;
  margin-bottom: 12px;
}

.primary-btn:hover { filter: brightness(1.08); }

/* ── Forms ────────────────────────────────────────────────── */
input {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.84rem;
  font-family: inherit;
  outline: none;
  transition: border-color .13s;
}

input:focus { border-color: var(--accent); }
input::placeholder { color: var(--muted-2); }

.inline-form {
  display: flex;
  gap: 9px;
  margin-bottom: 14px;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.config-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

/* ── Chips ────────────────────────────────────────────────── */
.chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

/* ── Alert ────────────────────────────────────────────────── */
.alert-box {
  padding: 9px 13px;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.alert-box.success {
  background: var(--green-dim);
  border-color: rgba(34,197,94,0.22);
  color: #86efac;
}

.alert-box.error {
  background: var(--red-dim);
  border-color: rgba(239,68,68,0.22);
  color: #fca5a5;
}

.hidden { display: none !important; }

/* ── Misc ─────────────────────────────────────────────────── */
.monospace {
  font-family: 'Cascadia Code', 'Fira Code', Consolas, monospace;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ── Auth page (login) ────────────────────────────────────── */
body.auth-page {
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 34px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}

.auth-card h1 {
  margin: 12px 0 8px;
  font-size: 1.45rem;
  font-weight: 700;
}

.auth-copy, .muted-text {
  color: var(--muted);
  font-size: 0.84rem;
  margin-bottom: 20px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent-h);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* ── Links / Analytics ────────────────────────────────────── */
.links-grid {
  display: grid;
  grid-template-columns: 1fr 270px;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.link-item {
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-sub);
}

.link-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  min-width: 0;
}

.link-item-title {
  flex: 1;
  font-size: .81rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.link-clicks-badge {
  font-size: .75rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.tipo-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: .66rem;
  font-weight: 700;
  letter-spacing: .04em;
  flex-shrink: 0;
  text-transform: uppercase;
}

.badge-amz { background: var(--yellow-dim); color: var(--yellow); }
.badge-ml  { background: var(--blue-dim);   color: var(--blue); }

.click-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

.click-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .4s ease;
}

.link-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: .69rem;
  color: var(--muted);
  gap: 8px;
}

.link-item-meta span:first-child {
  font-family: 'Cascadia Code', Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sort-active {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
}

/* ── Bar chart ─────────────────────────────────────────────── */
.chart-wrap {
  flex: 1;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  flex: 1;
  min-height: 0;
}

.bar-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 0;
}

.bar-val {
  font-size: .58rem;
  font-weight: 600;
  color: var(--text);
  height: 14px;
  line-height: 14px;
  min-width: 0;
}

.bar-fill {
  width: 100%;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height .35s ease;
}

.bar-label {
  font-size: .58rem;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
  text-align: center;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .72rem;
  color: var(--muted);
  padding-top: 8px;
  border-top: 1px solid var(--border-sub);
  flex-shrink: 0;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: middle;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--muted);
  font-size: .8rem;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1200px) {
  .stats-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .dash-lower { grid-template-columns: 1fr; }
  .config-grid { grid-template-columns: 1fr; }
  .links-grid { grid-template-columns: 1fr; }
}

/* ── Hamburger button ─────────────────────────────────────── */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--r-sm);
  flex-shrink: 0;
}
.hamburger-btn:hover { background: var(--surface-2); }
.hamburger-btn span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}
.hamburger-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.open span:nth-child(2) { opacity: 0; }
.hamburger-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Sidebar overlay ──────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
  backdrop-filter: blur(2px);
}

@media (max-width: 700px) {
  .hamburger-btn { display: flex; }
  .sidebar-overlay.open { display: block; }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0; bottom: 0;
    transition: left .25s ease;
    z-index: 100;
    width: 260px;
  }
  .sidebar.open { left: 0; }
  .main-area { margin-left: 0 !important; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .topbar-actions .btn-ghost,
  .topbar-actions .btn-secondary { display: none; }
}
