/* =========================================================
   RESET
========================================================= */

:root {
  --primary: #2563eb;
  --primary-light: #60a5fa;

  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;

  --text: #0f172a;
  --text-secondary: #64748b;

  --bg: #f8fbff;
  --bg-secondary: #eef4ff;

  --glass: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(255, 255, 255, 0.4);

  --dark-bg: #0f172a;
  --dark-card: #1e293b;

  --shadow-sm: 0 5px 20px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 15px 40px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.08);

  --radius-sm: 18px;
  --radius-md: 24px;
  --radius-lg: 30px;
  --radius-xl: 35px;

  --space-xs: 10px;
  --space-sm: 15px;
  --space-md: 20px;
  --space-lg: 30px;
  --space-xl: 40px;

  --transition: 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
}

html {
  scroll-behavior: smooth;
}

body {
  background: linear-gradient(135deg, var(--bg), var(--bg-secondary));
  color: var(--text);
  overflow-x: hidden;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* =========================================================
   UTILITIES
========================================================= */

.glass {
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-md);
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden {
  display: none !important;
}

/* =========================================================
   BACKGROUND
========================================================= */

.bg1,
.bg2 {
  position: fixed;
  border-radius: 50%;
  filter: blur(150px);
  z-index: -1;
}

.bg1 {
  width: 700px;
  height: 700px;
  background: var(--primary);
  opacity: 0.15;
  top: -250px;
  right: -200px;
}

.bg2 {
  width: 600px;
  height: 600px;
  background: var(--primary-light);
  opacity: 0.12;
  bottom: -250px;
  left: -200px;
}

/* =========================================================
   MOBILE TOP
========================================================= */

.mobile-top {
  display: none;
}

/* =========================================================
   SIDEBAR
========================================================= */

body:not(.logged-in) .sidebar,
body:not(.logged-in) .mobile-top {
  display: none !important;
}

.sidebar {
  width: 290px;
  height: 100vh;

  position: fixed;
  top: 0;
  left: 0;

  padding: var(--space-lg) 22px;

  display: flex;
  flex-direction: column;
  justify-content: space-between;

  z-index: 999;

  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(20px);

  border-right: 1px solid rgba(255, 255, 255, 0.4);

  transition: left var(--transition);
}

.logo {
  font-size: 40px;
  font-weight: 800;
  color: var(--primary);
}

.slogan {
  margin-top: var(--space-xs);
  color: var(--text-secondary);
  line-height: 1.6;
}

.menu {
  margin-top: var(--space-xl);
}

.menu a {
  display: flex;
  align-items: center;
  gap: 12px;

  padding: 18px;
  margin-bottom: var(--space-sm);

  border-radius: var(--radius-sm);

  color: var(--text);
  text-decoration: none;
  font-weight: 600;

  cursor: pointer;

  transition:
    background var(--transition),
    color var(--transition),
    transform var(--transition);
}

.menu a:hover {
  background: var(--primary);
  color: white;
  transform: translateX(5px);
}

.menu a.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}

.bottom-sidebar {
  padding: var(--space-md);
  border-radius: var(--radius-md);

  background: white;

  box-shadow: var(--shadow-sm);
}

.bottom-sidebar h3 {
  margin-bottom: var(--space-xs);
}

.bottom-sidebar p {
  color: var(--text-secondary);
  line-height: 1.5;
  font-size: 14px;
}

/* =========================================================
   MAIN
========================================================= */

.main {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 0;
  min-height: 100dvh;
  padding: 35px;
}

body.logged-in .main {
  display: block;
  margin-left: 290px;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* =========================================================
   LOGIN
========================================================= */

.login-card {
  width: 100%;
  max-width: 520px;
  min-height: 500px;
  padding: 45px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.85),
    rgba(255, 255, 255, 0.65)
  );
  border: 1px solid rgba(15, 23, 42, 0.04);
  box-shadow: 0 20px 60px rgba(2, 6, 23, 0.08);
  border-radius: 24px;
  animation: fade 0.45s cubic-bezier(0.2, 0.9, 0.2, 1);
}

.badge {
  width: fit-content;
  padding: 10px 18px;
  margin-bottom: 25px;
  border-radius: 999px;
  background: #dbeafe;
  color: var(--primary);
  font-size: 14px;
  font-weight: 700;
}

.login-card h1 {
  font-size: 40px;
  line-height: 1.1;
  margin-bottom: var(--space-sm);
  text-align: center;
}

.login-card p {
  margin-bottom: var(--space-lg);
  color: var(--text-secondary);
  line-height: 1.7;
}

.login-card button {
  width: 100%;
}

.auth-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.auth-actions button {
  flex: 1 1 140px;
  min-width: 120px;
  width: auto;
}

.page-grid {
  display: flex;
  gap: 20px;
  margin-top: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.dashboard-content {
  flex: 1 1 580px;
  min-width: 320px;
}

.dashboard-aside {
  flex: 0 1 360px;
  min-width: 260px;
  width: 100%;
  max-width: 360px;
}

.page-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-actions,
.history-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.page-actions button,
.history-page-actions button {
  flex: 1 1 140px;
  min-width: 120px;
  width: auto;
}

.page-search {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: white;
  box-shadow: var(--shadow-sm);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.history-card table {
  width: 100%;
  min-width: 0; /* allow table to shrink on small screens; container handles horizontal scroll */
}

.user-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* =========================================================
   FORM
========================================================= */

input {
  width: 100%;

  padding: 18px;
  margin-bottom: 18px;

  border: none;
  border-radius: var(--radius-sm);

  background: white;
  color: var(--text);

  font-size: 16px;

  box-shadow: var(--shadow-sm);

  transition:
    border var(--transition),
    transform var(--transition);
}

input::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.12);
  transform: translateY(-1px) scale(1.01);
}

button {
  border: none;

  padding: 18px 26px;

  border-radius: var(--radius-sm);

  background: linear-gradient(135deg, var(--primary), #3b82f6);

  color: white;

  cursor: pointer;

  font-size: 16px;
  font-weight: 700;

  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.3);

  transition:
    transform var(--transition),
    opacity var(--transition);
}

button:hover {
  transform: translateY(-4px);
}

button:active {
  transform: scale(0.98);
}

/* =========================================================
   TOPBAR
========================================================= */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;

  gap: var(--space-md);

  margin-bottom: 35px;
}

.top-left h1 {
  font-size: 44px;
}

.top-left p {
  margin-top: 8px;
  color: var(--text-secondary);
}

.top-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.search,
.profile,
.mini-card {
  background: white;
  box-shadow: var(--shadow-sm);
}

.search {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  width: 100%;
  min-width: 0;
}

.search input {
  width: 100%;
  margin: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

.profile {
  display: flex;
  align-items: center;
  gap: 14px;

  padding: 14px 20px;

  border-radius: var(--radius-sm);
}

.avatar {
  width: 45px;
  height: 45px;

  border-radius: 50%;

  background: var(--primary);
}

/* =========================================================
   CARDS
========================================================= */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));

  gap: 25px;
}

.card {
  background: #fdfdfd;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  padding: 26px;
  border-radius: var(--radius-md);
  transition:
    transform var(--transition),
    box-shadow var(--transition);
}

.card:hover {
  transform: translateY(-4px);
}

.card::before {
  content: "";

  position: absolute;

  width: 100px;
  height: 100px;

  top: -30px;
  right: -30px;

  border-radius: 50%;

  background: rgba(255, 255, 255, 0.35);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-top span {
  color: var(--text-secondary);
  font-weight: 600;
}

.card h2 {
  margin: 18px 0;

  font-size: 52px;
  color: var(--primary);
}

.card small {
  color: var(--text-secondary);
}

.tag {
  padding: 8px 12px;

  border-radius: 999px;

  background: #dcfce7;
  color: var(--success);

  font-size: 13px;
  font-weight: 700;
}

.red {
  background: #fee2e2;
  color: var(--danger);
}

/* =========================================================
   ACTIONS
========================================================= */

.actions {
  display: flex;
  gap: var(--space-md);

  margin-top: 35px;

  flex-wrap: wrap;
}

/* =========================================================
   CHARTS
========================================================= */

.charts {
  display: grid;
  grid-template-columns: 2fr 1fr;

  gap: 20px;

  margin-top: 24px;
}

.chart-card,
.history-card,
.activity-card,
.productivity-card {
  padding: var(--space-md);
  border-radius: var(--radius-md);
}

.history-card {
  background: white;
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-md);
  border: 1px solid rgba(15, 23, 42, 0.06);
}

.history-card .history-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.history-card .history-actions-row button {
  flex: 1 1 140px;
  min-width: 120px;
}

.history-card ul {
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
  margin: 0;
}

.history-list {
  max-height: 260px;
  overflow: auto;
  padding: 0;
  margin: 0;
}

.history-card ul li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  background: rgba(248, 251, 255, 0.95);
  border: 1px solid rgba(15, 23, 42, 0.06);
  color: var(--text);
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
  transition:
    transform var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
}

.history-card ul li:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

.history-card ul li .history-entry {
  flex: 1 1 180px;
  min-width: 180px;
  white-space: normal;
  word-break: break-word;
}

.history-card ul li .history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  flex: 0 1 auto;
}

.history-card ul li .history-actions button {
  padding: 10px 14px;
  min-width: 88px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
  box-shadow: none;
  transition:
    background var(--transition),
    color var(--transition),
    transform var(--transition);
}

.history-card ul li .history-actions button:hover {
  background: var(--primary);
  color: #fff;
  transform: translateY(-1px);
}

.chart-card h2,
.history-card h2 {
  margin-bottom: var(--space-md);
}

/* =========================================================
   BOTTOM GRID
========================================================= */

.bottom-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;

  gap: 20px;

  margin-top: 24px;
}

.section-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 25px;
}

.online-badge {
  padding: 8px 14px;

  border-radius: 999px;

  background: #d6fde4;
  color: var(--success);

  font-size: 13px;
  font-weight: 700;
}

/* =========================================================
   ACTIVITY
========================================================= */

.activity {
  display: flex;
  align-items: center;
  gap: var(--space-sm);

  margin-bottom: 25px;
}

.activity h4 {
  margin-bottom: 5px;
}

.activity p {
  color: var(--text-secondary);
  font-size: 14px;
}

.activity-icon {
  width: 16px;
  height: 16px;

  border-radius: 50%;
}

.blue {
  background: var(--primary);
}

.green {
  background: var(--success);
}

.orange {
  background: var(--warning);
}

/* =========================================================
   PROGRESS
========================================================= */

.progress-area {
  margin-top: var(--space-md);
}

.progress-title {
  margin-bottom: 12px;

  color: var(--text-secondary);
  font-weight: 600;
}

.progress-bar {
  width: 100%;
  height: 14px;

  overflow: hidden;

  border-radius: 999px;

  background: #dbeafe;
}

.progress-fill {
  width: 89%;
  height: 100%;

  border-radius: 999px;

  background: linear-gradient(90deg, var(--primary), var(--primary-light));
}

.mini-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;

  gap: var(--space-sm);

  margin-top: var(--space-lg);
}

.mini-card {
  padding: var(--space-md);

  border-radius: 22px;

  text-align: center;
}

.mini-card h3 {
  margin-bottom: 8px;

  font-size: 32px;
  color: var(--primary);
}

.mini-card p {
  color: var(--text-secondary);
}

/* =========================================================
   HISTORY
========================================================= */

.history-card {
  margin-top: 35px;
}

li {
  list-style: none;

  margin-bottom: var(--space-sm);
  padding: var(--space-md);

  border-radius: var(--radius-sm);

  background: white;

  line-height: 1.7;

  box-shadow: var(--shadow-sm);
}

/* =========================================================
   TABLE
========================================================= */

.table {
  width: 100%;
  margin-top: var(--space-md);

  border-collapse: collapse;
}

.table th {
  padding: 18px;

  background: var(--primary);
  color: white;

  text-align: left;
}

.table td {
  padding: 18px;

  background: white;

  border-bottom: 1px solid #f1f5f9;
}

/* =========================================================
   DARK MODE
========================================================= */

body.dark {
  background: linear-gradient(135deg, #0f172a, #111827);

  color: white;
}

body.dark .login-card {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

body.dark .login-card h1 {
  color: white;
}

body.dark input {
  color: white;
}

body.dark .auth-actions button {
  color: white;
}

body.dark .online-badge {
  background: #d6fde4;
  color: var(--success);
}

body.dark .card {
  background: var(--dark-card);
}

body.dark .sidebar,
body.dark .glass,
body.dark .mobile-top {
  background: rgba(15, 23, 42, 0.75);
  border-color: rgba(255, 255, 255, 0.05);
}

body.dark .history-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.dark .history-card ul li {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
}

body.dark .history-card ul li .history-actions button {
  background: rgba(255, 255, 255, 0.08);
  color: #e5e7eb;
  border-color: rgba(255, 255, 255, 0.12);
}

body.dark .history-card ul li .history-actions button:hover {
  background: rgba(255, 255, 255, 0.14);
}

body.dark .bottom-sidebar,
body.dark .profile,
body.dark .search,
body.dark .mini-card,
body.dark li,
body.dark input,
body.dark .table td {
  background: var(--dark-card);
  color: white;
}

body.dark p,
body.dark span,
body.dark small {
  color: #ffffff;
}

body.dark .menu a {
  color: white;
}

body.dark input::placeholder {
  color: #94a3b8;
  opacity: 0.8;
}

body.dark .progress-bar {
  background: #334155;
}

body.dark .table th {
  background: #1d4ed8;
}

/* =========================================================
   RESPONSIVE
========================================================= */

@media (max-width: 1100px) {
  .charts,
  .bottom-grid {
    grid-template-columns: 1fr;
  }

  .page-grid {
    flex-direction: column;
  }

  .dashboard-content,
  .dashboard-aside {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 900px) {
  body.logged-in .mobile-top {
    display: flex;
  }

  body:not(.logged-in) .mobile-top {
    display: none;
  }

  .mobile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px;
    position: sticky;
    top: 0;
    z-index: 1200;
    backdrop-filter: blur(20px);
    background: rgba(255, 255, 255, 0.8);
  }

  .sidebar {
    left: -100%;
    width: 280px;
  }

  .sidebar.active {
    left: 0;
  }

  body.logged-in .main {
    margin-left: 0;
    padding: 18px;
  }

  .main {
    padding: 18px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .top-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .search,
  .profile {
    width: 100%;
  }

  .actions,
  .page-actions,
  .history-page-actions {
    flex-direction: column;
  }

  .actions button,
  .page-actions button,
  .history-page-actions button {
    width: 100%;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .charts,
  .bottom-grid,
  .mini-stats {
    grid-template-columns: 1fr;
  }

  .card,
  .history-card,
  .chart-card,
  .activity-card,
  .productivity-card {
    padding: 18px;
  }

  .history-card ul li {
    flex-direction: column;
    align-items: stretch;
  }

  .history-card ul li .history-actions {
    width: 100%;
    justify-content: stretch;
  }

  .history-card ul li .history-actions button {
    flex: 1;
  }

  .table {
    min-width: 650px;
  }

  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 600px) {
  html,
  body {
    overflow-x: hidden;
  }

  body,
  .main {
    min-height: 100dvh;
  }

  .main {
    padding: 12px;
  }

  .auth-actions{
    flex-direction: column;
    gap: 10px;
  }

  .auth-actions button {
    width: 100%;
    flex: 0;
    min-width: 0;
    padding: 12px;
    font-size: 14px;
  }

  .login-card {
    padding: 22px;
    border-radius: 20px;
  }

  .login-card h1,
  .top-left h1 {
    font-size: 30px;
    line-height: 1.2;
  }

  .top-left p,
  .login-card p {
    font-size: 14px;
  }

  .logo {
    font-size: 28px;
  }

  .card h2 {
    font-size: 30px;
  }

  input,
  button {
    padding: 14px;
    font-size: 15px;
  }

  .profile {
    padding: 12px;
  }

  .avatar {
    width: 38px;
    height: 38px;
  }

  .card,
  .mini-card,
  .history-card {
    border-radius: 18px;
  }

  .stats {
    gap: 14px;
  }

  .charts,
  .bottom-grid,
  .page-grid {
    gap: 14px;
  }

  .toast-wrap {
    right: 10px;
    left: 10px;
    top: 10px;
  }

  .toast {
    width: 100%;
  }
}

/* =========================================================
   ANIMATIONS
========================================================= */

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#sistema {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

/* Toasts */
.toast-wrap {
  position: fixed;
  right: 20px;
  top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}
.toast {
  background: rgba(15, 23, 42, 0.95);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(2, 6, 23, 0.4);
  transform-origin: right top;
  animation: toast-in 0.28s ease;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Sidebar collapsed state */
.sidebar.collapsed {
  width: 88px;
}
.sidebar.collapsed .menu a {
  justify-content: center;
}
.sidebar.collapsed .logo {
  font-size: 20px;
}

/* Small screens: show mobile top only after logged-in */
@media (max-width: 900px) {
  body.logged-in .mobile-top {
    display: flex;
  }
  body:not(.logged-in) .mobile-top {
    display: none;
  }
  .sidebar {
    left: -100%;
  }
  .sidebar.active {
    left: 0;
  }
}
