@import "./design-tokens.css";

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

html {
  color-scheme: dark;
  height: 100%;
}
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
img { max-width: 100%; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: minmax(var(--sidebar-min), var(--sidebar-pct)) 1fr;
  min-height: 100vh;
  background: var(--bg-deep);
}

/* ——— Sidebar ——— */
.sidebar {
  background: linear-gradient(180deg, var(--bg-sidebar-top) 0%, var(--bg-sidebar) 100%);
  border-right: 1px solid rgba(226, 4, 53, 0.08);
  display: flex;
  flex-direction: column;
  padding: 22px 12px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 2;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 10px 28px;
}
.brand-logo {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(226, 4, 53, 0.26);
  box-shadow: 0 0 18px rgba(226, 4, 53, 0.28);
  flex: none;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(145deg, #ff2e55 0%, var(--accent) 55%, #b1052c 100%);
  box-shadow: 0 0 16px var(--accent-glow);
  display: grid;
  place-items: center;
  flex: none;
}
.brand-mark svg {
  width: 15px;
  height: 15px;
  stroke: #fff;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.brand-name {
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.04em;
  color: var(--text);
}
.brand-name span { color: var(--accent); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--text-rose);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color .15s ease, background .15s ease;
}
.nav a svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.65;
  flex: none;
}
.nav a:hover {
  color: var(--text);
  background: rgba(226, 4, 53, 0.08);
}
.nav a.active {
  background: var(--active-nav-grad);
  color: var(--text);
  font-weight: 600;
}

.sidebar-spacer { flex: 1; min-height: 12px; }

.upgrade-card {
  background: var(--upgrade-grad);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-card);
  padding: 16px 14px 14px;
  margin: 8px 6px 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 20px var(--accent-glow-soft);
}
.upgrade-card h4 {
  margin: 0 0 6px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}
.upgrade-card p {
  margin: 0 0 14px;
  font-size: 0.72rem;
  color: var(--text-rose);
  line-height: 1.45;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 8px 6px;
  color: inherit;
  border-radius: 12px;
}
.sidebar-user:hover { background: rgba(226, 4, 53, 0.06); }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-btn);
  flex: none;
}
.sidebar-user .meta { min-width: 0; flex: 1; }
.sidebar-user .meta strong {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .meta span {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.chev {
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  fill: none;
  stroke-width: 2;
  flex: none;
}

.sidebar-foot {
  padding: 4px 10px 2px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* ——— Main + header ——— */
.main-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    radial-gradient(980px 480px at 12% -12%, var(--bg-glow), transparent 54%),
    radial-gradient(640px 420px at 100% 0%, rgba(80, 0, 18, 0.22), transparent 46%),
    var(--bg);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 32px var(--content-pad) 8px;
}
.greet { min-width: 0; }
.greet h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.15;
}
.greet p {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 400;
}

.topbar-tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(8, 0, 2, 0.72);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  min-width: 260px;
  width: min(340px, 32vw);
  color: var(--text-muted);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}
.search svg {
  flex: none;
  opacity: 0.75;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}
.search input {
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  width: 100%;
  font-size: 0.84rem;
}
.search input::placeholder { color: #7c7a7b; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  position: relative;
}
.icon-btn:hover { background: rgba(226, 4, 53, 0.1); }
.icon-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.content { padding: 18px var(--content-pad) 40px; }

/* ——— Buttons / cards ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-btn);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface-3);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover { background: #ff1848; }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--accent-border);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  color: var(--text);
  background: var(--accent-fill-soft);
}
.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: var(--text);
  width: 100%;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: #fff;
}

.card {
  background: var(--surface-grad);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}
.card-pad { padding: 18px 20px; }

.flash-ok, .flash-err {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}
.flash-ok { background: rgba(46, 204, 113, 0.12); color: var(--success); }
.flash-err { background: rgba(226, 4, 53, 0.12); color: #ff6b8a; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1000px 560px at 8% -12%, rgba(226, 4, 53, 0.22), transparent 50%),
    var(--bg);
}
.auth-card {
  width: min(420px, 92vw);
  padding: 28px 26px;
}
.auth-brand {
  gap: 12px;
}
.auth-brand .brand-logo-frame {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(226, 4, 53, 0.26);
  box-shadow: 0 0 18px rgba(226, 4, 53, 0.28);
  flex: none;
}
.auth-brand .brand-logo {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.auth-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.auth-card .muted { color: var(--text-secondary); margin: 0 0 22px; font-size: 0.88rem; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text-rose);
  margin-bottom: 6px;
  font-weight: 600;
}
.form-group input,
.form-group select,
.settings-field input,
.admin-table input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-btn);
  color: var(--text);
}
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 8px 0;
}

.admin-page {
  min-height: 100vh;
  padding: 32px;
  background:
    radial-gradient(1000px 560px at 8% -12%, rgba(226, 4, 53, 0.18), transparent 50%),
    var(--bg);
}
.admin-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 16px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--accent-border);
}
.admin-table th {
  color: var(--text-rose);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-row {
  display: flex;
  gap: calc(100% / (5 * var(--gutter-ratio)));
  margin: 0 0 14px;
}
.kpi-row .kpi { flex: 1; min-width: 0; }
.kpi {
  background: var(--surface-grad);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-card);
  padding: 10px 12px;
  box-shadow: var(--shadow-card);
}
.kpi .label {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--text-rose);
}
.kpi .value {
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.term-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  color: #fca5a5;
  background: rgba(226, 4, 53, 0.2);
}
.badge-success {
  color: #86efac;
  background: rgba(46, 204, 113, 0.12);
  border-color: rgba(46, 204, 113, 0.28);
}
.fn-live-badge { display: inline-flex; align-items: center; gap: 6px; }
.fn-live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
}
.live-last-update { font-size: 0.75rem; color: var(--text-muted); }

.cycle-list { display: flex; flex-direction: column; gap: 12px; }
.cycle-card { display: block; padding: 14px 16px; color: inherit; }
.muted { color: var(--text-secondary); }
.version-tag { color: var(--text-muted); font-size: 0.75rem; }

.admin-unlock-wrap {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}
.admin-unlock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.74rem;
  opacity: 0.7;
  transition: opacity .15s ease, color .15s ease;
}
.admin-unlock svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.admin-unlock:hover {
  opacity: 1;
  color: var(--text-secondary);
}

html.terminal-page, html.terminal-page body { height: 100%; overflow: hidden; }
.terminal-page .app-shell { height: 100vh; max-height: 100vh; overflow: hidden; }
.terminal-page .main-wrap { min-height: 0; overflow: hidden; }
.terminal-page .content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 16px;
}
.rede163-terminal-stack {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (max-width: 1180px) {
  .search { min-width: 180px; width: 200px; }
  .greet h1 { font-size: 1.4rem; }
}
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 72px 1fr; }
  .brand-name,
  .nav a span,
  .sidebar-user .meta,
  .upgrade-card,
  .sidebar-foot,
  .chev { display: none; }
  .nav a { justify-content: center; padding: 12px 0; }
  .brand { justify-content: center; padding: 4px 0 18px; }
  .admin-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { flex-wrap: wrap; padding: 20px 20px 0; }
  .topbar-tools { width: 100%; margin-left: 0; }
  .search { min-width: 0; flex: 1; width: auto; }
  .content { padding: 16px 20px 28px; }
  .kpi-row { display: grid; grid-template-columns: 1fr 1fr; }
}
