/* ==============================================================
   assets/css/style.css
   ธีมหลักของระบบ: โทนฟ้า-เขียว โมเดิร์น, Sidebar, ฟอร์ม, ตาราง
   ============================================================== */

:root {
  --blue: #0ea5e9;
  --blue-dark: #0284c7;
  --green: #10b981;
  --green-dark: #0f766e;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --radius: 10px;
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Noto Sans Thai', 'Sarabun', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { text-decoration: none; color: inherit; }

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

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--green-dark), var(--blue-dark));
  color: #fff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: margin-left 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255,255,255,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-icon svg {
  width: 18px;
  height: 18px;
  stroke: #fff;
  display: block;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.85);
  font-size: 0.95rem;
  transition: background 0.15s ease;
}

.nav-item:hover { background: rgba(255,255,255,0.12); }
.nav-item.active { background: rgba(255,255,255,0.22); color: #fff; font-weight: 600; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.15);
}

.nav-item.logout { color: #fecaca; }

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
}

.page-title {
  font-size: 1.15rem;
  margin: 0;
  flex: 1;
}

.topbar-user { font-size: 0.9rem; color: var(--text-muted); }

.content {
  padding: 22px 24px;
  flex: 1;
}

.app-footer {
  padding: 14px 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--green-dark), var(--blue));
}

.login-card {
  background: #fff;
  padding: 36px 32px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}

.login-brand { text-align: center; margin-bottom: 18px; }

.login-badge {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--green));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(14,165,233,0.32);
}

.login-badge svg {
  width: 30px;
  height: 30px;
  stroke: #fff;
  display: block;
}

.login-brand h1 { font-size: 1.15rem; margin: 6px 0 2px; color: var(--green-dark); }
.login-brand p { color: var(--text-muted); font-size: 0.85rem; margin: 0; }

.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-hint { text-align: center; font-size: 0.78rem; color: var(--text-muted); margin-top: 10px; }

.input-icon-wrap { position: relative; }

.input-icon-wrap input[type] {
  /* [type] เพิ่มความจำเพาะ (specificity) ให้สูงกว่ากฎ input[type="text"]/[type="password"] ทั่วไปด้านล่าง
     ป้องกันไม่ให้ padding-left ถูกทับด้วย padding: 9px 11px แล้วทำให้ไอคอนซ้อนทับกับตัวอักษรที่พิมพ์ */
  width: 100%;
  padding-left: 38px;
}

.input-icon-wrap svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  stroke: var(--text-muted);
  pointer-events: none;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.btn-line {
  background: #06c755;
  color: #fff;
  gap: 8px;
}

.btn-line:hover { background: #05b34c; }

.line-icon {
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  background: rgba(255,255,255,0.25);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---------- Cards / Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(15,23,42,0.06);
  border-left: 5px solid var(--blue);
}

.stat-blue { border-left-color: var(--blue); }
.stat-green { border-left-color: var(--green); }
.stat-teal { border-left-color: var(--green-dark); }

.stat-value { font-size: 1.7rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

/* ---------- Panels ---------- */
.panel {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 8px rgba(15,23,42,0.06);
  margin-bottom: 20px;
}

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

.panel-header h2 { font-size: 1.05rem; margin: 0; }

/* ---------- Forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="month"],
input[type="password"],
select,
textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.search-form, .filter-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Payroll form columns ---------- */
.payroll-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 18px;
}

@media (max-width: 720px) {
  .payroll-columns { grid-template-columns: 1fr; }
}

.col-title {
  font-size: 0.95rem;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 10px;
}

.income-title { color: var(--green-dark); border-color: var(--green); }
.deduct-title { color: var(--blue-dark); border-color: var(--blue); }

.amount-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.88rem;
}

.amount-row input {
  width: 130px;
  text-align: right;
}

.total-row {
  font-weight: 700;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 10px;
}

.net-summary {
  display: flex;
  justify-content: space-between;
  background: #ecfdf5;
  color: var(--green-dark);
  font-weight: 700;
  padding: 14px 18px;
  border-radius: 8px;
  margin: 20px 0;
  font-size: 1.05rem;
}

/* ---------- Settings / Signature ---------- */
.signature-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.signature-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

.signature-preview img {
  max-height: 80px;
  max-width: 220px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
}

.signature-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.field-hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--green));
  color: #fff;
}

.btn-outline {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border-color: #fecaca;
}

.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: #f8fafc;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.text-right { text-align: right; }

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.inline-form { display: inline; }

.empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 24px !important;
}

/* ---------- Badges / Alerts ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}

.badge-green { background: #dcfce7; color: #15803d; }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.88rem;
}

.alert-success { background: #dcfce7; color: #15803d; }
.alert-error { background: #fee2e2; color: #b91c1c; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    margin-left: calc(var(--sidebar-w) * -1);
    z-index: 30;
    box-shadow: 4px 0 16px rgba(0,0,0,0.2);
  }
  .sidebar.open { margin-left: 0; }
  .sidebar-toggle { display: block; }
}
