/* =====================================================================
   Event ERP theme. All colours come from the variables below; the brand
   colour is injected from Settings (see brand_style_tag()).
   Mobile-first behaviour lives at the bottom (max-width breakpoints).
   ===================================================================== */
:root {
  --primary: #4f46e5;
  --secondary: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0284c7;
  --dark: #0f172a;
  --light: #f4f6fb;
  --border: #e6e9f0;
  --surface: #ffffff;
  --muted: #64748b;
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-width: 264px;
  --topbar-height: 60px;
  --bottom-nav-height: 66px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 6px 22px rgba(15, 23, 42, .08);
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body { background: var(--light); color: var(--dark); font-size: .925rem; -webkit-tap-highlight-color: transparent; }
h5, .h5 { font-weight: 700; letter-spacing: -.01em; }
a { color: var(--primary); }

/* ---------- Buttons / forms tuned to the brand colour ---------- */
.btn { border-radius: var(--radius-sm); font-weight: 600; }
.btn-primary {
  --bs-btn-bg: var(--primary); --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: color-mix(in srgb, var(--primary) 86%, #000); --bs-btn-hover-border-color: color-mix(in srgb, var(--primary) 86%, #000);
  --bs-btn-active-bg: color-mix(in srgb, var(--primary) 78%, #000); --bs-btn-active-border-color: color-mix(in srgb, var(--primary) 78%, #000);
  --bs-btn-disabled-bg: var(--primary); --bs-btn-disabled-border-color: var(--primary);
}
.btn-outline-primary { --bs-btn-color: var(--primary); --bs-btn-border-color: var(--primary); --bs-btn-hover-bg: var(--primary); --bs-btn-hover-border-color: var(--primary); --bs-btn-active-bg: var(--primary); }
.form-control, .form-select { border-radius: var(--radius-sm); border-color: #d8dde8; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--primary) 18%, transparent); }
.form-label { font-weight: 600; font-size: .8rem; color: #334155; margin-bottom: .3rem; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.nav-pills .nav-link.active { background: var(--primary); }
.nav-pills .nav-link { border-radius: 999px; font-weight: 600; font-size: .85rem; }
.page-link { color: var(--primary); }
.badge { font-weight: 600; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width); flex-shrink: 0; position: fixed; inset: 0 auto 0 0; z-index: 1040;
  background: linear-gradient(180deg, #111827 0%, #0f172a 100%); color: #cbd5e1;
  display: flex; flex-direction: column; transition: transform .25s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: .7rem; padding: 18px 18px 16px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.07); }
.sidebar .brand .brand-name { font-weight: 700; font-size: 1.02rem; line-height: 1.15; }
.sidebar .brand .brand-sub { font-size: .7rem; color: #94a3b8; }
.brand-tile { display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--primary); color: #fff; font-weight: 700; flex-shrink: 0; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 10px 6px; }
.nav-caption { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 12px 12px 4px; }
.sidebar a.nav-link {
  color: #cbd5e1; padding: 10px 12px; margin-bottom: 2px; border-radius: 10px; display: flex; align-items: center; gap: 12px; font-weight: 500; position: relative;
}
.sidebar a.nav-link i { font-size: 1.15rem; width: 22px; text-align: center; opacity: .9; }
.sidebar a.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-link.active { background: color-mix(in srgb, var(--primary) 28%, transparent); color: #fff; }
.sidebar a.nav-link.active::before { content: ""; position: absolute; left: -10px; top: 9px; bottom: 9px; width: 4px; border-radius: 0 4px 4px 0; background: var(--primary); }
.sidebar-user { border-top: 1px solid rgba(255,255,255,.07); padding: 12px 14px; display: flex; align-items: center; gap: .7rem; }
.sidebar-user .avatar { width: 38px; height: 38px; border-radius: 50%; background: color-mix(in srgb, var(--primary) 60%, #1e293b); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.sidebar-user .who { min-width: 0; flex: 1; }
.sidebar-user .who .n { color: #fff; font-weight: 600; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who .r { font-size: .7rem; color: #94a3b8; }
.sidebar-user a { color: #94a3b8; font-size: 1.25rem; padding: 8px; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); backdrop-filter: blur(2px); z-index: 1035; display: none; }
.sidebar-backdrop.show { display: block; }

.main-wrap { margin-left: var(--sidebar-width); flex-grow: 1; min-width: 0; width: 100%; }
.topbar {
  height: var(--topbar-height); background: rgba(255,255,255,.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .75rem; padding: 0 22px; position: sticky; top: 0; z-index: 1020;
}
.topbar .icon-btn { width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: var(--dark); text-decoration: none; position: relative; background: transparent; border: 0; font-size: 1.3rem; }
.topbar .icon-btn:hover { background: #eef1f7; }
.topbar .icon-btn .dot { position: absolute; top: 4px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; }
.topbar .search-box { max-width: 420px; flex: 1; }
.topbar .search-box .form-control { background: #f1f4f9; border-color: transparent; }
.content { padding: 22px; max-width: 1500px; }

/* ---------- Cards, stats, tables ---------- */
.card { border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); background: var(--surface); }
.card-header { background: transparent; border-bottom: 1px solid var(--border); padding: .9rem 1.1rem; font-weight: 700; }
.card > .table-responsive-wrap:last-child table { margin-bottom: 0; }

.stat-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 16px 18px; height: 100%; box-shadow: var(--shadow-sm); display: block; }
.stat-card.has-icon { display: flex; align-items: center; gap: .9rem; }
.stat-icon { width: 46px; height: 46px; border-radius: 13px; display: inline-flex; align-items: center; justify-content: center; font-size: 1.4rem; flex-shrink: 0; }
.tone-primary { background: color-mix(in srgb, var(--primary) 12%, #fff); color: var(--primary); }
.tone-success { background: #dcfce7; color: #15803d; }
.tone-warning { background: #fef3c7; color: #b45309; }
.tone-danger  { background: #fee2e2; color: #b91c1c; }
.tone-info    { background: #e0f2fe; color: #0369a1; }
.tone-dark    { background: #e2e8f0; color: #334155; }
.stat-card .stat-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.stat-card .stat-value { font-size: 1.45rem; font-weight: 800; color: var(--dark); line-height: 1.2; letter-spacing: -.02em; word-break: break-word; }
.stat-card.clickable { transition: transform .12s ease, box-shadow .15s ease; }
.stat-card.clickable:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card.border-warning { border-color: #fcd34d !important; background: #fffbeb; }
.stat-card.border-danger { border-color: #fca5a5 !important; }

.table-responsive-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .75rem .9rem; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--border); font-weight: 700; white-space: nowrap; }
.table td, .table th { vertical-align: middle; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #f8fafc; }

.badge-pending { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.empty-state { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty-state i { font-size: 2.6rem; opacity: .45; display: block; margin-bottom: 8px; }

.section-title { font-weight: 800; font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 6px 0 12px; }
.modal-content { border: 0; border-radius: 18px; box-shadow: var(--shadow); }
.modal-header, .modal-footer { border-color: var(--border); }
.list-group-item { border-color: var(--border); }
.dropdown-menu { border-radius: 12px; border-color: var(--border); box-shadow: var(--shadow); padding: 6px; }
.dropdown-item { border-radius: 8px; padding: .5rem .75rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--primary) 55%, #0f172a), transparent 60%), linear-gradient(160deg, #0f172a, #1e1b4b); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 22px; padding: 34px 28px 28px; box-shadow: 0 30px 70px rgba(0,0,0,.35); }
.login-card .form-control { min-height: 48px; }
.login-card .btn-primary { min-height: 48px; font-size: 1rem; }

/* ---------- Bottom navigation (phones/tablets) ---------- */
.bottom-nav { display: none; }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; }

/* ---------- Tablet & phone ---------- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-102%); box-shadow: none; }
  .sidebar.show { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,.5); }
  .main-wrap { margin-left: 0; }
  .topbar { padding: 0 12px; }
  .content { padding: 14px 14px calc(var(--bottom-nav-height) + 24px + env(safe-area-inset-bottom)); }

  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: rgba(255,255,255,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(15,23,42,.06);
  }
  .bottom-nav .bn-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #64748b; text-decoration: none; font-size: .66rem; font-weight: 600; background: none; border: 0; padding: 6px 2px; min-width: 0; }
  .bottom-nav .bn-item i { font-size: 1.45rem; line-height: 1; }
  .bottom-nav .bn-item.active { color: var(--primary); }
  .bottom-nav .bn-item.primary i { background: var(--primary); color: #fff; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-top: -22px; box-shadow: 0 8px 18px color-mix(in srgb, var(--primary) 45%, transparent); border: 4px solid #fff; box-sizing: content-box; }
  .bottom-nav .bn-item.primary span { margin-top: 2px; }
}

/* ---------- Phone ---------- */
@media (max-width: 767.98px) {
  body { font-size: .95rem; }
  .form-control, .form-select { font-size: 1rem; min-height: 46px; }   /* 16px prevents iOS zoom-on-focus */
  textarea.form-control { min-height: 84px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; padding-left: .8rem; padding-right: .8rem; }
  .page-link { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .stat-card { padding: 14px; }
  .stat-card .stat-value { font-size: 1.15rem; }
  .stat-icon { width: 40px; height: 40px; font-size: 1.2rem; }
  .card-body { padding: 1rem; }
  h5, .h5 { font-size: 1.1rem; }
  .content .d-flex.justify-content-between.align-items-center.mb-3 { flex-wrap: wrap; gap: .6rem; }

  /* Tables turn into readable cards (labels are injected by main.js) */
  .table-mobile-cards { border: 0; }
  .table-mobile-cards thead { display: none; }
  .table-mobile-cards tbody, .table-mobile-cards tr, .table-mobile-cards td { display: block; width: 100%; }
  .table-mobile-cards tbody tr {
    margin: 0 0 12px; padding: 6px 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
  }
  .table-mobile-cards tbody tr.collapse:not(.show) { display: none; }
  .table-mobile-cards td { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: .42rem .8rem !important; border: 0 !important; text-align: right; word-break: break-word; }
  .table-mobile-cards td::before { content: attr(data-label); font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: 0 0 38%; padding-top: 2px; }
  .table-mobile-cards td[data-label=""]::before, .table-mobile-cards td.td-full::before { display: none; }
  .table-mobile-cards td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; padding-top: .6rem !important; border-top: 1px dashed var(--border) !important; margin-top: 4px; }
  .table-mobile-cards td.td-full { display: block; text-align: center; }
  .table-mobile-cards td > .small, .table-mobile-cards td > div { text-align: right; }
  .table-mobile-cards td form { display: inline-block; }
  .card > .table-responsive-wrap { padding: 12px; background: var(--light); border-radius: var(--radius); }
  .card:has(> .table-mobile-cards-wrap), .card:has(> .table-responsive-wrap > .table-mobile-cards) { background: transparent; border: 0; box-shadow: none; }

  /* Collapsible filter forms */
  form.js-filters { display: none !important; }
  form.js-filters.open { display: flex !important; }
  .filter-toggle { display: flex !important; }

  /* Sticky primary action bars on long forms */
  .sticky-actions { padding: 10px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, var(--light) 30%); bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom)); }
  .sticky-actions .btn { width: 100%; min-height: 50px; font-size: 1rem; }

  .pagination-wrap, .content .pagination { flex-wrap: wrap; }
}
.filter-toggle { display: none; }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .bottom-nav, .sidebar-backdrop, .btn, .filter-toggle { display: none !important; }
  .main-wrap { margin-left: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}

/* ---------- Attendance camera with live stamp ---------- */
.cam-wrap { position: relative; border-radius: 14px; overflow: hidden; background: #000; }
.cam-wrap video, .cam-wrap img { display: block; width: 100%; max-height: 62vh; object-fit: cover; }
.cam-wrap .stamp {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 12px 10px; text-align: left; color: #fff; font-size: .72rem; line-height: 1.35;
  background: linear-gradient(to top, rgba(8, 12, 24, .88), rgba(8, 12, 24, .55) 70%, transparent); text-shadow: 0 1px 2px #000;
}
.cam-wrap .stamp .st-time { font-weight: 800; font-size: .92rem; color: #5eead4; letter-spacing: .01em; }
.cam-wrap .stamp #stAddr { opacity: .95; }
