*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #38bdf8;
  --primary-dark: #0ea5e9;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --border: #475569;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: var(--text);
  min-height: 100vh;
}

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

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: rgba(15, 23, 42, 0.95);
  border-left: 1px solid var(--border);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 2rem;
  color: var(--primary);
}

.nav a {
  display: block;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.nav a.active,
.nav a:hover {
  background: var(--surface);
  color: var(--primary);
}

.main {
  padding: 1.5rem 2rem 3rem;
}

.page-title {
  font-size: 1.6rem;
  margin: 0 0 1.5rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dashboard-cards {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card .label { color: var(--muted); font-size: 0.9rem; }
.card .value { font-size: 1.8rem; font-weight: 700; margin-top: 0.35rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-size: 0.92rem;
}

th { color: var(--muted); font-weight: 600; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
}

.badge.success { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.badge.warning { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge.danger { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  cursor: pointer;
  font-size: 0.92rem;
  background: var(--primary);
  color: #0f172a;
  font-weight: 600;
}

.btn:hover { background: var(--primary-dark); color: #fff; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #111; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
}

input, select, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}

input[type="checkbox"] { width: auto; }

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.flash.success { background: rgba(74, 222, 128, 0.12); color: var(--success); }
.flash.error { background: rgba(248, 113, 113, 0.12); color: var(--danger); }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-box {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.login-box h1 {
  margin: 0 0 0.5rem;
  text-align: center;
}

.login-box p {
  text-align: center;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.tab-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

.tab-btn.active { background: var(--primary); color: #0f172a; }

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

.device-test-results {
  margin-bottom: 1rem;
}

.device-test-results h2 {
  margin-top: 0;
}

.device-test-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
  background: #0b1220;
}

.device-test-card.ok {
  border-color: rgba(74, 222, 128, 0.35);
}

.device-test-card.fail {
  border-color: rgba(248, 113, 113, 0.35);
}

.device-test-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.device-test-ip {
  color: var(--muted);
  font-family: monospace;
}

.device-test-message {
  font-weight: 600;
}

.device-test-detail,
.device-test-meta {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 0.25rem;
}

.device-test-empty {
  color: var(--muted);
  margin: 0;
}

.device-test-error {
  color: var(--danger);
}

.shift-badge {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
}

.shift-card {
  margin-bottom: 0.5rem;
}

.shift-hours-box .shift-hours-display {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-height: 2.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.shift-hours-value {
  font-size: 1.35rem;
  color: var(--primary);
}

.shift-hours-unit {
  color: var(--muted);
  font-size: 0.9rem;
}

.section-label {
  font-size: 0.95rem;
  color: var(--primary);
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.section-label:first-child {
  margin-top: 0;
}

table input, table select {
  margin: 0;
}

tr.row-inactive {
  opacity: 0.65;
}

tr.row-on-time {
  background: rgba(74, 222, 128, 0.06);
}

.finance-up {
  color: var(--success);
  font-weight: 600;
}

.finance-down {
  color: var(--danger);
  font-weight: 600;
}

.finance-total-row {
  background: rgba(56, 189, 248, 0.08);
  border-top: 2px solid var(--border);
}

.table-scroll {
  overflow-x: auto;
}

.punch-employee-card {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.punch-employee-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: rgba(56, 189, 248, 0.06);
  border-bottom: 1px solid var(--border);
}

.punch-emp-code {
  color: var(--muted);
  margin-right: 0.5rem;
  font-size: 0.9rem;
}

.punch-employee-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  font-size: 0.9rem;
}

.punch-detail-table {
  width: 100%;
  margin: 0;
}

.punch-detail-table th,
.punch-detail-table td {
  padding: 0.55rem 0.85rem;
}

.punch-seq-error {
  background: rgba(248, 113, 113, 0.08);
}

.badge.primary {
  background: rgba(56, 189, 248, 0.2);
  color: var(--primary);
  border: 1px solid rgba(56, 189, 248, 0.4);
}

.badge.muted {
  background: rgba(148, 163, 184, 0.15);
  color: var(--muted);
  border: 1px solid var(--border);
}

select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}

.filter-bar {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.filter-bar .inline-form {
  margin-bottom: 0;
}

.page-subtitle {
  color: var(--muted);
  margin: -0.5rem 0 1rem;
  font-size: 0.95rem;
}

.finance-summary-cards {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.finance-employee-card {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.finance-employee-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: rgba(56, 189, 248, 0.06);
  border-bottom: 1px solid var(--border);
}

.finance-employee-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.finance-daily-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.finance-daily-table th,
.finance-daily-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.finance-daily-table thead th {
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  font-weight: 600;
}

.finance-row-absent {
  opacity: 0.7;
  background: rgba(248, 113, 113, 0.04);
}

.period-fields-day,
.period-fields-range,
.period-fields-month,
.period-fields-week {
  display: contents;
}

.filter-bar[data-period-mode="day"] .period-fields-range,
.filter-bar[data-period-mode="day"] .period-fields-month,
.filter-bar[data-period-mode="day"] .period-fields-week,
.filter-bar[data-period-mode="week"] .period-fields-day,
.filter-bar[data-period-mode="week"] .period-fields-range,
.filter-bar[data-period-mode="week"] .period-fields-month,
.filter-bar[data-period-mode="range"] .period-fields-day,
.filter-bar[data-period-mode="range"] .period-fields-month,
.filter-bar[data-period-mode="range"] .period-fields-week,
.filter-bar[data-period-mode="month"] .period-fields-day,
.filter-bar[data-period-mode="month"] .period-fields-range,
.filter-bar[data-period-mode="month"] .period-fields-week {
  display: none;
}

.table-search-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.table-live-search {
  flex: 1;
  min-width: 200px;
  max-width: 420px;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
}

.table-search-count {
  color: var(--muted);
  font-size: 0.9rem;
}

tr.filter-hidden,
.punch-employee-card.filter-hidden {
  display: none !important;
}

.filter-result-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.82rem;
}

.punch-actions {
  white-space: nowrap;
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  width: min(480px, 92vw);
  max-height: 90vh;
  overflow: auto;
  z-index: 1;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.danger-zone {
  background: #1a0f12;
}

.payroll-stats-cards .card-hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.panel-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: -0.25rem 0 1rem;
}

.btn-link-sm {
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
}

.btn-link-sm:hover {
  text-decoration: underline;
}

.payroll-employee-block {
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.payroll-employee-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  background: rgba(56, 189, 248, 0.06);
  list-style: none;
}

.payroll-employee-summary::-webkit-details-marker {
  display: none;
}

.payroll-employee-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.payroll-employee-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.payroll-tag {
  font-size: 0.82rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.payroll-tag-ded {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.35);
}

.payroll-tag-ot {
  color: var(--success);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.35);
}

.payroll-tag-muted {
  color: var(--muted);
}

.payroll-detail-table {
  margin: 0;
}

.payroll-row-ded td:nth-child(13) {
  font-weight: 600;
}

.payroll-empty {
  padding: 1rem;
  color: var(--muted);
  margin: 0;
}

.finance-daily-table thead th {
  white-space: nowrap;
}

.finance-session-line {
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: nowrap;
}

.wa-send-form {
  display: inline;
  margin: 0;
}

.wa-send-btn {
  white-space: nowrap;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { height: auto; position: static; }
}
