/* ===== CSS Variables ===== */
:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #f5f7fa;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --text-sidebar: #374151;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #eff6ff;
  --green: #10b981;
  --green-light: #ecfdf5;
  --orange: #f59e0b;
  --orange-light: #fffbeb;
  --purple: #8b5cf6;
  --purple-light: #f5f3ff;
  --red: #ef4444;
  --telegram: #229ed9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 280px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-sidebar: #13151f;
  --bg-hover: #22263a;
  --border: #2a2d3e;
  --text: #f1f3f9;
  --text-muted: #8b8fa8;
  --text-sidebar: #c4c9e0;
  --primary-light: #1e2a45;
  --green-light: #0d2618;
  --orange-light: #261e0a;
  --purple-light: #1f1535;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.25);
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition:
    background var(--transition),
    color var(--transition);
}
button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
}
input {
  font-family: inherit;
}
a {
  color: inherit;
  text-decoration: none;
}

/* ===== Layout ===== */
.layout {
  display: flex;
  min-height: 100vh;
  padding-top: 0;
}

/* ===== Mobile header ===== */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 200;
  box-shadow: var(--shadow);
}
.mobile-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}
.btn-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition:
    background var(--transition),
    color var(--transition);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ===== Sidebar ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 299;
}
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 6px;
  flex-shrink: 0;
  transition:
    background var(--transition),
    transform 0.25s ease;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.brand-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.brand-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 1px;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}
.dot-green {
  background: var(--green);
}
.dot-red {
  background: var(--red);
}
.dot-orange {
  background: var(--orange);
}

.sidebar-section-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 4px 2px;
}

.input-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}
.input-date,
.input-search {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  transition:
    border-color var(--transition),
    background var(--transition);
}
.input-date:focus,
.input-search:focus {
  border-color: var(--primary);
}
.date-picker-wrap,
.date-range-wrap {
  margin-bottom: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  transition:
    background var(--transition),
    opacity var(--transition);
}
.btn-full {
  width: 100%;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-telegram {
  background: var(--telegram);
  color: #fff;
}
.btn-telegram:hover {
  opacity: 0.88;
}

/* Shift list in sidebar */
.shift-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shift-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition:
    border-color var(--transition),
    background var(--transition);
}
.shift-item:hover,
.shift-item.active {
  border-color: var(--primary);
  background: var(--primary-light);
}
.shift-item-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}
.shift-item-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.shift-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  float: right;
  margin-top: 1px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.empty-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}

/* ===== Main content ===== */
.main {
  flex: 1;
  padding: 24px;
  min-width: 0;
  position: relative;
}

/* ===== Stats grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  transition:
    background var(--transition),
    border-color var(--transition);
}
.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon-blue {
  background: var(--primary-light);
  color: var(--primary);
}
.stat-icon-green {
  background: var(--green-light);
  color: var(--green);
}
.stat-icon-orange {
  background: var(--orange-light);
  color: var(--orange);
}
.stat-icon-purple {
  background: var(--purple-light);
  color: var(--purple);
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Tabs ===== */
.tabs-bar {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}
.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition:
    color var(--transition),
    border-color var(--transition);
}
.tab-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ===== Shift overview cards ===== */
.shift-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.shift-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition:
    box-shadow var(--transition),
    background var(--transition);
}
.shift-card:hover {
  box-shadow: var(--shadow-md);
}
.shift-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
}
.shift-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.shift-card-time {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.shift-card-count {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 1.4rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  line-height: 1;
}
.shift-card-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 2px;
}
.shift-card-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}
.employee-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.chip {
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 500;
  background: var(--bg-hover);
  color: var(--text-sidebar);
  border: 1px solid var(--border);
}

/* ===== Employee table ===== */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.input-search {
  max-width: 280px;
}
.table-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: auto;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  text-align: left;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 11px 16px;
  font-size: 0.85rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.data-table tr:last-child td {
  border-bottom: none;
}
.data-table tbody tr:hover {
  background: var(--bg-hover);
}
.empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 32px !important;
}

/* ===== Shift detail list ===== */
.shift-detail-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.shift-detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.shift-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.shift-detail-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.shift-detail-time {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.shift-detail-badge {
  background: var(--green-light);
  color: var(--green);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--green);
}
.shift-detail-body {
  padding: 14px 18px;
}
.shift-detail-table {
  width: 100%;
  border-collapse: collapse;
}
.shift-detail-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.shift-detail-table td {
  padding: 9px 10px;
  font-size: 0.84rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.shift-detail-table tr:last-child td {
  border-bottom: none;
}
.shift-detail-table tbody tr:hover {
  background: var(--bg-hover);
}

/* ===== Placeholder ===== */
.placeholder-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 24px;
  font-size: 0.9rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ===== Loading overlay ===== */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(var(--bg), 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  z-index: 10;
  border-radius: var(--radius);
  backdrop-filter: blur(2px);
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.25s,
    transform 0.25s;
  pointer-events: none;
  z-index: 9999;
  max-width: 320px;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast.success {
  background: var(--green);
  color: #fff;
}
.toast.error {
  background: var(--red);
  color: #fff;
}

/* ===== Salary tab ===== */
.salary-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 4px;
}
.salary-month-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.salary-action-wrap {
  display: flex;
  gap: 8px;
}
.btn-penalty {
  background: #fee2e2;
  color: var(--red);
  border: 1px solid #fca5a5;
}
.btn-penalty:hover {
  background: #fecaca;
}
[data-theme="dark"] .btn-penalty {
  background: #3b1212;
  color: #f87171;
  border-color: #7f1d1d;
}
.btn-bonus {
  background: var(--green-light);
  color: var(--green);
  border: 1px solid #6ee7b7;
}
.btn-bonus:hover {
  background: #d1fae5;
}
[data-theme="dark"] .btn-bonus {
  background: #0d2618;
  color: #34d399;
  border-color: #065f46;
}
.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Salary table cells */
.salary-base-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.salary-input-inline {
  width: 110px;
  padding: 4px 8px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.83rem;
}
.btn-save-inline {
  padding: 3px 8px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  cursor: pointer;
}
.btn-save-inline:hover {
  background: var(--primary-hover);
}
.btn-edit-salary {
  opacity: 0.5;
  font-size: 0.8rem;
  width: 22px;
  height: 22px;
}
.btn-edit-salary:hover {
  opacity: 1;
}
.money-plus {
  color: var(--green);
  font-weight: 600;
}
.money-minus {
  color: var(--red);
  font-weight: 600;
}
.money-total {
  font-weight: 700;
  color: var(--text);
}
.money-zero {
  color: var(--text-muted);
}

/* Expand / collapse salary detail row */
.btn-expand-row {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.btn-expand-row.open {
  transform: rotate(180deg);
}
.salary-detail-row td {
  padding: 0 !important;
}
.salary-detail-wrap {
  padding: 12px 18px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.salary-detail-sections {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.salary-detail-section {
  flex: 1;
  min-width: 220px;
}
.salary-detail-section h4 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.salary-detail-section table {
  width: 100%;
  border-collapse: collapse;
}
.salary-detail-section td {
  font-size: 0.82rem;
  padding: 5px 8px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.salary-detail-section tr:last-child td {
  border-bottom: none;
}
.btn-del-item {
  background: transparent;
  border: none;
  color: var(--red);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.85rem;
  opacity: 0.6;
}
.btn-del-item:hover {
  opacity: 1;
}
.salary-empty-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ===== Modals ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open {
  display: flex;
}
.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }
  .layout {
    padding-top: 52px;
  }
  .sidebar {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    z-index: 300;
    transform: translateX(-100%);
    box-shadow: var(--shadow-md);
    overflow-y: auto;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.show {
    display: block;
  }
  .main {
    padding: 16px;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card {
    padding: 12px;
  }
  .stat-value {
    font-size: 1.25rem;
  }
  .tabs-bar {
    overflow-x: auto;
    white-space: nowrap;
  }
  .tab-btn {
    padding: 8px 12px;
    font-size: 0.8rem;
  }
  .data-table th,
  .data-table td {
    padding: 8px 10px;
  }
  .input-search {
    max-width: 100%;
  }
  .toast {
    bottom: 12px;
    right: 12px;
    left: 12px;
    max-width: unset;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  .stat-icon {
    width: 36px;
    height: 36px;
  }
  .shift-cards {
    grid-template-columns: 1fr;
  }
}
