:root {
  --bg: #16181d;
  --panel: #1e2128;
  --panel-2: #262a33;
  --border: #343a46;
  --text: #eef0f3;
  --muted: #9aa3b2;
  --yellow: #f4c93a;
  --accent: #4f8cff;
  --danger: #e5484d;
  --danger-bg: #3a1f21;
  --green: #3ecf8e;

  --m-color: #4f8cff;
  --i-color: #a06bff;
  --t-color: #3ecf8e;
  --n-color: #232733;
  --n-text: #eef0f3;
  --extra-color: #f4c93a;
  --ferias-color: #f2823a;
  --folga-color: #ffffff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Subtle moving background used on the app/admin screens (after login) */
.app-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(79, 140, 255, 0.16), transparent 60%),
                     radial-gradient(circle, rgba(244, 201, 58, 0.12), transparent 60%),
                     radial-gradient(circle, rgba(62, 207, 142, 0.1), transparent 60%);
  background-size: 60% 60%, 55% 55%, 50% 50%;
  background-repeat: no-repeat;
  animation: appBgMove 30s ease-in-out infinite alternate;
}

@keyframes appBgMove {
  0% { background-position: -10% -10%, 110% 10%, 50% 120%; }
  50% { background-position: 60% 40%, 30% 70%, 90% 20%; }
  100% { background-position: 100% 90%, -10% 40%, 10% -10%; }
}

.topbar, .container { position: relative; z-index: 1; }

a { color: var(--accent); }

.centered-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
}

.card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.card .subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 14px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 14px 0 6px;
}

input, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  cursor: pointer;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 14px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 20px;
  font-weight: 600;
}

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

button.danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  min-height: 16px;
}

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar .brand {
  font-weight: 700;
  font-size: 16px;
}

.topbar .brand .dot { color: var(--yellow); }

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

.topbar-actions .username {
  color: var(--muted);
  font-size: 13px;
  margin-right: 6px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 18px;
}

.month-nav h2 {
  margin: 0;
  min-width: 220px;
  text-align: center;
  text-transform: capitalize;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 18px;
  font-size: 12px;
  color: var(--muted);
}

.legend .swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: middle;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 90px;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.calendar-grid .dow {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 0;
  font-weight: 600;
}

.calendar-grid .dow.week-total-label { color: var(--yellow); }

.day-cell {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 84px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day-cell:hover { border-color: var(--accent); }

.day-cell.other-month { opacity: 0.4; }
.day-cell.other-month .day-num { color: var(--muted); }

.day-cell .day-num {
  font-size: 12px;
  color: var(--muted);
}

.day-dow-mobile { display: none; }

.shift-chip {
  font-size: 11px;
  border-radius: 5px;
  padding: 2px 5px;
  font-weight: 700;
  color: #0b0d10;
}

.shift-chip.M { background: var(--m-color); color: #fff; }
.shift-chip.I { background: var(--i-color); color: #fff; }
.shift-chip.T { background: var(--t-color); color: #06231a; }
.shift-chip.N { background: var(--n-color); color: var(--n-text); border: 1px solid var(--border); }
.shift-chip.EXTRA { background: var(--extra-color); color: #2a2200; }
.shift-chip.FERIAS { background: var(--ferias-color); color: #2a1500; }
.shift-chip.FOLGA { background: var(--folga-color); color: #1a1a1a; border: 1px solid var(--border); }

/* When a day is a whole Ferias/Folga day, colour the entire cell, not just the chip */
.day-cell.day-ferias {
  background: var(--ferias-color);
  border-color: var(--ferias-color);
}
.day-cell.day-ferias .day-num { color: #2a1500; }
.day-cell.day-ferias .shift-chip { background: rgba(0, 0, 0, 0.2); color: #fff; }

.day-cell.day-folga {
  background: var(--folga-color);
  border-color: #cfcfcf;
}
.day-cell.day-folga .day-num { color: #333; }
.day-cell.day-folga .shift-chip { background: rgba(0, 0, 0, 0.08); color: #222; }

.week-total {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--yellow);
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.summary-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
}

.summary-card .label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.summary-card .value {
  font-size: 22px;
  font-weight: 700;
}

.payroll-section {
  margin-top: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
}

.payroll-section h3 {
  margin: 0 0 16px;
}

.payroll-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  padding: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
}

.payroll-toggle-hint {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.payroll-body {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.payroll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 18px;
}

.payroll-grid .field small {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  font-size: 11px;
}

.irs-calc {
  margin-top: 22px;
  padding: 16px 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.irs-calc h4 {
  margin: 0 0 12px;
  font-size: 14px;
}

.irs-calc-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.irs-calc-row .field { flex: 1; min-width: 160px; }
.irs-calc-row .field label { margin: 0 0 6px; }
.irs-calc-row button { height: 40px; }

.irs-calc-result {
  margin: 14px 0 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  min-height: 20px;
}

.irs-calc-note {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.suppl-table-wrap {
  overflow-x: auto;
  margin-top: 12px;
}

.suppl-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
}

.suppl-table th, .suppl-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.suppl-table th { color: var(--muted); font-weight: 600; font-size: 11px; }

.suppl-table .supl-hours-cell input,
.suppl-table .supl-pct-cell input {
  width: 70px;
  padding: 6px 8px;
}

.suppl-table .supl-label { color: var(--text); }
.suppl-table .supl-extraordinario .supl-label { color: var(--yellow); }

.payroll-result {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: center;
}

.payroll-result .breakdown {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.payroll-result .liquido {
  margin-left: auto;
  text-align: right;
}

.payroll-result .liquido .label {
  color: var(--muted);
  font-size: 13px;
}

.payroll-result .liquido .value {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
}

.payroll-actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-msg {
  font-size: 13px;
  color: var(--green);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 340px;
}

.modal h3 { margin: 0 0 4px; }
.modal .modal-date { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

.existing-shifts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.existing-shifts .shift-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
}

.existing-shifts .shift-chip button {
  background: none;
  border: none;
  color: inherit;
  padding: 0;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

/* Admin */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 18px;
}

.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.admin-table th { color: var(--muted); font-weight: 600; font-size: 12px; }

.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge.admin { background: #3a2f0d; color: var(--yellow); }
.badge.user { background: #1c2c3a; color: var(--accent); }

.new-user-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.new-user-form .field { flex: 1; min-width: 160px; }
.new-user-form label { margin: 0 0 6px; }

.hidden { display: none !important; }

/* Login page: background photo + intro animation */

.login-body {
  min-height: 100vh;
  overflow: hidden;
}

.bg-photo {
  position: fixed;
  inset: -20px;
  background-image: url("../images/login-bg.jpg");
  background-size: cover;
  background-position: center;
  z-index: 0;
  animation: bgKenBurns 22s ease-in-out infinite alternate;
}

@keyframes bgKenBurns {
  0% { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.18) translate(-2%, -2%); }
}

.bg-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(16,18,22,0.75), rgba(16,18,22,0.9));
  z-index: 1;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 1;
  background-image: radial-gradient(circle, rgba(79, 140, 255, 0.3), transparent 60%),
                     radial-gradient(circle, rgba(244, 201, 58, 0.2), transparent 60%);
  background-size: 70% 70%, 60% 60%;
  background-repeat: no-repeat;
  animation: bgGlowMove 16s ease-in-out infinite alternate;
  mix-blend-mode: screen;
}

@keyframes bgGlowMove {
  0% { background-position: -10% -10%, 110% 110%; }
  100% { background-position: 90% 30%, 10% 70%; }
}

.login-body .centered-page {
  position: relative;
  z-index: 2;
}

.login-card {
  opacity: 0;
  transform: translateY(12px);
  animation: cardFadeIn 0.9s ease forwards;
  animation-delay: 2.3s;
  backdrop-filter: blur(4px);
  background: rgba(30, 33, 40, 0.9);
}

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

.intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c0d10;
  animation: introFadeOut 0.7s ease forwards;
  animation-delay: 2s;
}

.intro-badge {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(0.6);
  opacity: 0;
  animation: introBadgeZoom 2.2s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

.intro-logo {
  width: 62%;
  height: 62%;
  object-fit: contain;
}

@keyframes introBadgeZoom {
  0% { transform: scale(0.6); opacity: 0; box-shadow: 0 0 0 rgba(79, 140, 255, 0); }
  25% { transform: scale(1); opacity: 1; box-shadow: 0 0 30px rgba(79, 140, 255, 0.5); }
  65% { transform: scale(2.6); opacity: 1; box-shadow: 0 0 80px rgba(79, 140, 255, 0.85); }
  100% { transform: scale(3.4); opacity: 0; box-shadow: 0 0 110px rgba(79, 140, 255, 0); }
}

@keyframes introFadeOut {
  0% { opacity: 1; visibility: visible; }
  99% { opacity: 0; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}


.tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 10px 16px;
  color: var(--muted);
  font-weight: 600;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.jump-to {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.jump-to label {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.jump-to select, .jump-to input {
  width: auto;
}

.jump-to input[type="number"] {
  width: 90px;
}

.annual-note {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 18px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  border-top: 3px solid var(--border);
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  inset: auto -30px -30px auto;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  opacity: 0.08;
  background: currentColor;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 800;
}

.kpi-bruto { border-top-color: var(--accent); color: var(--accent); }
.kpi-bruto .kpi-value { color: var(--text); }
.kpi-ss { border-top-color: var(--ferias-color); color: var(--ferias-color); }
.kpi-ss .kpi-value { color: var(--text); }
.kpi-irs { border-top-color: var(--danger); color: var(--danger); }
.kpi-irs .kpi-value { color: var(--text); }
.kpi-liquido { border-top-color: var(--green); color: var(--green); }
.kpi-liquido .kpi-value { color: var(--green); }

.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
}

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}

.chart-card h4 {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.chart-canvas-wrap {
  position: relative;
  height: 280px;
}

.chart-canvas-wrap-donut {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.greeting {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 18px;
}

.greeting::before { content: "👋 "; }

textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  margin-top: 6px;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.calendar-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Mobile optimisation */
@media (max-width: 720px) {
  .container { padding: 14px; }

  .topbar { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .topbar-actions { gap: 8px; }

  .month-nav { gap: 10px; margin-bottom: 14px; }
  .month-nav h2 { min-width: 0; font-size: 18px; }

  .legend { gap: 8px; font-size: 11px; margin-bottom: 14px; }

  /* Calendar stays a real 7-column grid on phones (like a normal paper
     calendar), just compact - with the days from the previous/next month
     shown dimmed to complete each week, and the week total as its own
     full-width bar under each row instead of a cramped 8th column. */
  .calendar-scroll { overflow-x: visible; }

  .calendar-grid {
    grid-template-columns: repeat(7, 1fr);
    min-width: 0;
    padding: 6px;
    gap: 3px;
  }

  .calendar-grid .dow { font-size: 10px; padding: 4px 0; }
  .calendar-grid .dow.week-total-label { display: none; }

  .day-cell {
    min-height: 52px;
    padding: 4px;
    gap: 2px;
  }

  .day-cell.other-month { opacity: 0.35; }

  .day-cell .day-num {
    font-size: 11px;
    text-align: right;
  }

  .day-dow-mobile { display: none; }

  .shift-chip {
    font-size: 8px;
    padding: 1px 3px;
    line-height: 1.3;
  }

  .week-total {
    grid-column: 1 / -1;
    justify-content: space-between;
    padding: 6px 12px;
    font-size: 11px;
    background: var(--panel);
  }

  .week-total::before { content: "Total da semana"; color: var(--muted); font-weight: 600; }

  .summary-cards { grid-template-columns: 1fr; gap: 10px; margin-top: 16px; }
  .summary-card { padding: 14px 16px; }
  .summary-card .value { font-size: 19px; }

  .payroll-section { padding: 16px; margin-top: 20px; }
  .payroll-grid { grid-template-columns: 1fr; gap: 12px; }

  .payroll-result { flex-direction: column; align-items: stretch; gap: 12px; }
  .payroll-result .liquido { margin-left: 0; text-align: left; }
  .payroll-result .liquido .value { font-size: 26px; }

  .payroll-actions { flex-wrap: wrap; }

  .kpi-row { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
  .kpi-card { padding: 14px 16px; }
  .kpi-value { font-size: 19px; }

  .chart-grid { grid-template-columns: 1fr; }
  .chart-canvas-wrap { height: 220px; }

  .irs-calc-row { flex-direction: column; align-items: stretch; }
  .irs-calc-row button { width: 100%; }

  .modal { max-width: none; width: calc(100% - 32px); }

  .new-user-form { flex-direction: column; align-items: stretch; }
  .new-user-form .field { min-width: 0; }

  .admin-table { display: block; overflow-x: auto; }
}

@media (max-width: 400px) {
  .card { padding: 22px; }
}
