/* Shared HRMS design tokens also reach Vuetify's detached menus and dialogs. */
html[data-hrms-theme="light"],
.v-application.theme--light {
  --hrms-bg: #f4f7f5;
  --hrms-surface: #ffffff;
  --hrms-surface-muted: #f0f5f2;
  --hrms-border: #dbe5de;
  --hrms-text: #20372a;
  --hrms-muted: #5d7165;
  --hrms-primary: #176247;
  --hrms-primary-soft: #e7f3ec;
  --hrms-primary-contrast: #ffffff;
  --hrms-danger: #b42332;
  --hrms-danger-soft: #fff0f1;
  --hrms-warning: #8b6200;
  --hrms-warning-soft: #fff7df;
  color-scheme: light;
}

html[data-hrms-theme="dark"],
.v-application.theme--dark {
  --hrms-bg: #101a14;
  --hrms-surface: #18271e;
  --hrms-surface-muted: #21352a;
  --hrms-border: #344e3e;
  --hrms-text: #e8f2eb;
  --hrms-muted: #adbfaf;
  --hrms-primary: #8edbb2;
  --hrms-primary-soft: #233e30;
  --hrms-primary-contrast: #10251b;
  --hrms-danger: #ffacb5;
  --hrms-danger-soft: #41252d;
  --hrms-warning: #f1cd78;
  --hrms-warning-soft: #3b3321;
  color-scheme: dark;
}

html,
body {
  background: var(--hrms-bg, #f4f7f5);
}

.v-application {
  background: var(--hrms-bg) !important;
  color: var(--hrms-text) !important;
}

/* Dark-theme action colors are light accents, so filled buttons need dark text. */
.v-application.theme--dark .v-btn:not(.v-btn--text):not(.v-btn--outlined):not(.v-btn--disabled):is(
  .primary, .secondary, .accent, .success, .warning, .error, .info
) {
  color: var(--hrms-primary-contrast) !important;
}

.v-application.theme--dark .v-btn:not(.v-btn--text):not(.v-btn--outlined):not(.v-btn--disabled):is(
  .primary, .secondary, .accent, .success, .warning, .error, .info
) .v-icon {
  color: inherit !important;
}

/* Keep the flex layout shrinkable: wide records scroll inside their table. */
.v-application .v-main,
.v-application .v-main__wrap,
.v-application .v-content,
.v-application .v-content__wrap,
.v-application .container,
.v-application .row > [class*="col"],
.v-application .v-card,
.v-application .v-data-table {
  min-width: 0;
}

.v-application :is(
  .management, .travel-dashboard, .leave-management-dashboard,
  .my-leave-page, .users-management-page, .attendance-management-page,
  .attendance-report-page, .opening-balance-page, .lookup-management-page,
  .lookup-types-page, .country-offices-page, .employee-grades-page,
  .leave-types-page, .office-timing-page, .country-weekends-page,
  .leave-ledger-page, .all-purchase-page, .all-rop-page
) {
  min-width: 0;
  max-width: 100%;
}

/* Existing management components share these neutral surface classes. */
.v-application :is(
  .header-card, .filter-card, .data-table-card, .request-table-card,
  .all-travel-filter-card, .all-travel-table-card, .summary-card,
  .dialog-header, .dialog-footer, .form-section, .switch-card,
  .travel-leg-table-container, .travel-leg-form-section, .attachment-header,
  .transport-summary-card, .transport-analytics-card, .rop-summary-card,
  .rop-inner-card, .rop-expense-header, .rop-checklist-header,
  .rop-checklist-image-preview, .purchase-summary-card, .purchase-inner-card,
  .purchase-item-header, .approval-section-icon, .users-table-actions,
  .users-step-content, .users-pagination, .users-stepper .v-stepper__header,
  .users-stepper .v-stepper__items, .attendance-employee-card,
  .attendance-summary-card, .attendance-stats-card, .attendance-management-actions,
  .attendance-management-pagination, .attendance-report-employee-card,
  .attendance-report-summary-card, .leave-ledger-results-header,
  .vms-approval-table-card, .table-toolbar, .leave-table-toolbar,
  .my-leave-pagination, .leave-management-pagination, .appearance-menu
) {
  background: var(--hrms-surface) !important;
  border-color: var(--hrms-border) !important;
  color: var(--hrms-text);
}

.v-application :is(
  .dialog-content, .users-dialog-content, .option-box, .nested-section,
  .travel-leg-container, .approval-card, .travel-review-info-box,
  .travel-status-option-box, .transport-summary-icon, .transport-analytics-icon,
  .rop-summary-icon, .rop-status-box, .rop-expense-total, .rop-expense-meta-box,
  .rop-checklist-file-mini, .rop-checklist-file-icon, .rop-checklist-preview-box,
  .rop-checklist-pdf-preview, .rop-approval-priority-box, .all-rop-priority-box,
  .purchase-summary-icon, .purchase-item-mini-icon, .purchase-item-total-preview,
  .purchase-item-grand-total, .purchase-approval-priority-box,
  .all-purchase-priority-box, .approval-region-icon, .approval-section-block,
  .project-activity-code, .project-activity-mini-icon, .project-activity-upload-box,
  .attendance-summary-icon, .employee-attendance-selection-bar,
  .attendance-report-stat, .lookup-switch-card, .lookup-types-switch-card,
  .my-leave-switch-card, .leave-ledger-switch-wrap, .close-btn
) {
  background: var(--hrms-surface-muted) !important;
  border-color: var(--hrms-border) !important;
}

.v-application :is(
  .header-icon, .dialog-icon, .section-icon, .primary-soft, .success-soft,
  .travel-leg-heading-icon, .travel-leg-section-icon, .attachment-header-icon,
  .rop-expense-header-icon, .rop-checklist-header-icon, .purchase-item-header-icon,
  .lookup-item-icon, .lookup-types-item-icon, .office-timing-region-icon,
  .weekends-day-icon, .grade-icon, .holiday-row-icon,
  .rop-approval-decision-section, .purchase-approval-decision-section
) {
  background: var(--hrms-primary-soft) !important;
}

.v-application :is(.warning-soft) {
  background: var(--hrms-warning-soft) !important;
}

.v-application :is(.error-soft, .delete-icon) {
  background: var(--hrms-danger-soft) !important;
}

/* Text classes are explicit so status chips and colored actions retain meaning. */
.v-application :is(
  .page-title, .summary-value, .table-primary-text, .dialog-title,
  .section-title, .switch-title, .approval-name, .empty-title, .delete-title,
  .travel-leg-title, .travel-leg-date, .travel-leg-location, .travel-leg-project,
  .travel-leg-days, .travel-leg-section-title, .travel-leg-empty-title,
  .all-travel-date, .all-travel-empty-title, .travel-review-info-value,
  .vehicle-days, .vehicle-leg-route, .attachment-title,
  .attachment-selected-file.has-file, .attachment-empty-title,
  .transport-summary-value, .transport-amount, .transport-analytics-title,
  .rop-summary-value, .rop-amount, .rop-expense-title, .rop-expense-amount,
  .rop-expense-total strong, .rop-expense-meta-item strong, .rop-expense-empty-title,
  .rop-checklist-title, .rop-checklist-name, .rop-checklist-preview-name,
  .rop-checklist-empty-title, .purchase-summary-value, .purchase-amount,
  .purchase-item-title, .purchase-item-amount, .purchase-item-total-preview strong,
  .purchase-item-grand-total strong, .purchase-item-empty-title,
  .approval-section-title, .project-activity-project, .attendance-employee-name,
  .attendance-summary-value, .attendance-report-employee-name,
  .attendance-report-stat-value, .table-toolbar-title,
  .leave-ledger-results-title, .lookup-type-label
) {
  color: var(--hrms-text) !important;
}

.v-application :is(
  .page-subtitle, .summary-label, .table-secondary-text, .dialog-subtitle,
  .section-description, .option-label, .switch-subtitle, .nested-title,
  .radio-label, .approval-role, .empty-description, .delete-description,
  .travel-leg-subtitle, .travel-leg-secondary-text, .travel-leg-activity,
  .travel-leg-days span, .travel-leg-section-desc, .travel-leg-empty-text,
  .all-travel-purpose, .all-travel-empty-text, .travel-review-info-label,
  .travel-current-status-label, .vehicle-leg-meta, .attachment-subtitle,
  .attachment-selected-file, .attachment-help-text, .attachment-empty-text,
  .transport-summary-label, .transport-analytics-description,
  .rop-summary-label, .rop-subsection-title, .rop-expense-subtitle,
  .rop-expense-remarks, .rop-expense-total span, .rop-expense-meta-item span,
  .rop-expense-empty-text, .rop-checklist-subtitle, .rop-checklist-attachment-name,
  .rop-checklist-file-help, .rop-checklist-preview-label, .rop-checklist-empty-text,
  .rop-checklist-preview-message, .purchase-summary-label,
  .purchase-item-subtitle, .purchase-item-remarks, .purchase-item-total-preview span,
  .purchase-item-grand-total span, .purchase-item-empty-text,
  .approval-section-subtitle, .project-activity-code, .project-activity-file-help,
  .users-stepper .v-stepper__label, .users-dialog-card h4.text--secondary,
  .attendance-summary-label, .missing-attendance-remarks, .employee-attendance-remarks,
  .attendance-report-stat-label, .lookup-record-count, .lookup-description,
  .lookup-switch-hint, .lookup-types-count, .lookup-types-description,
  .lookup-types-switch-hint, .holiday-result-count, .record-count,
  .my-leave-page-note, .my-leave-truncated, .leave-ledger-results-description,
  .grades-filter-info, .weekends-filter-info, .office-switch-help,
  .leave-type-switch-help, .date-cell
) {
  color: var(--hrms-muted) !important;
}

.v-application :is(.request-id, .attachment-file-link) {
  color: var(--hrms-primary) !important;
}

.v-application .request-id {
  background: var(--hrms-primary-soft) !important;
  border-color: var(--hrms-border) !important;
}

/* Outlined inputs continue using Vuetify's native focus/error border colors. */
.v-application .search-field .v-input__slot,
.v-application .travel-leg-readonly .v-input__slot {
  background: var(--hrms-surface-muted) !important;
  border-color: var(--hrms-border) !important;
}

.v-application .travel-leg-readonly input,
.v-application .vehicle-filter-switch .v-label,
.v-application .leave-ledger-switch-wrap .v-label {
  color: var(--hrms-muted) !important;
}

.v-application :is(
  .status-filter, .lookup-status-filter, .lookup-types-status-filter,
  .office-timing-filter-toggle, .approval-panel, .radio-box
) {
  border-color: var(--hrms-border) !important;
}

.v-application:is(.theme--light, .theme--dark) :is(
  .lookup-status-filter, .lookup-types-status-filter, .office-timing-filter-toggle
) .v-btn {
  background: var(--hrms-surface) !important;
  color: var(--hrms-muted) !important;
}

.v-application:is(.theme--light, .theme--dark) :is(
  .lookup-status-filter, .lookup-types-status-filter, .office-timing-filter-toggle
) .v-btn.v-btn--active {
  background: var(--hrms-primary-soft) !important;
  color: var(--hrms-primary) !important;
}

/* The wrapper, not the document, owns horizontal scrolling. */
.v-application .v-data-table,
.v-application .v-simple-table,
.v-application .ledger-table {
  max-width: 100%;
  background-color: var(--hrms-surface) !important;
  color: var(--hrms-text) !important;
}

.v-application .v-data-table__wrapper {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: var(--hrms-border) var(--hrms-surface-muted);
}

.v-application .v-data-table table,
.v-application .v-data-table td,
.v-application .v-data-table th,
.v-application .v-data-footer,
.v-application .ledger-table td,
.v-application .ledger-table th {
  border-color: var(--hrms-border) !important;
}

.v-application:is(.theme--light, .theme--dark) .v-data-table .v-data-table__wrapper table thead th,
.v-application .ledger-table th {
  background: var(--hrms-surface-muted) !important;
  color: var(--hrms-muted) !important;
}

.v-application :is(
  .travel-table, .travel-leg-table, .all-travel-table, .attachment-table,
  .rop-expense-table, .rop-checklist-table, .purchase-item-table,
  .attendance-report-table
) tbody td {
  color: var(--hrms-text) !important;
}

.v-application .v-data-table tbody tr:hover:not(.v-data-table__expanded__content),
.v-application .ledger-table tr:hover {
  background: var(--hrms-surface-muted) !important;
}

.v-application .ledger-table tr:nth-child(even) {
  background: var(--hrms-surface-muted) !important;
}

/* Preserve the attendance report's semantic row colors in either appearance. */
.v-application .attendance-report-weekend td {
  background: var(--hrms-danger-soft) !important;
}

.v-application :is(
  .attendance-report-leave td, .attendance-report-field-cell,
  .attendance-report-half-day
) {
  background: var(--hrms-primary-soft) !important;
}

.v-application .attendance-report-missing td {
  background: var(--hrms-surface-muted) !important;
}

.v-application.theme--dark .attendance-report-holiday td {
  background: #203b3e !important;
}

.v-application.theme--dark .download-repository-container {
  background: var(--hrms-bg) !important;
}

.v-application.theme--dark .download-repository-container :is(
  .header-section, .category-section
) {
  background: var(--hrms-surface) !important;
  border-color: var(--hrms-border) !important;
}

.v-application.theme--dark .download-repository-container .loading-card {
  background: var(--hrms-surface-muted) !important;
}

.v-application .page-header,
.v-application .table-toolbar,
.v-application .table-toolbar-info,
.v-application .dialog-header,
.v-application .dialog-footer {
  gap: 12px;
}

.v-application .page-header,
.v-application .table-toolbar,
.v-application .dialog-footer,
.v-application :is(
  .filter-actions, .lookup-filter-actions, .lookup-types-filter-actions,
  .office-filter-actions, .holiday-filter-actions, .my-leave-filter-actions,
  .leave-server-filter-actions, .leave-toolbar-actions, .all-purchase-filter-actions,
  .all-rop-filter-actions, .attendance-management-actions, .users-table-actions,
  .leave-ledger-actions, .purchase-approval-filter-actions
) {
  flex-wrap: wrap;
}

.v-application .page-header > .d-flex,
.v-application .dialog-header > .d-flex,
.v-application .header-copy,
.v-application .table-toolbar-info,
.v-application .table-search,
.v-application .v-input {
  min-width: 0;
}

.v-application .page-title,
.v-application .dialog-title,
.v-application .section-title {
  overflow-wrap: anywhere;
}

.v-application :is(.status-filter, .leave-status-filter, .office-timing-filter-toggle) {
  max-width: 100%;
  height: auto !important;
  flex-wrap: wrap;
}

.v-application .v-dialog {
  max-width: calc(100% - 32px);
}

.v-application .v-dialog--fullscreen {
  max-width: 100%;
}

.v-application :is(button, a, [role="button"], [tabindex]):focus-visible {
  outline: 3px solid var(--hrms-primary);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 3000;
  padding: 12px 18px;
  border-radius: 8px;
  background: var(--hrms-primary, #176247);
  color: var(--hrms-primary-contrast, #fff) !important;
  font-weight: 700;
  transform: translateY(calc(-100% - 24px));
}

.skip-link:focus,
.skip-link:focus-visible {
  transform: translateY(0);
}

@media (max-width: 959px) {
  .v-application .page-header {
    align-items: flex-start;
  }

  .v-application :is(
    .filter-actions, .lookup-filter-actions, .lookup-types-filter-actions,
    .office-filter-actions, .holiday-filter-actions, .my-leave-filter-actions,
    .leave-server-filter-actions, .all-purchase-filter-actions,
    .all-rop-filter-actions, .purchase-approval-filter-actions
  ) {
    justify-content: flex-start;
  }

  .v-application .approval-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 599px) {
  .v-application .page-title {
    font-size: 20px;
    line-height: 1.35;
  }

  .v-application .page-subtitle {
    font-size: 12px;
    line-height: 1.5;
  }

  .v-application .page-header > .d-flex {
    width: 100%;
  }

  .v-application .page-header .primary-action-btn {
    margin-left: 0 !important;
    min-height: 40px !important;
  }

  .v-application .table-toolbar {
    align-items: flex-start;
  }

  .v-application .table-toolbar-info {
    flex-wrap: wrap;
  }

  .v-application .table-toolbar .table-search {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
  }

  .v-application :is(
    .status-filter, .lookup-status-filter, .lookup-types-status-filter,
    .leave-status-filter, .office-timing-filter-toggle
  ) {
    flex-wrap: wrap;
    height: auto !important;
    overflow: visible;
  }

  .v-application :is(
    .status-filter, .lookup-status-filter, .lookup-types-status-filter,
    .leave-status-filter, .office-timing-filter-toggle
  ) .v-btn {
    min-height: 38px !important;
    flex: 1 0 auto;
  }

  .v-application .v-data-footer {
    justify-content: center;
    gap: 4px;
    padding: 8px;
  }

  .v-application .v-data-footer__select {
    margin: 0 8px;
  }

  .v-application .v-data-footer__pagination {
    margin: 0 8px;
  }

  .v-application :is(.dialog-header, .dialog-footer) {
    padding: 14px 16px !important;
  }

  .v-application .dialog-header .close-btn {
    flex-shrink: 0;
    min-width: 40px;
    min-height: 40px;
  }

  .v-application .dialog-content {
    padding: 14px 12px !important;
  }

  .v-application .form-section {
    padding: 14px 12px 4px;
  }

  .v-application .dialog-footer .v-btn {
    min-height: 40px !important;
    margin: 0;
    flex: 1 1 auto;
  }

  .v-application .approval-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .v-application .users-stepper .v-stepper__header {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .v-application .users-stepper .v-stepper__step {
    flex-shrink: 0;
  }

  .v-application .download-repository-container {
    padding: 12px;
  }

  .v-application .download-repository-container :is(.header-section, .category-section) {
    padding: 20px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .v-application .v-card,
  .v-application .summary-card,
  .v-application .download-all-btn,
  .skip-link {
    transition: none !important;
  }

  .v-application .download-repository-container .loading-card {
    animation: none !important;
  }

  .v-application .summary-card:hover,
  .v-application .download-all-btn:hover {
    transform: none !important;
  }
}
