/* ============================================
   ZapOS — internal payroll UI
   Flat, quiet, no glass / glow / gradient chrome
   ============================================ */

/* --- CSS Variables --- */
:root {
  --primary: #3a5f4a;
  --primary-light: #4d7a62;
  --primary-dark: #2d4a3a;
  --accent: #3a5f4a;
  --accent-light: #5a8a6e;
  --danger: #b33b3b;
  --danger-light: #c95a5a;
  --warning: #b8860b;
  --warning-light: #d4a017;

  --bg-primary: #121411;
  --bg-secondary: #1a1c18;
  --bg-card: #1a1c18;
  --bg-glass: #22251f;
  --bg-hover: #262922;
  --bg-input: #151714;

  --text-primary: #e8e6e1;
  --text-secondary: #a8a49a;
  --text-muted: #6f6b62;

  --border: #2c2f28;
  --border-active: #4d7a62;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-glow: none;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;

  --sidebar-width: 232px;
  --header-height: 56px;
  --transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

/* Light theme */
[data-theme="light"] {
  --primary: #2f5340;
  --primary-light: #3a5f4a;
  --primary-dark: #244032;
  --accent: #2f5340;
  --bg-primary: #f4f2ec;
  --bg-secondary: #fffcf7;
  --bg-card: #fffcf7;
  --bg-glass: #f0ede5;
  --bg-hover: #ebe7dc;
  --bg-input: #ffffff;
  --text-primary: #1c1b17;
  --text-secondary: #5c584f;
  --text-muted: #8a857a;
  --border: #ddd7c8;
  --border-active: #3a5f4a;
  --shadow-sm: 0 1px 2px rgba(28, 27, 23, 0.06);
  --shadow-md: 0 2px 8px rgba(28, 27, 23, 0.08);
  --shadow-lg: 0 8px 20px rgba(28, 27, 23, 0.1);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-primary);
}

.login-screen[hidden] { display: none !important; }
body.is-login .app { pointer-events: none; }
body.is-login .login-screen { display: grid; }

.login-panel {
  width: min(400px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.login-logo { margin-bottom: 16px; }
.login-panel h1 { font-size: 22px; font-weight: 600; margin-bottom: 4px; letter-spacing: -0.02em; }
.login-panel p { color: var(--text-secondary); margin-bottom: 22px; font-size: 13px; }
.login-submit { width: 100%; justify-content: center; margin-top: 6px; }
.login-error { min-height: 20px; margin-top: 14px; color: var(--danger-light); font-size: 13px; }
.app-locked { opacity: 0.35; pointer-events: none; }

a { color: var(--primary-light); text-decoration: none; }
a:hover { color: var(--text-primary); text-decoration: underline; }

/* --- Layout --- */
.app { display: flex; min-width: 0; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #f4f2ec;
  letter-spacing: 0.02em;
}

.sidebar-brand { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; }
.sidebar-brand span { color: var(--text-muted); font-weight: 400; font-size: 11px; display: block; margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }

.nav-section { margin-bottom: 18px; }
.nav-section-title {
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.04em; color: var(--text-muted);
  padding: 6px 10px 4px; margin-bottom: 2px;
  text-transform: none;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 13px; font-weight: 450;
  cursor: pointer;
  text-decoration: none; position: relative;
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
  color: var(--primary-light);
}

.nav-item.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-left-color: var(--primary);
  font-weight: 550;
}

.nav-item.active::before { display: none; }

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.nav-icon .icon {
  width: 18px;
  height: 18px;
}

.nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--primary); color: #f4f2ec;
  padding: 1px 6px; border-radius: var(--radius-sm);
}

/* Premium stroke icons */
.icon {
  width: 20px;
  height: 20px;
  display: block;
  flex-shrink: 0;
  overflow: visible;
}

.icon path,
.icon circle,
.icon rect,
.icon line,
.icon polyline,
.icon polygon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.icon-sm { width: 16px; height: 16px; }
.icon-sm path,
.icon-sm circle,
.icon-sm rect,
.icon-sm line {
  stroke-width: 1.65;
}

.icon-lg { width: 28px; height: 28px; }
.icon-lg path,
.icon-lg circle,
.icon-lg rect {
  stroke-width: 1.35;
}

.btn-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-icon-only:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-active);
}

.btn-icon-only.action-danger:hover {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.mobile-menu-toggle.btn-icon-only {
  width: 38px;
  height: 38px;
}

/* Main content */
.main { flex: 1; min-width: 0; margin-left: var(--sidebar-width); min-height: 100vh; }

.header {
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 50;
}

.header-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.header-left > div { min-width: 0; }
.header-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.header-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.current-user {
  color: var(--text-secondary);
  font-size: 12px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content { min-width: 0; padding: 20px 22px; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  min-width: 0;
}

.card:hover { border-color: var(--border); box-shadow: none; }

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}

.card-title { font-size: 14px; font-weight: 600; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Metric cards */
.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.metric-card::before { display: none; }
.metric-card:hover::before { display: none; }
.metric-card:hover { transform: none; box-shadow: none; }

.metric-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  background: var(--bg-glass);
  color: var(--text-secondary);
}

.metric-icon .icon {
  width: 18px;
  height: 18px;
}

.metric-icon.tone-olive {
  color: var(--primary-light);
  border-color: rgba(77, 122, 98, 0.35);
  background: rgba(58, 95, 74, 0.12);
}

.metric-icon.tone-gold {
  color: var(--warning-light);
  border-color: rgba(184, 134, 11, 0.35);
  background: rgba(184, 134, 11, 0.1);
}

.metric-icon.tone-danger {
  color: var(--danger-light);
  border-color: rgba(179, 59, 59, 0.35);
  background: rgba(179, 59, 59, 0.1);
}

.metric-value {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.metric-label { font-size: 12px; color: var(--text-secondary); }
.metric-change {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 500; margin-top: 8px;
  padding: 2px 6px; border-radius: var(--radius-sm);
}
.metric-change.up { background: rgba(58, 95, 74, 0.15); color: var(--accent-light); }
.metric-change.down { background: rgba(179, 59, 59, 0.12); color: var(--danger-light); }

/* --- Tables --- */
.table-container {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

table { width: 100%; border-collapse: collapse; }
.table-container table { min-width: 720px; }

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px; font-weight: 500;
  text-transform: none; letter-spacing: 0;
  color: var(--text-secondary);
  background: var(--bg-glass);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: default;
  user-select: none;
}

thead th:hover { color: var(--text-primary); }
thead th.sorted { color: var(--primary-light); }

[data-theme="light"] thead th {
  color: #334155;
  background: rgba(241, 245, 249, 0.9);
}

.actions-col {
  width: 1%;
  min-width: 132px;
  text-align: center;
  color: var(--text-primary);
}

thead th.actions-col {
  color: var(--primary-light);
  background: rgba(58, 95, 74, 0.16);
  border-left: 1px solid var(--border);
}

[data-theme="light"] thead th.actions-col {
  color: #1D4ED8;
  background: rgba(58, 95, 74, 0.10);
}

tbody td.actions-cell {
  text-align: center;
  white-space: nowrap;
  border-left: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.actions-cell .btn {
  justify-content: center;
}

.action-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
}

.action-danger {
  color: var(--danger);
}

.action-danger:hover {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.action-select {
  width: 136px;
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
  border-color: var(--border-active);
  background: var(--bg-input);
}

tbody td {
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

tbody tr:hover { background: var(--bg-hover); }
tbody tr:last-child td { border-bottom: none; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; font-family: inherit;
  border: none; cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: none;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--bg-glass); color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-active); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #DC2626; }

.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }
#menu-toggle { display: none; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }

.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 13px; font-family: inherit;
  transition: var(--transition);
  color-scheme: dark;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(58, 95, 74, 0.25);
}

.form-input:focus-visible, .form-select:focus-visible, .form-textarea:focus-visible,
.btn:focus-visible, .nav-item:focus-visible, .department-tab:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.form-textarea { min-height: 80px; resize: vertical; }
.form-select {
  cursor: pointer;
  min-height: 38px;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

.form-select option,
.form-select optgroup {
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

.form-select option:checked {
  color: #fff;
  background-color: var(--primary);
}

[data-theme="light"] .form-input,
[data-theme="light"] .form-select,
[data-theme="light"] .form-textarea {
  color-scheme: light;
}

[data-theme="light"] .form-select,
[data-theme="light"] .form-select option,
[data-theme="light"] .form-select optgroup {
  color: #0F172A;
  background-color: #FFFFFF;
}

.enhanced-select {
  min-height: 42px;
  padding-right: 38px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 12px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

/* --- Modals --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: min(90vw, 520px);
  max-height: 85vh;
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.3s ease;
}

.modal-wide {
  width: min(96vw, 1120px);
  max-width: 1120px;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}

.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { cursor: pointer; color: var(--text-muted); font-size: 20px; padding: 4px; border: 0; background: transparent; line-height: 1; }
.modal-close:hover { color: var(--text-primary); }
.modal-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.modal-body {
  min-width: 0;
  padding: 24px;
}
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 12px; justify-content: flex-end; }

.form-section-title {
  margin: 6px 0 14px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.employee-form-layout {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 22px;
  align-items: start;
}

.photo-uploader {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
}

.employee-photo-preview {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.employee-photo-preview img,
.employee-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed; top: 20px; right: 20px;
  z-index: 2000; display: flex; flex-direction: column; gap: 8px;
}

.toast {
  padding: 14px 20px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
  box-shadow: var(--shadow-md);
  animation: slideInRight 0.3s ease;
  min-width: 300px;
}

.toast-success { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border); border-left: 3px solid var(--accent); }
.toast-error { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border); border-left: 3px solid var(--danger); }
.toast-warning { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border); border-left: 3px solid var(--warning); }

/* --- Status Badges --- */
.badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 600;
}

.badge-active { background: rgba(58, 95, 74, 0.14); color: var(--accent-light); }
.badge-inactive { background: rgba(179, 59, 59, 0.12); color: var(--danger); }
.badge-pending { background: rgba(184, 134, 11, 0.14); color: var(--warning); }
.badge-approved { background: rgba(58, 95, 74, 0.14); color: var(--accent-light); }
.badge-paid { background: rgba(58, 95, 74, 0.14); color: var(--accent-light); }
.badge-cancelled { background: rgba(100, 116, 139, 0.12); color: var(--text-muted); }

.admin-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.admin-tab {
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  color: var(--text-secondary);
  background: transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.admin-tab.active {
  color: #fff;
  background: var(--primary);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}

.table-muted {
  color: var(--text-muted);
  font-size: 11px;
}

.telegram-payload-cell {
  min-width: 340px;
}

.telegram-payload-cell summary {
  cursor: pointer;
  color: var(--primary-light);
  font-weight: 700;
}

.telegram-payload-cell pre {
  max-width: 620px;
  max-height: 320px;
  margin-top: 10px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.24);
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.status-ok { color: var(--accent) !important; }
.status-warn { color: var(--warning) !important; }
.status-danger { color: var(--danger) !important; }
.status-bonus { color: var(--primary-light) !important; }

.row-danger-soft {
  background: rgba(239, 68, 68, 0.08);
}

.advance-limit-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
  color: var(--text-secondary);
  background: var(--bg-glass);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.advance-limit-panel strong { color: var(--text-primary); }
.advance-limit-panel span { font-size: 12px; }
.advance-limit-ok { border-color: rgba(16, 185, 129, 0.35); background: rgba(16, 185, 129, 0.08); }
.advance-limit-warning { border-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.1); }
.advance-limit-danger { border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.1); }

.limit-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}
.limit-ok { background: var(--accent); }
.limit-warning { background: var(--warning); }
.limit-danger { background: var(--danger); }

/* --- Search & Filter Bar --- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.employee-card-list {
  display: grid;
  gap: 10px;
}

.employee-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  overflow: hidden;
  transition: var(--transition);
}

.employee-card:hover {
  border-color: var(--border-active);
}

.employee-card.active {
  border-color: var(--primary);
  box-shadow: none;
  border-color: var(--primary);
}

.employee-card-main {
  display: grid;
  grid-template-columns: 52px minmax(180px, 1.3fr) minmax(160px, 1fr) minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 12px 14px;
  cursor: pointer;
}

.employee-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

.employee-avatar.large {
  width: 64px;
  height: 64px;
  font-size: 18px;
}

.employee-card-name,
.employee-card-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.employee-card-name strong,
.employee-card-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-card-name strong {
  font-size: 14px;
}

.employee-card-name span,
.employee-card-meta small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 12px;
}

.employee-card-actions {
  display: inline-flex;
  gap: 4px;
}

.employee-details {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-glass);
}

.employee-profile-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.employee-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
}

.employee-detail-item {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
}

.employee-detail-item span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.employee-detail-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.stats-controls {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) minmax(240px, 1fr) auto minmax(150px, 180px);
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.dashboard-period-bar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(150px, 180px);
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.control-field {
  min-width: 0;
}

.control-field .form-label {
  margin-bottom: 7px;
}

.stats-action {
  min-height: 42px;
  justify-content: center;
}

.employee-stat-list {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.employee-stat-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(4, minmax(120px, 1fr));
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}

.employee-stat-row:hover {
  border-color: var(--border-active);
  background: var(--bg-hover);
}

.employee-stat-row.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(58, 95, 74, 0.22);
}

.employee-stat-expanded {
  margin: -2px 0 10px;
  padding: 16px;
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
  overflow: hidden;
}

.employee-stat-expanded .metrics-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  margin-bottom: 0;
}

.employee-stat-expanded .metric-card {
  padding: 18px;
}

.employee-stat-expanded .metric-value {
  font-size: 22px;
}

.employee-stat-person {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.employee-stat-person strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}

.employee-stat-person span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 12px;
}

.mini-stat {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
}

.mini-stat span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.mini-stat small {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.selected-employee-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
}

.employee-rate-settings {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
}

.custom-rate-editor {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-glass);
  min-width: 0;
  overflow: hidden;
}

.custom-rate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.custom-rate-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.1fr);
  gap: 16px;
  min-width: 0;
}

.rate-calendar-weekdays,
.rate-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.rate-calendar-weekdays {
  margin-bottom: 6px;
}

.rate-calendar-weekdays span {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.rate-calendar-empty {
  min-height: 64px;
}

.rate-calendar-day {
  min-height: 64px;
  padding: 7px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}

.rate-calendar-day:hover {
  border-color: var(--primary);
  background: var(--bg-hover);
}

.rate-calendar-day.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(58, 95, 74, 0.22);
}

.rate-calendar-day:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.rate-calendar-day span,
.rate-calendar-day small {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rate-calendar-day span {
  margin-bottom: 8px;
  font-weight: 600;
}

.rate-calendar-day small {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.25;
}

.custom-rate-day-panel {
  min-width: 0;
}

.custom-rate-day-table {
  max-height: 260px;
  overflow-y: auto;
}

.employee-rate-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.rate-month {
  max-width: 180px;
}

.rate-summary-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  color: var(--text-secondary);
}

.rate-summary-line strong {
  color: var(--text-primary);
}

.rate-segment-form {
  display: grid;
  grid-template-columns: 150px 110px 110px 120px minmax(180px, 1fr) auto;
  gap: 10px;
  margin-bottom: 12px;
}

.rate-segment-form.modal-rate-segment-form {
  grid-template-columns: 92px 92px minmax(100px, 120px) minmax(0, 1fr);
}

.rate-segment-form.modal-rate-segment-form .btn {
  grid-column: 1 / -1;
  justify-self: end;
}

.compact-table table th,
.compact-table table td {
  padding: 9px 10px;
  font-size: 12px;
}

.compact-table table { min-width: 560px; }

.employee-finance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.employee-finance-grid div,
.advance-summary-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
}

.employee-finance-grid span,
.advance-summary-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.employee-finance-grid strong,
.advance-summary-card strong {
  color: var(--text-primary);
  font-size: 16px;
}

.advance-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.salary-rate-card {
  margin-bottom: 20px;
}

.salary-rate-manager {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(0, 1.25fr);
  gap: 16px;
}

.salary-rate-list,
.salary-rate-editor {
  min-width: 0;
}

.salary-rate-employees {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-height: 540px;
  overflow-y: auto;
}

.salary-rate-employee {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}

.salary-rate-employee:hover,
.salary-rate-employee.active {
  border-color: var(--primary);
  background: var(--bg-hover);
}

.salary-rate-employee span:first-child {
  min-width: 0;
}

.salary-rate-employee strong,
.salary-rate-employee small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.salary-rate-employee small {
  margin-top: 4px;
  color: var(--text-muted);
}

.salary-rate-fields {
  margin: 16px 0 0;
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  text-align: center;
  background: var(--bg-glass);
}

.department-tabs {
  position: relative;
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  padding: 6px;
  overflow-x: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.department-tab {
  position: relative;
  flex: 1 0 200px;
  min-height: 38px;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
}

.department-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.department-tab.active {
  color: #fff;
  background: var(--primary);
}

.tab-panel-animate {
  animation: tabPanelIn 0.24s ease both;
}

.search-box {
  position: relative; flex: 1; min-width: 200px;
}

.search-box input {
  width: 100%; padding: 10px 14px 10px 40px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 13px; font-family: inherit;
}

.search-box input {
  padding-left: 14px;
}

.search-box::before { display: none; }

.search-box input:focus { outline: none; border-color: var(--primary); }
.search-box input:focus-visible {
  outline: 2px solid var(--primary-light);
  outline-offset: 2px;
}

/* --- Upload Zone --- */
.upload-zone {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 36px 20px; text-align: center;
  cursor: pointer;
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--bg-glass);
}

.upload-zone-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-glass);
  color: var(--primary-light);
}

.upload-zone-text { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.upload-zone-hint { font-size: 12px; color: var(--text-muted); }

.import-result {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-glass);
  font-size: 13px;
  line-height: 1.45;
}
.import-result-ok { border-left: 3px solid var(--accent); }
.import-result-err { border-left: 3px solid var(--danger); }

/* Theme toggle uses .btn styles via markup */

/* Quiet motion only where useful */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes tabPanelIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.skeleton { animation: pulse 1.4s ease-in-out infinite; background: var(--bg-glass); border-radius: var(--radius-sm); }

/* --- Charts placeholder --- */
.chart-container { position: relative; height: 300px; width: 100%; }

/* --- Grid layouts --- */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* --- Responsive --- */
@media (max-width: 1024px) {
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 1050;
    background: rgba(0, 0, 0, 0.58);
    }

  #menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 18px;
  }

  .sidebar {
    width: min(86vw, 300px);
    z-index: 1100;
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .header { z-index: 900; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .employee-card-main { grid-template-columns: 52px minmax(180px, 1fr) minmax(150px, 1fr) auto; }
  .employee-card-meta:nth-of-type(2) { display: none; }
  .employee-detail-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .dashboard-period-bar,
  .stats-controls { grid-template-columns: 1fr 180px; }
  .stats-controls .stats-action { grid-column: 1 / -1; }
  .employee-stat-row { grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(120px, 1fr)); }
  .rate-segment-form,
  .advance-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .custom-rate-layout { grid-template-columns: 1fr; }
  .salary-rate-manager { grid-template-columns: 1fr; }
  .rate-segment-form.modal-rate-segment-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  html { font-size: 13px; }
  .login-screen { padding: 16px; }
  .login-panel { padding: 22px; }
  .login-panel h1 { font-size: 23px; }
  .metrics-grid { grid-template-columns: 1fr; }
  .metrics-grid,
  .grid-2,
  .grid-3 { gap: 12px; }
  .content { padding: 12px; }
  .card,
  .metric-card { padding: 16px; border-radius: var(--radius-md); }
  .metric-card:hover { transform: none; }
  .metric-value { font-size: 24px; }
  .metric-icon { width: 38px; height: 38px; margin-bottom: 12px; }
  .toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }
  .toolbar > *,
  .toolbar .btn,
  .toolbar .form-group,
  .toolbar input,
  .toolbar select,
  .search-box {
    width: 100%;
    min-width: 0;
  }
  .header {
    min-height: 60px;
    height: auto;
    padding: 10px 12px;
    gap: 10px;
  }
  .header-left { gap: 10px; flex: 1; }
  .header-actions { gap: 8px; flex-shrink: 0; }
  .header-title { font-size: 16px; }
  .header-subtitle,
  .current-user { display: none; }
  #logout-btn { padding: 7px 10px; }
  .card-header,
  .selected-employee-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }
  .employee-form-layout { grid-template-columns: 1fr; }
  .employee-card-main {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
  }
  .employee-card-meta, .employee-card-main .badge { display: none; }
  .employee-card-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
  .employee-card-actions .btn,
  .employee-card-actions .action-control {
    min-width: 38px;
  }
  .action-select { width: 100%; }
  .employee-detail-grid { grid-template-columns: 1fr; }
  .dashboard-period-bar,
  .stats-controls { grid-template-columns: 1fr; padding: 14px; }
  .stats-controls .stats-action { grid-column: auto; }
  .employee-stat-row {
    grid-template-columns: 1fr;
    gap: 8px;
    min-height: 0;
    padding: 12px;
  }
  .employee-stat-person { grid-column: auto; }
  .mini-stat {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
  .employee-stat-expanded { padding: 12px; }
  .employee-stat-expanded .metrics-grid { grid-template-columns: 1fr; }
  .employee-rate-toolbar { align-items: stretch; flex-direction: column; }
  .rate-month { max-width: none; }
  .rate-segment-form,
  .modal-rate-segment-form,
  .custom-rate-layout,
  .employee-finance-grid,
  .advance-summary-grid,
  .salary-rate-manager { grid-template-columns: 1fr; }
  .custom-rate-head { align-items: stretch; flex-direction: column; }
  .rate-summary-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
  .rate-calendar-empty,
  .rate-calendar-day { min-height: 50px; }
  .rate-calendar-weekdays,
  .rate-calendar-grid { gap: 4px; }
  .rate-calendar-day { padding: 5px; }
  .rate-calendar-day span { margin-bottom: 4px; }
  .rate-calendar-day small { font-size: 9px; }
  .advance-summary-grid { gap: 10px; }
  .salary-rate-employee { align-items: flex-start; flex-direction: column; }
  .department-tabs {
    margin-right: -2px;
    margin-left: -2px;
    padding: 4px;
    scroll-snap-type: x mandatory;
  }
  .department-tab {
    flex: 0 0 78%;
    min-height: 40px;
    padding: 9px 12px;
    scroll-snap-align: start;
  }
  .modal-overlay { align-items: flex-end; }
  .modal {
    width: 100vw;
    max-height: 92vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal-wide { width: 100vw; max-width: 100vw; }
  .modal-header,
  .modal-footer {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
    gap: 10px;
  }
  .modal-body { padding: 16px; }
  .modal-close { align-self: flex-end; }
  .modal-footer .btn { width: 100%; justify-content: center; }
  .table-container table { min-width: 640px; }
  .compact-table table { min-width: 520px; }
  .telegram-payload-cell { min-width: 260px; }
  .telegram-payload-cell pre { max-width: 78vw; }
  .toast-container {
    top: 12px;
    right: 12px;
    left: 12px;
  }
  .toast { min-width: 0; width: 100%; }
  .upload-zone { padding: 28px 16px; }
  .heatmap-cell { font-size: 9px; }
}

@media (max-width: 420px) {
  .content { padding: 10px; }
  .btn { padding-right: 14px; padding-left: 14px; }
  .header-title { max-width: 42vw; }
  .department-tab { flex-basis: 86%; }
  .table-container table { min-width: 600px; }
  .rate-calendar-day small { display: none; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Heatmap Calendar --- */
.heatmap { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heatmap-cell {
  aspect-ratio: 1; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; transition: var(--transition);
}
.heatmap-cell.level-0 { background: var(--bg-glass); color: var(--text-muted); }
.heatmap-cell.level-1 { background: rgba(16, 185, 129, 0.15); color: var(--accent); }
.heatmap-cell.level-2 { background: rgba(16, 185, 129, 0.3); color: var(--accent); }
.heatmap-cell.level-3 { background: rgba(16, 185, 129, 0.5); color: #fff; }
.heatmap-cell.level-4 { background: rgba(16, 185, 129, 0.75); color: #fff; }
