/* =============================================
   My-RIAN App — Stylesheet
   Mobile-first, system font, CSS custom props
   ============================================= */

:root {
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-sidebar: #cbd5e1;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --border: #e2e8f0;
  --bg-muted: #f1f5f9;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --sidebar-w: 240px;
  --topbar-h: 56px;
}

/* Dark theme: follows the device setting (Auto), or forced with data-theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.4);
    --bg-muted: #0f172a;
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.4);
  --bg-muted: #0f172a;
}
:root { color-scheme: light dark; }            /* native inputs/date pickers follow the theme */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }


/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* =============================================
   Layout
   ============================================= */

.app-container { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar.closed { transform: translateX(-100%); }

.sidebar-brand {
  padding: 20px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.02em;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand span { color: var(--primary); }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.nav-section {
  padding: 8px 20px 4px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255,255,255,.35);
  margin-top: 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: .875rem;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.active {
  background: rgba(37,99,235,.15);
  color: #fff;
  border-left-color: var(--primary);
}
.nav-link svg { width: 18px; height: 18px; opacity: .7; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .7rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .8rem;
}
.sidebar-footer .user-name { color: #fff; font-weight: 600; }
.sidebar-footer .user-role { color: var(--text-muted); font-size: .7rem; text-transform: uppercase; }

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1.05rem; font-weight: 600; }

.btn-menu {
  display: none;
  background: none; border: none;
  color: var(--text); cursor: pointer; padding: 8px;
}
.btn-menu svg { width: 24px; height: 24px; }

.online-badge {
  font-size: .75rem;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 500;
}
.online-badge.online { background: #dcfce7; color: #166534; }
.online-badge.offline { background: #fef2f2; color: #991b1b; }

/* Page content */
.page-content { padding: 24px; max-width: 1200px; }

/* =============================================
   Components
   ============================================= */

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 600; }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { padding: 20px; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  font-family: var(--font);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 12px; font-size: .8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: var(--font);
  background: var(--bg-card);
  color: var(--text);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-control.error { border-color: var(--danger); }
select.form-control { appearance: auto; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; font-weight: 600; padding: 10px 12px; border-bottom: 2px solid var(--border); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:hover td { background: rgba(0,0,0,.02); }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 500;
}
.badge-active, .badge-approved, .badge-present { background: #dcfce7; color: #166534; }
.badge-pending, .badge-submitted { background: #fef3c7; color: #92400e; }
.badge-inactive, .badge-rejected, .badge-absent { background: #fef2f2; color: #991b1b; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-school_head { background: #dbeafe; color: #1e40af; }
.badge-hr_staff { background: #fce7f3; color: #9d174d; }
.badge-employee { background: #f1f5f9; color: #475569; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--bg-card); }
.modal-close {
  background: none; border: none; font-size: 1.5rem;
  cursor: pointer; color: var(--text-muted); line-height: 1;
}

/* Toast / Alerts */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: .875rem;
  max-width: 360px;
  animation: slideIn .25s ease;
}
.toast-success { background: #166534; color: #fff; }
.toast-error { background: #991b1b; color: #fff; }
.toast-warning { background: #92400e; color: #fff; }
.toast-info { background: #1e40af; color: #fff; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Punch buttons */
.punch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 500px; margin: 0 auto; }
.punch-btn {
  padding: 32px 20px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  cursor: pointer;
  text-align: center;
  transition: all .2s;
  font-family: var(--font);
}
.punch-btn:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.punch-btn.done { border-color: var(--success); background: #f0fdf4; opacity: .6; pointer-events: none; }
.punch-btn .punch-icon { font-size: 2rem; margin-bottom: 8px; }
.punch-btn .punch-label { font-size: .95rem; font-weight: 600; }
.punch-btn .punch-time { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* Webcam */
.webcam-container {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
.webcam-container video { width: 100%; display: block; }
.webcam-container canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
  padding: 16px;
}
.login-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 40px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 4px;
  text-align: center;
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
  margin-bottom: 28px;
}
.login-error {
  background: #fef2f2;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: .85rem;
  margin-bottom: 16px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .4; }

/* Loading */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   Responsive — mobile
   ============================================= */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .btn-menu { display: block; }
  .topbar { padding: 0 16px; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .punch-grid { grid-template-columns: 1fr; }
  .sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
  }

  /* =============================================
     Tables → Cards on mobile
     ============================================= */
  .table-wrap { overflow-x: visible; }

  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap th,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    padding: 12px 16px;
    position: relative;
  }

  .table-wrap tbody tr:hover td {
    background: transparent;
  }

  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: .875rem;
    text-align: right;
  }

  .table-wrap td:last-child {
    border-bottom: none;
    padding-top: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  .table-wrap td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    margin-right: 12px;
  }

  /* Card-header style for first cell */
  .table-wrap td:first-child {
    font-weight: 600;
    font-size: .95rem;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 2px;
  }

  /* Action buttons row */
  .table-wrap td:last-child .btn {
    flex: 0 0 auto;
  }

  /* Modal responsive */
  .modal { max-width: 100%; margin: 8px; }
  .modal-body .form-row { grid-template-columns: 1fr; }
}

/* Small phones */
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .punch-grid { grid-template-columns: 1fr; }
  .page-content { padding: 12px; }
}

/* Dashboard charts: stack on phones */
@media (max-width: 768px) { .dash-chart-grid { grid-template-columns: 1fr !important; } }

@media (max-width: 768px) { .up-grid { grid-template-columns: 1fr !important; } }
