/* ============================================================
   FEBC Admin — ส่วนเสริมของหลังบ้าน (ใช้คู่กับ style.css)
   ============================================================ */
.admin-body { background: var(--color-bg); }
.admin-body .btn-primary { width: auto; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); padding: var(--space-3) var(--space-6); font-size: var(--text-sm); border: none; cursor: pointer; text-decoration: none; }

/* Sidebar */
.admin-brand { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text); text-decoration: none; font-weight: 700; font-size: var(--text-sm); }
.admin-nav { display: flex; flex-direction: column; }
.admin-nav-group { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--color-text-faint); padding: var(--space-4) var(--space-3) var(--space-2); }
.admin-nav-item.active { font-weight: 600; }
.admin-nav-spacer { flex: 1; min-height: var(--space-6); }
.admin-user-card { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); margin-top: var(--space-2); border-top: 1px solid var(--color-divider); }
.admin-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--grad-brand); color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.admin-user-meta { flex: 1; min-width: 0; line-height: 1.25; }
.admin-user-meta strong { display: block; font-size: var(--text-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-user-meta span { font-size: 11px; color: var(--color-text-faint); }
.admin-logout { width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-md); color: var(--color-error); }
.admin-logout:hover { background: color-mix(in srgb, var(--color-error) 12%, transparent); }
.admin-logout svg { width: 18px; height: 18px; }

/* Topbar */
.admin-topbar { position: sticky; top: 0; z-index: 50; }
.admin-topbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.admin-burger { display: none; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: var(--radius-md); color: var(--color-text); background: none; border: none; cursor: pointer; }
.admin-overlay { display: none; }
.admin-content { max-width: 1280px; }
.admin-content > .alert-success, .admin-content > .alert-error { margin-bottom: var(--space-5); }

@media (max-width: 900px) {
  .admin-burger { display: inline-flex; }
  .admin-sidebar { position: fixed; left: -260px; top: 0; z-index: 300; width: 250px; height: 100dvh; transition: left var(--dur-base) var(--ease); box-shadow: var(--shadow-lg); }
  .nav-open .admin-sidebar { left: 0; }
  .nav-open .admin-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 250; }
  .admin-topbar { padding: var(--space-3) var(--space-4); }
}

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); font: inherit; font-size: var(--text-sm); font-weight: 500; border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); cursor: pointer; text-decoration: none; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); white-space: nowrap; }
.btn:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-green { background: #15803d; border-color: #15803d; color: #fff; }
.btn-green:hover { background: #166534; color: #fff; }
.btn-danger { color: var(--color-error); border-color: color-mix(in srgb, var(--color-error) 45%, var(--color-border)); }
.btn-danger:hover { background: var(--color-error); color: #fff; border-color: var(--color-error); }
.btn-sm { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.btn-sm.danger { color: var(--color-error); }
.btn-sm.danger:hover { border-color: var(--color-error); color: #fff; background: var(--color-error); }

/* Toolbar / cards */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.toolbar h2 { font-size: var(--text-lg); font-weight: 700; margin: 0; }
.toolbar-right { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: var(--space-5); }
.card h3 { font-size: var(--text-base); font-weight: 600; margin: 0 0 var(--space-1); }
.card .card-sub { font-size: var(--text-xs); color: var(--color-text-faint); margin: 0 0 var(--space-4); }
.muted { color: var(--color-text-muted); }
.faint { color: var(--color-text-faint); font-size: var(--text-xs); }
.num { font-variant-numeric: tabular-nums; text-align: right; }

select.form-input { appearance: auto; }
.form-input { width: 100%; box-sizing: border-box; }
.month-select { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); min-width: 170px; width: auto; }

/* Table helpers */
.admin-table td.actions { white-space: nowrap; }
.admin-table td.actions > * + * { margin-left: 4px; }
.admin-table tr.row-off td { opacity: .5; }
.admin-table tr.row-off td.actions { opacity: 1; }
.admin-table tfoot td { font-weight: 700; background: var(--color-surface-offset); border-top: 1px solid var(--color-border); }
.admin-table-wrap { overflow-x: auto; }
.bar-cell { display: flex; align-items: center; gap: var(--space-3); justify-content: flex-end; }
.bar-track { flex: 1; max-width: 220px; height: 8px; background: var(--color-surface-offset); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--grad-brand); border-radius: 99px; }
.badge-gray { background: var(--color-surface-offset); color: var(--color-text-muted); }
.badge-red { background: #fee2e2; color: #b91c1c; }
[data-theme="dark"] .badge-red { background: #3f1515; color: #fca5a5; }

/* Modal */
.modal { display: none; position: fixed; inset: 0; z-index: 500; background: rgba(0,0,0,.55); align-items: center; justify-content: center; padding: var(--space-4); }
.modal.open { display: flex; }
.modal-box { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: var(--space-6); width: 100%; max-width: 560px; box-shadow: var(--shadow-lg); max-height: 92dvh; overflow-y: auto; }
.modal-box h2 { font-size: var(--text-lg); font-weight: 700; margin: 0 0 var(--space-5); }
.modal-actions { display: flex; gap: var(--space-3); margin-top: var(--space-5); }
.modal-actions .btn-primary { flex: 1; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--space-4); }
@media (max-width: 560px) { .form-grid-2 { grid-template-columns: 1fr; } }
.hint { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: 2px; }

/* Day picker */
.day-presets { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }
.day-presets button { font: inherit; font-size: var(--text-xs); padding: 4px 12px; border-radius: 99px; border: 1px solid var(--color-border); background: var(--color-surface-offset); color: var(--color-text); cursor: pointer; }
.day-presets button.on { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.day-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.day-chips label { position: relative; }
.day-chips input { position: absolute; opacity: 0; pointer-events: none; }
.day-chips span { display: inline-flex; width: 42px; height: 34px; align-items: center; justify-content: center; border-radius: var(--radius-md); border: 1px solid var(--color-border); font-size: var(--text-sm); cursor: pointer; user-select: none; }
.day-chips input:checked + span { background: var(--color-primary-highlight); border-color: var(--color-primary); color: var(--color-primary); font-weight: 600; }
.day-chips input:focus-visible + span { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: var(--text-sm); }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 40px; height: 22px; border-radius: 99px; background: var(--color-border); position: relative; transition: background var(--dur-fast) var(--ease); flex-shrink: 0; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform var(--dur-fast) var(--ease); }
.switch input:checked + .track { background: var(--color-primary); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Password eye */
.pw-wrap { position: relative; }
.pw-wrap .form-input { padding-right: 46px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; display: grid; place-items: center; background: none; border: none; color: var(--color-text-muted); cursor: pointer; border-radius: var(--radius-md); }
.pw-eye:hover { color: var(--color-primary); }
.pw-eye svg { width: 20px; height: 20px; }
.pw-eye .eye-off { display: none; }
.pw-eye.is-on .eye-open { display: none; }
.pw-eye.is-on .eye-off { display: block; }
.check { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--color-primary); }

/* Dashboard */
.dash-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.kpi { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-xl); padding: var(--space-5); position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-c, var(--color-primary)); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.kpi-name { font-size: var(--text-xs); color: var(--color-text-muted); font-weight: 500; }
.kpi-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: color-mix(in srgb, var(--kpi-c, var(--color-primary)) 14%, transparent); color: var(--kpi-c, var(--color-primary)); }
.kpi-ico svg { width: 18px; height: 18px; }
.kpi-big { font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.3rem); font-weight: 700; font-variant-numeric: tabular-nums; margin: var(--space-2) 0 2px; line-height: 1.1; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-size: var(--text-xs); font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.delta.up { background: #dcfce7; color: #15803d; }
.delta.down { background: #fee2e2; color: #b91c1c; }
.delta.flat { background: var(--color-surface-offset); color: var(--color-text-muted); }
[data-theme="dark"] .delta.up { background: #14341f; color: #86efac; }
[data-theme="dark"] .delta.down { background: #3f1515; color: #fca5a5; }
.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--space-4); margin-bottom: var(--space-4); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; } .span-4 { grid-column: span 4; }
@media (max-width: 1100px) { .span-8, .span-4 { grid-column: span 12; } }
@media (max-width: 800px)  { .span-6 { grid-column: span 12; } }
.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 420px; }
.chart-box.short { height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-3); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.seg { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.seg a { padding: 6px 12px; font-size: var(--text-xs); color: var(--color-text-muted); text-decoration: none; }
.seg a.on { background: var(--color-primary); color: #fff; }

@media print {
  .admin-sidebar, .admin-topbar, .toolbar-right, .no-print, .admin-overlay { display: none !important; }
  .admin-content { padding: 0 !important; max-width: none; }
  body { background: #fff !important; color: #000 !important; }
  .admin-table th, .admin-table td { border: 1px solid #999 !important; color: #000 !important; }
  .print-title { display: block !important; text-align: center; margin-bottom: 12px; }
}
.print-title { display: none; }
.admin-table .badge { white-space: nowrap; }
