/* ================================================================
   SMS Platform — Mobile-First Design System
   ================================================================ */

:root {
  --primary: #1a56db;
  --primary-dark: #1341b5;
  --primary-light: #e8f0fe;
  --secondary: #6c757d;
  --success: #0d9488;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --info: #0ea5e9;
  --info-light: #e0f2fe;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --sidebar-w: 260px;
  --topbar-h: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--text-primary);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-name { font-size: 1.125rem; font-weight: 700; color: #fff; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.75rem; color: #94a3b8; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 0.75rem 0; }

.nav-section-label {
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: #64748b; padding: 0.75rem 1.25rem 0.25rem;
}

.nav-item { display: block; margin: 1px 0.5rem; }

.nav-link {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.625rem 0.875rem; border-radius: var(--radius-sm);
  color: #cbd5e1; font-size: 0.875rem; font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { font-size: 1rem; width: 1.125rem; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 1rem; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 0.8125rem; color: #94a3b8;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1.25rem; gap: 0.75rem;
  position: sticky; top: 0; z-index: 900;
}

.topbar-toggle {
  display: none; background: none; border: none; padding: 0.375rem;
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-secondary); font-size: 1.25rem;
}

.topbar-title { font-weight: 600; font-size: 1rem; color: var(--text-primary); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }

.topbar-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 0.8125rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

/* ── Main Content ────────────────────────────────────────────── */
.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }
.page-body { padding: 1.5rem; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.9375rem;
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
}
.card-body { padding: 1.25rem; }

/* ── Stat Cards ──────────────────────────────────────────────── */
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; display: flex; align-items: center; gap: 1rem; box-shadow: var(--shadow);
}
.stat-icon {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0;
}
.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8125rem; color: var(--text-secondary); margin-top: 2px; }

/* ── Tables ──────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th {
  background: var(--surface-2); font-weight: 600; font-size: 0.75rem;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary);
  padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 0.875rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.25rem 0.6rem; border-radius: 100px; font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge-success { background: var(--success-light); color: #065f46; }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-danger { background: var(--danger-light); color: #991b1b; }
.badge-info { background: var(--info-light); color: #0c4a6e; }
.badge-secondary { background: var(--surface-2); color: var(--text-secondary); }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  padding: 0.5625rem 1.125rem; border-radius: var(--radius-sm); font-size: 0.875rem;
  font-weight: 500; border: none; cursor: pointer; transition: all var(--transition);
  white-space: nowrap; text-decoration: none; line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #0f766e; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text-secondary); }
.btn-outline:hover { background: var(--surface-2); color: var(--text-primary); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.875rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.125rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 500; color: var(--text-primary); margin-bottom: 0.375rem; }
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control, .form-select {
  display: block; width: 100%; padding: 0.625rem 0.875rem;
  font-size: 0.9375rem; font-family: var(--font); color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none; appearance: none;
}
.form-control:focus, .form-select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.875rem center; padding-right: 2.25rem;
}
.form-text { font-size: 0.8125rem; color: var(--text-muted); margin-top: 0.25rem; }
.form-error { font-size: 0.8125rem; color: var(--danger); margin-top: 0.25rem; }
.form-check { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.form-check-input { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-radius: 4px; cursor: pointer; accent-color: var(--primary); }
.form-check-label { font-size: 0.875rem; color: var(--text-primary); cursor: pointer; }

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.page-header-title { font-size: 1.375rem; font-weight: 700; margin: 0; }
.page-header-sub { font-size: 0.875rem; color: var(--text-secondary); margin-top: 2px; }

/* ── Alerts ──────────────────────────────────────────────────── */
.alert {
  padding: 0.875rem 1.125rem; border-radius: var(--radius-sm);
  font-size: 0.875rem; margin-bottom: 1rem;
  display: flex; align-items: flex-start; gap: 0.625rem;
}
.alert-success { background: var(--success-light); color: #065f46; border-left: 4px solid var(--success); }
.alert-warning { background: var(--warning-light); color: #92400e; border-left: 4px solid var(--warning); }
.alert-danger { background: var(--danger-light); color: #991b1b; border-left: 4px solid var(--danger); }
.alert-info { background: var(--info-light); color: #0c4a6e; border-left: 4px solid var(--info); }

/* ── Student Card ────────────────────────────────────────────── */
.student-card { display: flex; align-items: center; gap: 0.75rem; }
.student-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  font-weight: 700; font-size: 0.9375rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden;
}
.student-avatar img { width: 100%; height: 100%; object-fit: cover; }
.student-name { font-weight: 600; font-size: 0.9375rem; }
.student-meta { font-size: 0.8125rem; color: var(--text-secondary); }

/* ── Progress ────────────────────────────────────────────────── */
.progress { height: 8px; background: var(--surface-2); border-radius: 100px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 100px; transition: width 0.4s ease; }
.progress-bar.success { background: var(--success); }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ── Attendance Buttons ──────────────────────────────────────── */
.att-btn-group { display: flex; gap: 4px; }
.att-btn {
  width: 36px; height: 36px; border-radius: 6px; border: 2px solid var(--border);
  background: var(--surface); font-size: 0.75rem; font-weight: 700;
  cursor: pointer; transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.att-btn:hover { border-color: var(--primary); color: var(--primary); }
.att-btn.selected-P { background: var(--success-light); border-color: var(--success); color: #065f46; }
.att-btn.selected-A { background: var(--danger-light); border-color: var(--danger); color: #991b1b; }
.att-btn.selected-L { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.att-btn.selected-E { background: var(--info-light); border-color: var(--info); color: #0c4a6e; }

/* ── Mobile Overlay ──────────────────────────────────────────── */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 999; }

/* ── Utility ─────────────────────────────────────────────────── */
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fs-sm { font-size: 0.8125rem; }
.w-100 { width: 100%; }
.text-center { text-align: center; }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

/* ── Login Page ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%); padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border-radius: var(--radius-lg); padding: 2.5rem 2rem; box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 2rem; }
.login-logo .logo-mark {
  width: 56px; height: 56px; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-size: 1.5rem;
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 0.75rem;
}
.login-logo h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
.login-logo p { font-size: 0.875rem; color: var(--text-secondary); margin: 4px 0 0; }

/* ── PWA Install Banner ──────────────────────────────────────── */
.pwa-banner {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--text-primary); color: #fff; padding: 1rem 1.25rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  z-index: 2000; transform: translateY(100%); transition: transform 0.35s ease;
}
.pwa-banner.visible { transform: translateY(0); }
.pwa-banner-text { font-size: 0.875rem; }
.pwa-banner-text strong { display: block; }
.pwa-banner-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* ── Divider ─────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { margin: 0 0 1rem; font-size: 0.9375rem; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.visible { display: block; }
  .main-content { margin-left: 0; }
  .topbar-toggle { display: flex; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page-body { padding: 1rem; }
  .hide-mobile { display: none !important; }
}
@media(max-width:768px){

    .grid-stats{
        grid-template-columns:1fr;
    }

}
@media (max-width: 576px) {
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.375rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .btn { width: 100%; justify-content: center; }
}

@media (max-width: 400px) {
  .grid-stats { grid-template-columns: 1fr; }
  .login-card { padding: 2rem 1.25rem; }
}

@media print {
  .sidebar, .topbar, .pwa-banner { display: none; }
  .main-content { margin-left: 0; }
}

/* ---------- DataTables ---------- */

.dt-container{
    font-family: var(--font);
}

.dt-layout-row{
    margin-bottom:1rem;
}

.dt-search input,
.dt-length select{
    padding:8px 12px;
    border:1px solid var(--border);
    border-radius:var(--radius-sm);
    background:#fff;
}

.dt-button{
    background:var(--primary)!important;
    color:#fff!important;
    border:none!important;
    border-radius:var(--radius-sm)!important;
    padding:8px 14px!important;
    margin-right:6px!important;
    cursor:pointer;
}

.dt-button:hover{
    background:var(--primary-dark)!important;
}

.dt-paging button{
    border-radius:var(--radius-sm)!important;
    margin:2px!important;
}

table.dataTable thead th{
    background:var(--surface-2);
}

table.dataTable tbody tr:hover{
    background:var(--surface-2);
}

.dt-info{
    color:var(--text-secondary);
}

/* ── Responsive Card Table ───────────────────────────────────── */
/*
   Usage: add class "card-table" to any <table>
   On mobile (≤768px) each row becomes a card automatically.
   Column headers are read from data-label attributes (auto-set by JS).
*/

.card-table-wrapper { width: 100%; }

/* Desktop — normal table */
.card-table { width: 100%; border-collapse: collapse; }

@media (max-width: 768px) {

  /* Hide the real header */
  .card-table thead { display: none; }

  /* Each row becomes a card */
  .card-table tbody tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: .875rem;
    padding: .75rem 1rem;
    position: relative;
  }

  .card-table tbody tr:hover { background: var(--surface); }

  /* Each cell becomes a flex row: label on left, value on right */
  .card-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .75rem;
    padding: .375rem 0;
    border: none;
    border-bottom: 1px solid var(--border);
    font-size: .875rem;
  }

  .card-table td:last-child { border-bottom: none; padding-bottom: 0; }
  .card-table td:first-child { padding-top: 0; }

  /* The auto-generated label */
  .card-table td::before {
    content: attr(data-label);
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 90px;
    padding-top: 2px;
  }

  /* Cell content aligns right */
  .card-table td > * { text-align: right; }
  .card-table td .student-card { flex-direction: column; align-items: flex-end; text-align: right; }

  /* First cell (primary info) gets special treatment — full width, no label */
  .card-table td.card-primary {
    flex-direction: column;
    align-items: flex-start;
    border-bottom: 1px solid var(--border);
    padding-bottom: .625rem;
    margin-bottom: .125rem;
  }

  .card-table td.card-primary::before { display: none; }
  .card-table td.card-primary > * { text-align: left; }
  .card-table td.card-primary .student-card {
    flex-direction: row;
    align-items: center;
    text-align: left;
  }

  /* Actions row — full width buttons */
  .card-table td.card-actions {
    flex-direction: row;
    justify-content: flex-end;
    flex-wrap: wrap;
    border-bottom: none;
    padding-top: .5rem;
    gap: .5rem;
  }

  .card-table td.card-actions::before { display: none; }
  .card-table td.card-actions .btn { flex: 1; justify-content: center; min-width: 70px; }

  /* Hide explicitly hidden cells on mobile */
  .card-table td.card-hide { display: none; }

  /* Status badge — no label needed if obvious */
  .card-table td.card-status {
    justify-content: flex-end;
    border-bottom: none;
  }
  .card-table td.card-status::before { display: none; }
}

/* ===== DataTable Mobile ===== */

.dt-layout-row{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:1rem;
    flex-wrap:wrap;
}

.dt-layout-cell{
    flex:1;
}

.dt-search{
    width:100%;
}

.dt-search input{
    width:100%;
    min-width:220px;
}

.dt-length select{
    min-width:90px;
}

.dt-buttons{
    display:flex;
    flex-wrap:wrap;
    gap:.5rem;
}

.dt-buttons .btn,
.dt-button{
    margin:0 !important;
}

@media (max-width:768px){

    .page-header{
        display:flex;
        flex-direction:column;
        align-items:stretch;
        gap:1rem;
    }

    .page-header-actions{
        width:100%;
    }

    .page-header-actions .btn{
        width:100%;
        justify-content:center;
    }

    .dt-layout-row{

        flex-direction:column;
        align-items:stretch;

    }

    .dt-layout-cell{

        width:100%;

    }

    .dt-search{

        width:100%;

    }

    .dt-search input{

        width:100%;

    }

    .dt-buttons{

        display:grid;
        grid-template-columns:repeat(2,1fr);
        gap:.5rem;

    }

    .dt-button{

        width:100%;
        text-align:center;

    }

    .dt-length{

        width:100%;

    }

    .dt-length select{

        width:100%;

    }

    .dt-info{

        text-align:center;

    }

    .dt-paging{

        display:flex;
        justify-content:center;
        overflow-x:auto;

    }

}