/* Madrasah website: shared styles.
   Page-specific styles (Home, results, dashboards, ...) are written inside each page. */

:root { --primary: #1e5aa8; --accent: #f4a300; --text: #222; --bg: #f7f9fc; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; color: var(--text); background: var(--bg); line-height: 1.6; }
.container { width: min(1100px, 92%); margin-inline: auto; padding: 1.5rem 0; }

/* ---------- header and menu ---------- */
.site-header { background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 10; }
.nav { display: flex; justify-content: space-between; align-items: center; }
.nav a { color: #fff; text-decoration: none; margin-left: 1rem; }
.logo { font-weight: 600; }
.logo img { height: 40px; vertical-align: middle; margin-right: .5rem; }
#menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.6rem; }

/* log in / sign up / log out buttons */
.nav-auth { display: inline-flex; align-items: center; gap: .5rem; margin-left: 1rem; }
.nav-user { font-size: .9rem; opacity: .9; }
.nav .btn { padding: .4rem .9rem; border-radius: 6px; margin-left: 0; font-weight: 600; }
.nav .btn-outline { border: 1px solid #fff; }
.nav .btn-accent { background: var(--accent); color: #222; }

/* Teachers drop-down (admin) */
.dropdown { position: relative; display: inline-block; margin-left: 1rem; }
.dropdown > a { margin-left: 0; }
.dropdown-menu {
  display: none; position: absolute; top: 100%; left: 0; min-width: 170px;
  background: #fff; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.15);
  overflow: hidden; z-index: 20;
}
.dropdown-menu a { display: block; color: var(--text); margin: 0; padding: .6rem 1rem; }
.dropdown-menu a:hover { background: var(--bg); }
.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu { display: block; }

/* ---------- cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.2rem; }
.card { background: #fff; padding: 1rem; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* ---------- forms and messages ---------- */
.form { max-width: 500px; background: #fff; padding: 1.2rem; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.form label { display: block; margin-top: 1rem; font-weight: 600; }
.form input[type=text], .form input[type=password], .form input[type=file],
.form input[type=date], .form input[type=number], .form select, .form textarea {
  width: 100%; padding: .6rem; margin-top: .3rem; border: 1px solid #ccd; border-radius: 6px;
  background: #fff; font-family: inherit; font-size: 1rem;
}
.form button { margin-top: 1.2rem; padding: .7rem 1.4rem; background: var(--primary); color: #fff; border: 0; border-radius: 6px; cursor: pointer; }
.form button:disabled { background: #aab3bf; cursor: not-allowed; }

.alert { padding: .8rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.alert ul { padding-left: 1.2rem; }
.alert.success { background: #e6f6ea; color: #17692f; }
.alert.error { background: #fdeaea; color: #8a1f1f; }

/* ---------- admin dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { text-align: center; }
.stat strong { display: block; font-size: 1.8rem; color: var(--primary); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; }
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid #e6eaf0; }
.table th { background: #eef2f8; }
.actions a { margin-right: .8rem; }
.link-danger { background: none; border: 0; color: #b42318; cursor: pointer; font: inherit; padding: 0; }
.thumb { width: 56px; height: 40px; object-fit: cover; border-radius: 4px; display: block; }

/* ---------- footer ---------- */
.site-footer { margin-top: 2rem; color: #555; }

/* ---------- all screens: nothing may be wider than the screen ---------- */
img { max-width: 100%; }
input, select, textarea, button { max-width: 100%; font-family: inherit; }
h1 { font-size: clamp(1.5rem, 5vw, 2rem); }
h2 { font-size: clamp(1.2rem, 4vw, 1.5rem); }
.table-wrap, [class$="-wrap"] { -webkit-overflow-scrolling: touch; }   /* smooth side-scroll of wide tables */

/* ---------- tablets and phones ---------- */
@media (max-width: 900px) {
  .container { width: 94%; }
}

/* ---------- phones ---------- */
@media (max-width: 700px) {
  .container { padding: 1rem 0; }
  .site-header .container { padding: .6rem 0; }
  .logo { font-size: 1.05rem; max-width: 75%; }

  /* menu: a button opens a full-width list with easy-to-tap links */
  #menu-toggle { display: block; padding: .3rem .7rem; cursor: pointer; }
  .nav { flex-wrap: wrap; }
  #menu { display: none; flex-direction: column; width: 100%; padding: .4rem 0 .8rem; }
  #menu.open { display: flex; }
  .nav a { margin: 0; padding: .7rem .2rem; min-height: 44px; display: flex; align-items: center; }

  .nav-auth { margin-left: 0; margin-top: .4rem; flex-direction: column; align-items: stretch; width: 100%; gap: .5rem; }
  .nav .btn { justify-content: center; text-align: center; padding: .7rem .9rem; }
  .nav-user { padding: .3rem .2rem; }

  .dropdown { margin-left: 0; width: 100%; }
  .dropdown > a { margin-left: 0; }
  .dropdown-menu { position: static; box-shadow: none; background: rgba(255,255,255,.12); border-radius: 0; }
  .dropdown-menu a { color: #fff; padding-left: 1.2rem; }
  .dropdown:hover .dropdown-menu,
  .dropdown:focus-within .dropdown-menu { display: none; }
  .dropdown.open .dropdown-menu { display: block; }

  /* forms and cards use the whole width */
  .form { max-width: 100%; padding: 1rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }

  /* wide tables become cards: every cell shows its column name (main.js adds the names) */
  table.stack { background: transparent; box-shadow: none; border-radius: 0; }
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.08); margin-bottom: .8rem; overflow: hidden; }
  table.stack td { position: relative; padding: .55rem .8rem .55rem 42%; min-height: 2.4rem; text-align: left;
                   white-space: normal; border-bottom: 1px solid #eef1f6; word-break: break-word; }
  table.stack td::before { content: attr(data-label); position: absolute; left: .8rem; top: .55rem; width: 36%;
                           font-weight: 600; color: #555; font-size: .85rem; }
  table.stack td[data-label=""] { padding-left: .8rem; }
  table.stack td[data-label=""]::before { content: none; }
  table.stack td:last-child { border-bottom: 0; }
}