:root {
  --bg: #0f1117;
  --bg-card: #181b23;
  --bg-input: #1e2230;
  --border: #2a2e3a;
  --text: #c8cdd6;
  --text-dim: #6b7280;
  --text-bright: #e8ecf1;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --active-bg: rgba(34,197,94,0.12);
  --active-text: #22c55e;
  --expired-bg: rgba(239,68,68,0.1);
  --expired-text: #ef4444;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f6;
    --bg-card: #ffffff;
    --bg-input: #f9fafb;
    --border: #d1d5db;
    --text: #374151;
    --text-dim: #9ca3af;
    --text-bright: #111827;
    --active-bg: rgba(34,197,94,0.08);
    --expired-bg: rgba(239,68,68,0.06);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: -0.01em;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-input); }

.screen { padding: 16px; max-width: 640px; margin: 0 auto; }

/* Login */
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 24px;
  margin-top: 20vh;
  text-align: center;
}
.login-card h2 {
  font-size: 18px;
  color: var(--text-bright);
  margin-bottom: 20px;
}
.login-card input {
  display: block;
  width: 100%;
  margin-bottom: 12px;
}
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }

/* Inputs */
input[type="text"], input[type="password"], input[type="number"], textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-bright);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
textarea {
  resize: vertical;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}
input:focus, textarea:focus { border-color: var(--primary); }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  margin-top: 12px;
}
label:first-child { margin-top: 0; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* Toolbar */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.search-wrap { flex: 1; min-width: 160px; }
.search-wrap input { width: 100%; }

/* Stats */
.stats-bar {
  display: flex;
  gap: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
}
.badge-active { color: var(--active-text); }
.badge-expired { color: var(--expired-text); }

/* Employee Card */
.emp-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}
.emp-card:hover { border-color: var(--primary); }
.emp-card.expired { border-left: 3px solid var(--expired-text); }
.emp-card.active { border-left: 3px solid var(--active-text); }

.emp-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.emp-check {
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.emp-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.emp-check .checkmark {
  display: block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  transition: all 0.15s;
}
.emp-check input:checked + .checkmark {
  background: var(--primary);
  border-color: var(--primary);
}
.emp-check input:checked + .checkmark::after {
  content: "";
  display: block;
  width: 5px;
  height: 9px;
  margin: 1px auto 0;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.emp-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.emp-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mc-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.mc-badge.active { background: var(--active-bg); color: var(--active-text); }
.mc-badge.expired { background: var(--expired-bg); color: var(--expired-text); }

.emp-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin: 6px 0 0 28px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.emp-machines {
  margin: 8px 0 0 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.emp-machine {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  background: var(--bg-input);
  border-radius: 4px;
}
.emp-machine .mc-code {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  user-select: all;
  word-break: break-all;
  flex: 1;
}
.mc-expiry {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.mc-expiry.expired { color: var(--expired-text); font-weight: 600; }
.emp-machine.machine-expired { border-left: 2px solid var(--expired-text); }
.btn-extend-machine {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 0 3px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.btn-extend-machine:hover { color: var(--primary); }
.btn-remove-machine {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
  flex-shrink: 0;
}
.btn-remove-machine:hover { color: var(--danger); }

.emp-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0 0 28px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay:not([hidden]) {
  display: flex;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}
.modal-sm { max-width: 340px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; color: var(--text-bright); }
.modal-body { padding: 16px 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-bright);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: toast-in 0.3s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(12px); } }

/* Empty / Loading */
#empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-dim);
  font-size: 14px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
  .toolbar { flex-wrap: wrap; }
  .search-wrap { flex: 1 1 100%; order: 3; }
  .emp-meta { flex-direction: column; gap: 2px; }
  .emp-machines { margin-left: 0; }
  .emp-actions { margin-left: 0; flex-wrap: wrap; }
}
