/* ============================================
   DESIGN SYSTEM — Agente Pessoal
   Flat/Modern | Slate Palette | Dark Mode Ready
   ============================================ */

/* --- Tokens CSS: Light Mode (default) --- */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-header: #0f172a;
  --bg-input: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-sidebar: #0f172a;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-on-header: #f1f5f9;

  --border: #e2e8f0;
  --border-focus: #6366f1;

  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #e0e7ff;

  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #f43f5e;
  --danger-bg: #ffe4e6;
  --info: #0ea5e9;
  --info-bg: #e0f2fe;

  --cal-cumprido-bg: #d1fae5;
  --cal-pendente-bg: #fef3c7;
  --cal-falta-bg: #ffe4e6;
  --cal-folga-bg: #e0f2fe;

  --sidebar-width: 240px;
  --sidebar-collapsed: 60px;
}

/* --- Tokens CSS: Dark Mode --- */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-header: #020617;
  --bg-input: #334155;
  --bg-hover: #334155;
  --bg-sidebar: #020617;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-on-header: #f1f5f9;

  --border: #334155;
  --border-focus: #818cf8;

  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: #1e1b4b;

  --success: #34d399;
  --success-bg: #064e3b;
  --warning: #fbbf24;
  --warning-bg: #78350f;
  --danger: #fb7185;
  --danger-bg: #4c0519;
  --info: #38bdf8;
  --info-bg: #0c4a6e;

  --cal-cumprido-bg: #064e3b;
  --cal-pendente-bg: #78350f;
  --cal-falta-bg: #4c0519;
  --cal-folga-bg: #0c4a6e;
}

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

/* --- Login Screen --- */
#login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 24rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.login-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 1rem;
  background: var(--accent);
  color: #fff;
  margin-bottom: 1rem;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}

.login-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0.5rem 0 1.5rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}

.login-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.login-field input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.login-field input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.login-btn {
  width: 100%;
  padding: 0.7rem;
  font-size: 0.95rem;
}

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  text-align: center;
}

body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
}

/* --- Transição global dark mode --- */
header, main, .card, .input, .nav-btn, .btn, .modal-card, .toast, select, .time-row, aside, .sidebar-link, .sidebar-section-toggle {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

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

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: width 0.2s ease, transform 0.2s ease;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: 0.5rem;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f1f5f9;
  white-space: nowrap;
  overflow: hidden;
}

/* --- Nav Links --- */
.sidebar-nav {
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #94a3b8;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #f1f5f9;
}

.sidebar-link.active {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
}

.sidebar-link svg {
  flex-shrink: 0;
}

/* --- Section (Projetos) --- */
.sidebar-section {
  padding: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin-top: auto;
}

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  border-radius: 0.375rem;
  transition: color 0.15s ease;
}

.sidebar-section-toggle:hover {
  color: #94a3b8;
}

.sidebar-section-list {
  padding: 0.25rem 0.75rem;
}

.sidebar-empty {
  font-size: 0.8rem;
  color: #475569;
  font-style: italic;
}

/* --- Bottom --- */
.sidebar-bottom {
  padding: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-bottom .sidebar-link {
  font-size: 0.8rem;
}

/* --- Sidebar collapsed --- */
.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .sidebar-link span,
.sidebar.collapsed .sidebar-section-toggle span,
.sidebar.collapsed .sidebar-section-list,
.sidebar.collapsed .sidebar-bottom .sidebar-link span {
  display: none;
}

.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: 0.6rem;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 1.25rem 0.5rem;
}

/* --- Sidebar collapse button (desktop) --- */
.sidebar-collapse-btn {
  display: none;
  position: fixed;
  top: 1.25rem;
  left: calc(var(--sidebar-width) - 1rem);
  z-index: 45;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: left 0.2s ease, transform 0.15s ease;
}

.sidebar-collapse-btn:hover {
  transform: scale(1.1);
}

.sidebar.collapsed ~ .sidebar-collapse-btn {
  left: calc(var(--sidebar-collapsed) - 0.5rem);
}

/* ============================================
   MOBILE HEADER & OVERLAY
   ============================================ */

.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-header);
  z-index: 30;
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
}

.mobile-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-on-header);
}

.hamburger-btn {
  background: transparent;
  border: none;
  color: var(--text-on-header);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hamburger-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 35;
}

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

.main-content {
  margin-left: var(--sidebar-width);
  padding: 1.5rem;
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed);
}

/* --- Page --- */
.page {
  max-width: 72rem;
  margin: 0 auto;
}

.page.hidden {
  display: none;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0;
}

/* ============================================
   COMPONENTS (mantidos do design system)
   ============================================ */

/* --- Card --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

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

/* --- Card Label --- */
.card-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

/* --- Card Value --- */
.card-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* --- Input --- */
.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

select.input {
  cursor: pointer;
  appearance: auto;
}

/* --- Nav Button --- */
.nav-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.nav-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

/* --- Button --- */
.btn {
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
  color: #fff;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.9); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }

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

.btn-ghost:hover {
  background: var(--bg-hover);
}

/* --- Day Cell (Calendário) --- */
.day-cell {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.375rem;
  cursor: pointer;
  text-align: center;
  min-height: 64px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.day-cell:hover {
  transform: translateY(-1px);
}

.day-cell.status-cumprido { background: var(--cal-cumprido-bg); border-color: var(--success); }
.day-cell.status-pendente { background: var(--cal-pendente-bg); border-color: var(--warning); }
.day-cell.status-falta { background: var(--cal-falta-bg); border-color: var(--danger); }
.day-cell.status-folga { background: var(--cal-folga-bg); border-color: var(--info); }
.day-cell.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.day-cell.is-selected { box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(99, 102, 241, 0.2); }

/* --- Calendar Mini Bar --- */
.cal-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--success);
  margin-top: 4px;
}

/* --- Calendar Check Icon --- */
.cal-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  margin-top: 2px;
}

.cal-check svg { width: 10px; height: 10px; }

/* --- Calendar Badge --- */
.cal-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 6px;
  border-radius: 9999px;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.4;
}

.cal-badge.badge-pendente { background: var(--warning-bg); color: var(--warning); }
.cal-badge.badge-falta { background: var(--danger-bg); color: var(--danger); }
.cal-badge.badge-folga { background: var(--info-bg); color: var(--info); }

.cal-report-dot {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 0 0 0.5rem 0.5rem;
}

/* --- Report Editor --- */
.report-editor {
  min-height: 280px;
  font-size: 0.9rem;
}

/* --- Time Row --- */
.time-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  padding: 0.5rem;
}

.time-row .input {
  width: 7rem;
  flex-shrink: 0;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-left: 4px solid var(--success);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  animation: toastIn 0.2s ease-out;
}

.toast.toast-error { border-left-color: var(--danger); }
.toast.hidden { display: none; }

/* --- Modal --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  overflow-y: auto;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  width: 100%;
  max-width: 36rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.25s ease-out;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0.5rem 0 0.25rem;
}

.empty-state p {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

/* --- Preview --- */
.editor-preview {
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-weight: 700;
  color: var(--text-primary);
}

/* --- Recent Activity Item --- */
.activity-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  background: var(--bg-secondary);
}

.activity-item .activity-day {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.activity-item .activity-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.activity-item .activity-hours {
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.activity-item .activity-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 9999px;
}

/* --- Animations --- */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fillBar {
  from { width: 0; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.animate-fill { animation: fillBar 0.6s ease-out; }

/* --- Prefers Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Scrollbar (dark mode) --- */
[data-theme="dark"] ::-webkit-scrollbar { width: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg-secondary); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

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

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding-top: calc(56px + 1.5rem);
  }

  .sidebar.collapsed ~ .main-content {
    margin-left: 0;
  }

  .sidebar-collapse-btn {
    display: none !important;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
