:root {
  color-scheme: light dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  background-attachment: fixed;
  color: #1a1a1a;
}

button {
  cursor: pointer;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 7px 14px;
  font: inherit;
  font-weight: 500;
  color: #334155;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

button:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.error {
  color: #c0392b;
  font-size: 0.85rem;
}

/* Login screen */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #f5f6f8 45%, #eef2ff 100%);
  padding: 16px;
}

.login-form {
  position: relative;
  overflow: hidden;
  background: #fff;
  padding: 36px 32px 32px;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  box-shadow:
    0 20px 40px -14px rgba(37, 99, 235, 0.22),
    0 2px 6px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(340px, 90vw);
  animation: login-card-in 0.35s ease-out;
}

.login-form::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
}

@keyframes login-card-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-header {
  text-align: center;
}

.login-icon {
  display: block;
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.login-form h1 {
  margin: 0;
  font-size: 1.4rem;
  color: #1e293b;
}

.login-subtitle {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: #64748b;
}

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
}

.login-form input {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font: inherit;
  font-weight: 400;
  color: #1a1a1a;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-form input:hover {
  border-color: #94a3b8;
}

.login-form input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.login-form button[type="submit"] {
  margin-top: 6px;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.login-form button[type="submit"]:hover {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.42);
}

.login-form button[type="submit"]:active {
  transform: translateY(0);
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.35);
}

.login-form button[type="submit"]:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.login-form .error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
}

/* Role badges */
.role-badge {
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.role-badge.role-viewer {
  background: #eee;
  color: #555;
}

.role-badge.role-vip {
  background: #fef3c7;
  color: #92400e;
}

.role-badge.role-editor {
  background: #dcfce7;
  color: #15803d;
}

.role-badge.role-leader {
  background: #dbeafe;
  color: #1d4ed8;
}

.username {
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
}

/* Shell */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
  opacity: 0.9;
}

.app-header h1 {
  margin: 0;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header h1::before {
  content: "📊";
  font-size: 1.2rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  padding: 6px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#change-password-btn {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #bfdbfe;
}

#change-password-btn:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

#logout-btn {
  color: #b91c1c;
  background: #fff;
  border-color: #fecaca;
}

#logout-btn:hover {
  background: #fef2f2;
  border-color: #fca5a5;
}

.loading-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 4px 10px;
  border-radius: 999px;
}

.loading-indicator[hidden] {
  display: none;
}

.loading-indicator .spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #ccc;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.tabs {
  display: flex;
  gap: 4px;
  margin: 10px 20px 0;
  padding: 3px;
  background: #e2e8f0;
  border-radius: 9px;
  width: fit-content;
}

.tab-btn {
  border: none;
  border-radius: 6px;
  background: transparent;
  padding: 6px 18px;
  font-size: 0.85rem;
  color: #475569;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.tab-btn.active {
  background: #fff;
  color: #2563eb;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
}

.filter-bar {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  align-items: flex-start;
  margin: 10px 20px;
  padding: 10px 16px;
  background: #fff;
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
}

.label-hint {
  font-style: italic;
  font-weight: 400;
  color: #94a3b8;
  font-size: 0.75rem;
}

.filter-bar select {
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #f8fafc;
  font: inherit;
  font-weight: 400;
  color: #1a1a1a;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.filter-bar select:hover {
  border-color: #94a3b8;
}

.filter-bar select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: #fff;
}

.filter-bar select[multiple] {
  min-width: 170px;
}

.filter-bar select[multiple] option:checked {
  background: linear-gradient(#2563eb, #2563eb);
  color: #fff;
}

.filter-bar select[multiple] option {
  padding: 3px 6px;
  border-radius: 3px;
}

.quarter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quarter-btn {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #334155;
}

.quarter-btn:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}

.quarter-btn.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.filter-static {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #334155;
}

.filter-static strong {
  padding: 6px 12px;
  border-radius: 6px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-weight: 600;
}

.refresh-btn {
  font-size: 1.1rem;
  line-height: 1;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #2563eb;
  background: #eff6ff;
  border-color: #bfdbfe;
  transition: background 0.15s, border-color 0.15s, transform 0.3s;
}

.refresh-btn:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  transform: rotate(90deg);
}

#tab-content {
  padding: 0 20px 20px;
}

#leaderboard-mount {
  padding: 0 20px 12px;
}

.leaderboard {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 16px;
}

.leaderboard-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.leaderboard-top {
  margin: 0 0 8px;
  padding-left: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  list-style: none;
  padding-left: 0;
}

.leaderboard-me {
  margin: 0;
  font-size: 0.85rem;
  color: #444;
}

.leaderboard-hint {
  padding: 0;
}

.hint {
  color: #666;
  padding: 12px 20px;
}

/* KPI table */
.table-scroll {
  overflow-x: auto;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.kpi-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8rem;
  white-space: nowrap;
}

.kpi-table th,
.kpi-table td {
  border: 1px solid #e2e2e2;
  padding: 6px 8px;
  text-align: right;
}

.kpi-table th {
  background: #fafafa;
  text-align: center;
}

/* Mau luan phien theo nhom cot the (C1, P1, P2...) de de phan biet */
.kpi-table th.card-group-0,
.kpi-table td.card-group-0 {
  background: #eff6ff;
}

.kpi-table th.card-group-1,
.kpi-table td.card-group-1 {
  background: #f0fdf4;
}

.kpi-table th.card-group-2,
.kpi-table td.card-group-2 {
  background: #fefce8;
}

.kpi-table th.card-group-3,
.kpi-table td.card-group-3 {
  background: #fdf2f8;
}

.kpi-table th.card-group-4,
.kpi-table td.card-group-4 {
  background: #f5f3ff;
}

.kpi-table th.card-group-5,
.kpi-table td.card-group-5 {
  background: #fff7ed;
}

.kpi-table .pic-name {
  text-align: left;
  font-weight: 600;
}

.kpi-table .month-cell {
  text-align: center;
  white-space: nowrap;
}

/* Freeze 2 cot dau (PIC, Thang) khi cuon ngang - chi ap dung cho thead/tbody,
   khong dung cho tfoot vi dong tong ket dung 1 o colspan rat rong. */
.kpi-table thead tr:first-child th:nth-child(1),
.kpi-table tbody td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #fff;
  min-width: 160px;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-table thead tr:first-child th:nth-child(2),
.kpi-table tbody td:nth-child(2) {
  position: sticky;
  left: 160px;
  z-index: 3;
  background: #fff;
}

.kpi-table .cell-empty {
  text-align: center;
  color: #999;
}

.kpi-table .kpi-cell-good {
  color: #15803d;
  font-weight: 700;
}

.kpi-table .kpi-cell-bad {
  color: #c0392b;
  font-weight: 700;
}

.kpi-table .kpi-overall {
  font-weight: 700;
  background: #eef4ff;
}

.kpi-table .kpi-overall-real {
  color: #777;
  font-style: italic;
}

.kpi-table .summary-row td {
  font-weight: 700;
  background: #f5f6f8;
  border-top: 2px solid #ccc;
}

.kpi-table .summary-row td:first-child {
  text-align: right;
}

/* Editor form */
.editor-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
}

.card-fieldset {
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  padding: 8px 12px 12px;
}

.card-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.card-fields[hidden] {
  display: none;
}

.card-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
}

.card-fields input {
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font: inherit;
}

.status {
  font-size: 0.85rem;
  color: #2563eb;
}

/* Sub-tabs trong tab Nhap lieu: Nhap thu cong / Import Excel */
.edit-subtabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  padding: 3px;
  background: #f1f5f9;
  border-radius: 8px;
  width: fit-content;
}

.subtab-btn {
  border: none;
  border-radius: 6px;
  background: transparent;
  padding: 6px 16px;
  font-size: 0.85rem;
  color: #475569;
}

.subtab-btn:hover {
  background: rgba(255, 255, 255, 0.7);
}

.subtab-btn.active {
  background: #fff;
  color: #2563eb;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1);
}

/* Import Excel */
.import-excel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 100%;
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
}

.file-picker-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.import-summary {
  margin: 0;
  font-size: 0.9rem;
}

.ok-text {
  color: #15803d;
}

.error-text {
  color: #c0392b;
}

.import-preview-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8rem;
  white-space: nowrap;
}

.import-preview-table th,
.import-preview-table td {
  border: 1px solid #e2e2e2;
  padding: 6px 8px;
  text-align: left;
}

.import-preview-table th {
  background: #fafafa;
}

.import-row-error {
  background: #fef2f2;
}

.import-status {
  font-size: 0.78rem;
  font-weight: 600;
}

.import-status-ok {
  color: #15803d;
}

.import-status-warning {
  color: #92400e;
}

.import-status-error {
  color: #c0392b;
}

.import-confirm-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Modal (dung chung, hien tai chi Doi mat khau) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-card {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  width: min(360px, 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-card h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.modal-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}

.modal-card input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font: inherit;
}

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

.modal-card select {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font: inherit;
  background: #fff;
}

.modal-card select:disabled,
.modal-card input:disabled {
  background: #f1f5f9;
  color: #64748b;
}

.modal-card .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.account-modal {
  width: min(420px, 100%);
}

.field-hint {
  margin: 0;
  font-size: 0.78rem;
  color: #64748b;
}

/* Nut dung chung */
.primary-btn {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.primary-btn:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.danger-btn {
  color: #b91c1c;
  border-color: #fecaca;
}

.danger-btn:hover {
  background: #fef2f2;
  border-color: #fca5a5;
}

/* Tab Tai khoan (chi Editor) */
.accounts {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  max-width: 960px;
}

.accounts-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.accounts-toolbar input[type="search"] {
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font: inherit;
  min-width: 220px;
}

.accounts-count {
  font-size: 0.85rem;
  color: #64748b;
}

.accounts .hint {
  padding: 0;
  font-size: 0.8rem;
}

.accounts-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
}

.accounts-table th,
.accounts-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 8px 12px;
  text-align: left;
  white-space: nowrap;
}

.accounts-table th {
  background: #fafafa;
}

.accounts-table .cell-empty {
  text-align: center;
  color: #999;
}

.account-name {
  font-weight: 600;
}

.account-inactive td {
  color: #94a3b8;
  background: #f8fafc;
}

.accounts-table td.account-actions {
  text-align: right;
}

.account-actions button {
  padding: 4px 12px;
  font-size: 0.8rem;
  margin-left: 6px;
}

.self-tag {
  font-weight: 400;
  color: #2563eb;
  font-size: 0.78rem;
}

.warn-tag {
  font-weight: 500;
  font-size: 0.72rem;
  color: #92400e;
  background: #fef3c7;
  border-radius: 999px;
  padding: 1px 8px;
}

.muted {
  color: #94a3b8;
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}

.status-active {
  background: #dcfce7;
  color: #15803d;
}

.status-inactive {
  background: #f1f5f9;
  color: #64748b;
}
