:root {
  --ink: #17223b;
  --muted: #6f7b91;
  --line: #e3e9f1;
  --surface: #fff;
  --page: #f3f6fa;
  --brand: #1558d6;
  --brand-dark: #0f43a6;
  --working-bg: #eaf8f0;
  --working-fg: #23724a;
  --dayoff-bg: #e7f0ff;
  --dayoff-fg: #1f5ba7;
  --vacation-bg: #fff0d2;
  --vacation-fg: #965900;
  --sick-bg: #ffe5e5;
  --sick-fg: #aa3030;
  --other-bg: #eceff4;
  --other-fg: #586277;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .65; }
h1, h2, p { margin: 0; }
.hidden { display: none !important; }

.dashboard { min-width: 760px; padding: 26px; }
.topbar, .title-group, .account-actions, .filters-card, .month-nav,
.date-filter, .list-filter, .legend, .legend span, .modal-heading,
.modal-actions, .right-actions, .access-toolbar {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.title-group { align-items: flex-start; gap: 14px; }
.title-group h1 { font-size: 29px; line-height: 1.1; }
.title-group > div > p:last-child { margin-top: 7px; color: var(--muted); }
.account-actions { gap: 9px; }
.eyebrow {
  margin-bottom: 5px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 17px;
  background: linear-gradient(145deg, #1558d6, #0e3d9b);
  box-shadow: 0 12px 28px rgba(21, 88, 214, .22);
  color: #fff;
  font-size: 26px;
  font-weight: 900;
}
.brand-mark.small { width: 48px; height: 48px; border-radius: 14px; font-size: 22px; }

.user-chip {
  display: flex;
  min-width: 170px;
  padding: 8px 13px;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.user-chip strong { font-size: 13px; }
.user-chip span { margin-top: 2px; color: var(--muted); font-size: 11px; }

.primary-button, .secondary-button, .danger-button, .icon-button, .month-title {
  min-height: 39px;
  padding: 0 15px;
  border-radius: 10px;
  font-weight: 750;
}
.primary-button { border: 1px solid var(--brand); background: var(--brand); color: #fff; }
.primary-button:hover { background: var(--brand-dark); }
.secondary-button { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.secondary-button:hover { background: #f8fafc; }
.danger-button { border: 1px solid #f1c4c4; background: #fff1f1; color: #a52b2b; }
.wide { width: 100%; }
.compact { min-height: 32px; padding: 0 10px; font-size: 12px; }
.icon-button { width: 40px; padding: 0; border: 0; background: #eef3f9; font-size: 20px; }
.month-title { min-width: 185px; border: 0; background: transparent; font-size: 17px; text-transform: capitalize; }

.filters-card {
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  background: var(--surface);
}
.month-nav { align-self: center; gap: 6px; }
.date-filter, .list-filter { align-items: flex-end; gap: 9px; }
.filters-card label, .modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #536177;
  font-size: 11px;
  font-weight: 760;
}
.filters-card input, .filters-card select,
.modal input, .modal select, .modal textarea {
  min-height: 39px;
  padding: 8px 10px;
  border: 1px solid #ccd6e3;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  outline: none;
}
.filters-card input:focus, .filters-card select:focus,
.modal input:focus, .modal select:focus, .modal textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 88, 214, .1);
}
#agent-search { width: 170px; }

.legend {
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 17px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}
.legend span { gap: 7px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.working { background: var(--working-bg); color: var(--working-fg); }
.day-off { background: var(--dayoff-bg); color: var(--dayoff-fg); }
.vacation { background: var(--vacation-bg); color: var(--vacation-fg); }
.sick { background: var(--sick-bg); color: var(--sick-fg); }
.other { background: var(--other-bg); color: var(--other-fg); }

.calendar-card {
  margin-top: 17px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 9px 30px rgba(30, 50, 84, .07);
}
.calendar-scroll { max-height: calc(100vh - 250px); overflow: auto; }
.calendar-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; }
.calendar-table th, .calendar-table td {
  min-width: 91px;
  height: 59px;
  padding: 6px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.calendar-table thead th {
  position: sticky;
  z-index: 4;
  top: 0;
  height: 63px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
}
.calendar-table thead th span, .calendar-table thead th strong { display: block; }
.calendar-table thead th strong { margin-top: 3px; color: var(--ink); font-size: 18px; }
.calendar-table thead th.weekend { background: #fff8f1; }
.calendar-table thead th.today { box-shadow: inset 0 3px 0 var(--brand); }
.calendar-table .agent-column {
  position: sticky;
  z-index: 3;
  left: 0;
  min-width: 220px;
  max-width: 220px;
  padding: 10px 14px;
  background: var(--surface);
  text-align: left;
}
.calendar-table thead .agent-column { z-index: 6; background: #f8fafc; }
.calendar-table tfoot td, .calendar-table tfoot .agent-column {
  position: sticky;
  z-index: 4;
  bottom: 0;
  background: #f8fafc;
}
.calendar-table tfoot .agent-column { z-index: 5; left: 0; }
.agent-name { overflow: hidden; font-size: 13px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.agent-column small { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.status-cell {
  width: 100%;
  min-height: 41px;
  padding: 5px 7px;
  border: 0;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 850;
  line-height: 1.1;
}
.status-cell:not(:disabled):hover { filter: brightness(.97); outline: 2px solid rgba(21, 88, 214, .16); }
.status-cell:disabled { opacity: 1; }
.working-count strong, .working-count span { display: block; }
.working-count strong { color: var(--working-fg); font-size: 19px; }
.working-count span { margin-top: 2px; color: var(--muted); font-size: 9px; }

.loading-state, .empty-state {
  display: flex;
  min-height: 330px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--muted);
}
.spinner { width: 30px; height: 30px; margin-bottom: 13px; border: 3px solid #dce5f2; border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-banner, .form-error { color: #a52b2b; }
.error-banner { margin-top: 14px; padding: 12px 14px; border: 1px solid #efc5c5; border-radius: 10px; background: #fff1f1; }
.form-error { padding: 10px 11px; border-radius: 8px; background: #fff1f1; font-size: 12px; }

.login-page { display: grid; min-height: 100vh; padding: 24px; place-items: center; }
.login-card { width: min(440px, 100%); padding: 36px; border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: 0 24px 70px rgba(20, 39, 74, .13); }
.login-card .brand-mark { margin-bottom: 25px; }
.login-card h1 { font-size: 30px; }
.login-copy { margin-top: 10px; color: var(--muted); line-height: 1.55; }
.stack-form { display: grid; gap: 16px; margin-top: 26px; }
.stack-form label { display: grid; gap: 7px; color: #526078; font-size: 12px; font-weight: 760; }
.stack-form input { min-height: 45px; padding: 10px 12px; border: 1px solid #cbd5e2; border-radius: 10px; outline: none; }
.stack-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(21, 88, 214, .1); }

dialog.modal { width: min(560px, calc(100vw - 30px)); max-height: calc(100vh - 30px); padding: 0; overflow: auto; border: 0; border-radius: 18px; box-shadow: 0 28px 90px rgba(10, 23, 47, .3); }
dialog.modal::backdrop { background: rgba(10, 22, 43, .52); backdrop-filter: blur(2px); }
dialog.large-modal { width: min(900px, calc(100vw - 30px)); }
.modal-content { padding: 24px; }
.modal-heading { align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-heading h2 { font-size: 22px; }
.close-button { width: 35px; height: 35px; border: 0; border-radius: 50%; background: #f1f4f8; color: var(--ink); font-size: 22px; }
.modal label { margin-top: 14px; }
.modal textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.modal label small { color: var(--muted); font-size: 10px; font-weight: 500; }
.modal-actions { justify-content: space-between; gap: 15px; margin-top: 23px; padding-top: 17px; border-top: 1px solid var(--line); }
.modal-actions.end { justify-content: flex-end; }
.right-actions { gap: 8px; }
.checkbox-row { flex-direction: row !important; align-items: center; }
.checkbox-row input { min-height: 0; }

.access-toolbar { justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.access-toolbar p { color: var(--muted); font-size: 12px; }
.users-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
.users-table th { background: #f8fafc; color: var(--muted); }
.users-table td strong, .users-table td small { display: block; }
.users-table td small { margin-top: 3px; color: var(--muted); }
.badge { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.badge.active { background: var(--working-bg); color: var(--working-fg); }
.badge.inactive { background: var(--other-bg); color: var(--other-fg); }
.audit-panel { margin-top: 20px; color: var(--muted); font-size: 12px; }
.audit-panel summary { cursor: pointer; font-weight: 750; }
.audit-list { display: grid; gap: 7px; margin-top: 12px; }
.audit-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 8px 10px; border-radius: 8px; background: #f7f9fc; }
.audit-list time { white-space: nowrap; }

.toast { position: fixed; z-index: 300; top: 18px; left: 50%; padding: 11px 16px; transform: translate(-50%, -25px); border-radius: 10px; background: #1d2b45; color: #fff; opacity: 0; pointer-events: none; transition: .2s; font-size: 13px; box-shadow: 0 12px 35px rgba(0, 0, 0, .2); }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: #a52b2b; }

@media (max-width: 1180px) {
  .filters-card { align-items: stretch; flex-wrap: wrap; }
  .month-nav { align-self: flex-end; }
}

@media (max-width: 760px) {
  .dashboard { padding: 16px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .account-actions { width: 100%; flex-wrap: wrap; }
  .user-chip { flex: 1; }
  .filters-card, .date-filter, .list-filter { align-items: stretch; flex-direction: column; }
  #agent-search { width: auto; }
  .form-grid { grid-template-columns: 1fr; }
}
