/* ============ BASE ============ */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Sarabun', 'TH Sarabun New', 'Tahoma', sans-serif; }
body { background: #eef2f5; color: #222; min-height: 100vh; }

/* ============ HEADER ============ */
.app-header {
  background: linear-gradient(135deg, #1e5c8a 0%, #2980b9 100%);
  color: white; padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.app-header img.logo {
  width: 52px; height: 52px; background: white;
  border-radius: 50%; padding: 2px; flex-shrink: 0;
}
.app-header .title h1 { font-size: 20px; margin-bottom: 2px; }
.app-header .title p { font-size: 13px; opacity: 0.9; }
.app-header .sync-status {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.sync-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #27ae60; box-shadow: 0 0 8px #27ae60;
  transition: all 0.3s;
}
.sync-dot.syncing { background: #f39c12; box-shadow: 0 0 8px #f39c12; animation: pulse 1s infinite; }
.sync-dot.error { background: #e74c3c; box-shadow: 0 0 8px #e74c3c; }
.sync-dot.offline { background: #95a5a6; box-shadow: none; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.4;} }

/* ============ LAYOUT ============ */
.container { max-width: 1400px; margin: 0 auto; padding: 16px; }

.tabs {
  background: white; border-radius: 8px 8px 0 0; display: flex;
  border-bottom: 2px solid #2980b9; overflow-x: auto;
}
.tab {
  padding: 14px 22px; cursor: pointer; border: none; background: none;
  font-size: 15px; font-weight: 500; color: #555; white-space: nowrap;
  transition: all 0.15s;
}
.tab:hover { background: #f5f5f5; color: #2980b9; }
.tab.active { color: #2980b9; border-bottom: 3px solid #2980b9; margin-bottom: -2px; }

.panel {
  background: white; border-radius: 0 0 8px 8px; padding: 22px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05); display: none;
  min-height: 400px;
}
.panel.active { display: block; }

/* ============ TOOLBAR ============ */
.toolbar {
  display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap;
  align-items: center;
}
.toolbar select, .toolbar input {
  padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px;
  font-size: 14px; font-family: inherit;
}
.toolbar input[type="text"] { flex: 1; min-width: 200px; }

/* ============ BUTTONS ============ */
button {
  padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer;
  font-size: 14px; font-family: inherit; font-weight: 500;
  transition: all 0.15s;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #2980b9; color: white; }
.btn-primary:hover:not(:disabled) { background: #1e5c8a; }
.btn-success { background: #27ae60; color: white; }
.btn-success:hover:not(:disabled) { background: #1e8449; }
.btn-warning { background: #f39c12; color: white; }
.btn-warning:hover:not(:disabled) { background: #d68910; }
.btn-danger { background: #e74c3c; color: white; }
.btn-danger:hover:not(:disabled) { background: #c0392b; }
.btn-secondary { background: #95a5a6; color: white; }
.btn-secondary:hover:not(:disabled) { background: #7f8c8d; }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ============ TABLES ============ */
table {
  width: 100%; border-collapse: collapse; font-size: 14px;
  background: white;
}
table th, table td {
  padding: 9px 11px; text-align: left; border-bottom: 1px solid #e8e8e8;
}
table th {
  background: #f8f9fa; font-weight: 600; color: #333;
  position: sticky; top: 0;
}
table tr:hover td { background: #fafbfc; }
.table-wrap {
  max-height: 600px; overflow: auto; border: 1px solid #e8e8e8;
  border-radius: 4px;
}

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: white; border-radius: 8px; padding: 22px;
  max-width: 600px; width: 90%; max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin-bottom: 18px; color: #2980b9; }
.form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.form-group { flex: 1; }
.form-group label {
  display: block; font-size: 13px; color: #555;
  margin-bottom: 4px; font-weight: 500;
}
.form-group input, .form-group select {
  width: 100%; padding: 8px 12px; border: 1px solid #ddd;
  border-radius: 4px; font-size: 14px; font-family: inherit;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: #2980b9;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid #eee;
}

/* ============ BADGES ============ */
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 500;
}
.badge-active { background: #d4edda; color: #155724; }
.badge-inactive { background: #f8d7da; color: #721c24; }

/* ============ STATS ============ */
.stat-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.stat-card {
  background: white; padding: 18px; border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05); border-left: 4px solid #2980b9;
}
.stat-card .label { color: #666; font-size: 13px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: bold; color: #2980b9; }

/* ============ SALARY FORM ============ */
.salary-table {
  border-collapse: collapse; width: 100%; font-size: 13px;
}
.salary-table th {
  background: #2980b9; color: white; padding: 8px 4px;
  text-align: center; font-weight: 600; position: sticky; top: 0;
}
.salary-table td {
  border: 1px solid #e0e0e0; padding: 3px; text-align: center;
}
.salary-table .month-cell {
  background: #ecf0f1; font-weight: 600; white-space: nowrap;
}
.salary-table input {
  width: 100%; padding: 6px 6px; border: 1px solid transparent;
  border-radius: 2px; text-align: right; font-size: 13px;
  background: transparent; font-family: inherit;
}
.salary-table input:focus {
  outline: none; border-color: #2980b9; background: #fff9e6;
}
.salary-table input[type="text"] { text-align: left; }
.salary-table .calc-cell {
  background: #e8f4f8; text-align: right;
  padding: 6px 8px; font-weight: 500;
}
.salary-table .net-cell {
  background: #d4edda; text-align: right; padding: 6px 8px;
  font-weight: bold; color: #27ae60;
}
.salary-table tfoot td {
  background: #fff3cd; font-weight: bold; padding: 6px 8px;
}
.salary-table tfoot .total-row td { background: #ecf0f1; }
.salary-table tfoot .bonus-row td { background: #d5f5e3; }
.salary-table tfoot .bonus-label {
  text-align: center; letter-spacing: 3px;
  background: #a9dfbf !important; color: #1e8449;
}

/* ============ MISC ============ */
.loading { text-align: center; padding: 40px; color: #999; }
.print-section {
  background: #fff3cd; padding: 16px; border-radius: 6px;
  margin-bottom: 14px; border: 1px solid #ffc107;
}
.print-section.slip { background: #d1ecf1; border-color: #17a2b8; }

.info-box {
  background: #e8f4f8; padding: 18px; border-radius: 8px;
  margin-bottom: 16px; border-left: 4px solid #2980b9;
}
.info-box h3 { color: #1e5c8a; margin-bottom: 10px; }
.info-box ol { margin-left: 20px; line-height: 1.8; }

.warning-box {
  background: #fff3cd; padding: 18px; border-radius: 8px;
  margin-bottom: 16px; border: 1px solid #ffc107;
}
.warning-box h3 { color: #856404; margin-bottom: 10px; }

.success-box {
  background: #d4edda; padding: 18px; border-radius: 8px;
  margin-bottom: 16px; border: 1px solid #28a745;
}
.success-box h3 { color: #155724; margin-bottom: 10px; }

/* ============ TOAST ============ */
.toast {
  position: fixed; top: 80px; right: 20px; padding: 14px 20px;
  background: #27ae60; color: white; border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 200;
  opacity: 0; transform: translateX(100%); transition: all 0.3s;
  max-width: 400px;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.error { background: #e74c3c; }
.toast.warning { background: #f39c12; }

/* ============ SETUP SCREEN ============ */
.setup-screen {
  max-width: 600px; margin: 60px auto; background: white;
  padding: 40px; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
.setup-screen h2 { color: #2980b9; margin-bottom: 16px; }
.setup-screen .url-input {
  width: 100%; padding: 12px; border: 2px solid #ddd;
  border-radius: 6px; font-size: 14px; margin: 12px 0;
  font-family: monospace;
}

/* ============ PRINT STYLES (in print window) ============ */
@media (max-width: 768px) {
  .form-row { flex-direction: column; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .salary-table { font-size: 11px; }
}
