:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #d8dee9;
  --text: #1a1d26;
  --muted: #5c6370;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --work: #dcfce7;
  --work-border: #86efac;
  --leave: #dbeafe;
  --leave-border: #93c5fd;
  --sick: #fef9c3;
  --sick-border: #fde047;
  --rest: #f1f5f9;
  --rest-border: #cbd5e1;
  --absence: #fee2e2;
  --absence-border: #fca5a5;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

body.app {
  height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: clamp(0.65rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 1.5rem);
  padding-left: clamp(0.75rem, 2vw, 1.5rem);
  padding-right: max(clamp(0.75rem, 2vw, 1.5rem), 12rem);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  position: relative;
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: rgb(190, 145, 70);
}

.header__title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.header__logo {
  display: block;
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
  flex-shrink: 0;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.app-nav__link {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.82rem;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid transparent;
}

.app-nav__link:hover {
  color: var(--text);
  background: var(--bg);
}

.app-nav__link--active {
  color: var(--primary);
  background: #e8eef9;
  border-color: #93c5fd;
  font-weight: 600;
}

.header__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
  margin-left: auto;
}

.header__account {
  position: fixed;
  top: clamp(0.65rem, 1.5vw, 1rem);
  right: clamp(0.75rem, 2vw, 1.5rem);
  left: auto;
  z-index: 300;
  flex-shrink: 0;
}

.header__controls label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.header__controls select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: var(--surface);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(320px, 28vw);
  gap: clamp(0.5rem, 1.5vw, 1rem);
  padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 1.5rem);
  max-width: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  align-items: stretch;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    overflow: auto;
  }
}

.layout--legend-collapsed {
  grid-template-columns: 1fr;
}

.layout--legend-collapsed .panel--legend {
  display: none;
}

#btnToggleLegend[aria-expanded="true"] {
  background: #e8eef9;
  border-color: #93c5fd;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel--main {
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel--legend {
  padding: 1rem;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
}

.panel--legend h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.panel__toolbar {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel__heading {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.references-table {
  max-width: 960px;
}

.schedule-type-switch {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
}

.schedule-type-switch legend {
  padding: 0 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.schedule-type-switch__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.schedule-fields {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.schedule-fields[hidden] {
  display: none !important;
}

.schedule-fields__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.weekday-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.35rem 0.5rem;
}

.weekday-grid label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.schedule-preview {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.schedule-preview span {
  color: var(--text);
  font-weight: 600;
}

.panel__toolbar .btn--sm {
  margin-left: auto;
}

.status-msg {
  font-size: 0.85rem;
  color: var(--muted);
}

.status-msg--ok {
  color: #15803d;
}

.status-msg--err {
  color: var(--danger);
}

.table-wrap {
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.empty-state {
  padding: clamp(1.5rem, 4vw, 3rem);
  text-align: center;
  color: var(--muted);
}

.timesheet {
  border-collapse: collapse;
  font-size: clamp(0.65rem, 0.75vw, 0.8rem);
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

.timesheet th,
.timesheet td {
  border: 1px solid var(--border);
  padding: 0;
  text-align: center;
  vertical-align: middle;
}

.timesheet th {
  background: #eef2ff;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.35rem 0.25rem;
  white-space: nowrap;
}

.timesheet th.sticky-col,
.timesheet td.sticky-col {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  text-align: left;
  padding: 0.35rem 0.65rem;
  width: 1%;
  white-space: nowrap;
}

.timesheet th.sticky-col-2,
.timesheet td.sticky-col-2 {
  position: sticky;
  left: var(--sticky-col-1-width, 0px);
  z-index: 1;
  background: var(--surface);
  text-align: left;
  padding: 0.35rem 0.65rem;
  width: 1%;
  white-space: nowrap;
}

.timesheet thead th.sticky-col,
.timesheet thead th.sticky-col-2 {
  z-index: 3;
  background: #eef2ff;
}

.timesheet th.rest-day {
  background: #e2e8f0;
  color: var(--muted);
}

.timesheet th.day-col,
.timesheet td.cell {
  width: var(--timesheet-cell-size, 2.2rem);
  min-width: var(--timesheet-cell-size, 2.2rem);
  max-width: var(--timesheet-cell-size, 2.2rem);
}

.timesheet td.cell {
  height: var(--timesheet-cell-size, 2rem);
  cursor: pointer;
  font-weight: 600;
  font-size: clamp(0.6rem, 0.7vw, 0.7rem);
  transition: filter 0.1s;
}

.timesheet td.cell:hover {
  filter: brightness(0.95);
}

.timesheet td.cell--work { background: var(--work); }
.timesheet td.cell--leave { background: var(--leave); }
.timesheet td.cell--sick { background: var(--sick); }
.timesheet td.cell--rest { background: var(--rest); color: var(--muted); }
.timesheet td.cell--inactive {
  background: #f3f4f6;
  cursor: default;
  color: transparent;
}

.timesheet td.cell--readonly {
  cursor: default;
}

.timesheet td.cell--readonly:hover {
  filter: none;
}

.timesheet td.cell--absence { background: var(--absence); }
.timesheet td.cell--trip,
.timesheet td.cell--study,
.timesheet td.cell--downtime { background: #faf5ff; }

.emp-name {
  font-weight: 500;
}

.emp-tab {
  font-size: 0.7rem;
  color: var(--muted);
}

.btn {
  padding: 0.45rem 0.85rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-hover);
}

.btn--secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn--secondary:hover {
  background: var(--bg);
}

.btn--danger {
  background: var(--danger);
  color: #fff;
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.legend-item {
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  gap: 0.5rem;
  align-items: start;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  cursor: default;
}

.legend-item:hover {
  background: var(--bg);
}

.legend-item__code {
  font-weight: 700;
  text-align: center;
  padding: 0.15rem 0;
  border-radius: 4px;
  font-size: 0.75rem;
}

.legend-item__code--work { background: var(--work); }
.legend-item__code--leave { background: var(--leave); }
.legend-item__code--sick { background: var(--sick); }
.legend-item__code--rest { background: var(--rest); }
.legend-item__code--absence { background: var(--absence); }

.legend-item__label {
  color: var(--text);
  line-height: 1.35;
}

.legend-item__num {
  color: var(--muted);
  font-size: 0.7rem;
}

.legend-note {
  margin: 1rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.legend-note a {
  color: var(--primary);
}

.dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  max-width: min(420px, calc(100vw - 2rem));
  width: calc(100% - 2rem);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.dialog form {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.dialog h3 {
  margin: 0;
  font-size: 1.1rem;
}

.dialog label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.dialog input,
.dialog select {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  color: var(--text);
}

.dialog input[type="date"] {
  min-height: 2.5rem;
}

.dialog-hint {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.dialog__actions .btn--primary {
  margin-left: auto;
}

#hoursLabel[hidden] {
  display: none !important;
}

#statusLabel[hidden] {
  display: none !important;
}

a.btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.page-main {
  padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.75rem, 2vw, 1.5rem);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-main > .panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.table-wrap--employees {
  flex: 1;
  min-height: 0;
}

.employees-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.employees-table th,
.employees-table td {
  border: 1px solid var(--border);
  padding: 0.6rem 0.75rem;
  text-align: left;
  vertical-align: middle;
}

.employees-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.employees-table th {
  background: #eef2ff;
  font-weight: 600;
}

.employees-table__filters th {
  background: #f8fafc;
  padding: 0.35rem 0.5rem;
  font-weight: normal;
}

.employees-table__filters .col-filter {
  width: 100%;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: normal;
  background: #fff;
}

.employees-table__filters select.col-filter {
  cursor: pointer;
}

.employees-table__filters .btn {
  width: 100%;
}

.employees-table tbody tr:hover {
  background: #f8fafc;
}

.employees-table .actions-cell {
  white-space: nowrap;
}

.employees-table .actions-cell .btn + .btn {
  margin-left: 0.35rem;
}

.emp-name-cell {
  font-weight: 500;
}

.id-cell {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.status-badge--active {
  background: #dcfce7;
  color: #15803d;
}

.status-badge--fired {
  background: #fee2e2;
  color: #b91c1c;
}

.btn--sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.search-input--inline {
  width: 180px;
  margin-bottom: 0;
}

.employee-count {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
}

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dropdown__arrow {
  font-size: 0.7rem;
  opacity: 0.7;
}

.dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 100;
  overflow: hidden;
}

.dropdown__item {
  display: block;
  width: 100%;
  padding: 0.55rem 0.85rem;
  border: none;
  background: none;
  text-align: left;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.dropdown__item:hover {
  background: var(--bg);
}

.dialog--wide {
  max-width: min(520px, calc(100vw - 2rem));
}

@media (max-width: 900px) {
  .header__controls {
    width: 100%;
  }

  .search-input--inline {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .mapping-row {
    grid-template-columns: 1fr;
  }

  .header h1 {
    font-size: 1.15rem;
  }

  .btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
  }
}

.import-summary {
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
}

.import-errors {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--danger);
  font-size: 0.85rem;
  max-height: 200px;
  overflow-y: auto;
}

.import-result {
  padding: 1.25rem;
}

.import-result h3 {
  margin: 0 0 0.75rem;
}

.btn--file {
  cursor: pointer;
  margin: 0;
}

.btn--file input {
  display: none;
}

.btn--block {
  display: flex;
  justify-content: center;
  width: 100%;
}

.sample-format-name {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.mapping-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.mapping-row {
  display: grid;
  grid-template-columns: minmax(100px, 1fr) minmax(180px, 1.4fr) 110px;
  gap: 0.65rem;
  align-items: center;
}

.mapping-row--header {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding-bottom: 0.15rem;
  border-bottom: 1px solid var(--border);
}

.mapping-row__value {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mapping-row__code,
.mapping-row__hours {
  width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.mapping-row__hours-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.mapping-row__hours-wrap[hidden] {
  display: none !important;
}

.mapping-row__hours-label {
  font-size: 0.72rem;
  color: var(--muted);
}

.mapping-row__hours[hidden] {
  display: none !important;
}

.calendar-page .calendar-panel {
  overflow: auto;
}

.calendar-page__intro {
  padding: 0.75rem 1rem 0;
}

.calendar-note {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.calendar-note a {
  color: var(--primary);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  padding: 0 1rem 1rem;
}

@media (max-width: 900px) {
  .calendar-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .calendar-grid {
    grid-template-columns: 1fr;
  }
}

.month-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fafbfc;
}

.month-card__title {
  margin: 0;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  background: #eef2ff;
  border-bottom: 1px solid var(--border);
}

.month-card__table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
}

.month-card__table th,
.month-card__table td {
  text-align: center;
  padding: 0.28rem 0.1rem;
  border: 1px solid #e5e7eb;
}

.month-card__table th {
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
}

.month-card__table td {
  background: #fff;
}

.month-card__table td.day-cell--weekend {
  background: var(--rest);
  color: var(--muted);
}

.month-card__table td.day-cell--holiday {
  background: #fecaca;
  color: #991b1b;
  font-weight: 700;
}

.month-card__table td.day-cell--transfer {
  background: #fed7aa;
  color: #9a3412;
  font-weight: 700;
}

.calendar-list {
  padding: 0 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.calendar-list h2 {
  margin: 1rem 0 0.75rem;
  font-size: 1rem;
}

.holiday-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.holiday-list__item {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.75rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  font-size: 0.88rem;
}

.holiday-list__item--transfer {
  border-color: #fdba74;
  background: #fff7ed;
}

.holiday-list__date {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.holiday-list__name {
  color: var(--muted);
}

@media (max-width: 640px) {
  .holiday-list__item {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #f0f2f5 0%, #e8ecf4 100%);
}

.login-card {
  width: min(100%, 24rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.login-card__brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-card__brand h1 {
  margin: 0.75rem 0 0;
  font-size: 1.5rem;
  color: rgb(190, 145, 70);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
}

.login-form input {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}

.login-form__submit {
  width: 100%;
  margin-top: 0.25rem;
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: nowrap;
  padding: 0.35rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-user__name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(36vw, 14rem);
}

.roles-info {
  padding: 0 1rem 0.75rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.table-actions {
  white-space: nowrap;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
