@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap');

:root {
  --ink: #17324d;
  --muted: #64748b;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --mint: #e9f7f3;
  --gold: #fff4ce;
  --line: #dbe7e3;
  --bg: #f5faf8;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(27, 73, 63, .10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font-family: 'Cairo', Tahoma, Arial, sans-serif; line-height: 1.6; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; }
input, select { font-size: 16px; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

.topbar { min-height: 76px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: calc(14px + env(safe-area-inset-top)) max(18px, calc((100vw - 1100px) / 2)) 14px; position: sticky; top: 0; z-index: 5; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; background: var(--teal); color: white; display: grid; place-items: center; font-weight: 800; font-size: 24px; box-shadow: 0 7px 14px rgba(15, 118, 110, .22); }
.topbar h1 { font-size: 20px; }
.eyebrow { font-size: 11px; color: var(--teal); font-weight: 800; letter-spacing: .06em; }
.icon-btn { margin-right: auto; border: 0; background: var(--mint); color: var(--teal); border-radius: 12px; width: 42px; height: 42px; font-size: 25px; }
.ios-tip { max-width: 1100px; margin: 12px auto 0; padding: 10px 15px; border-radius: 13px; background: #fff4ce; color: #755719; border: 1px solid #f0d98b; font-size: 12px; font-weight: 700; }

.app-shell { max-width: 1100px; margin: 0 auto; padding: 24px 18px 50px; }
.hero-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 24px; border-radius: 26px; background: linear-gradient(120deg, #0f766e, #0d9488); color: white; box-shadow: var(--shadow); margin-bottom: 18px; }
.hero-card h2 { font-size: 24px; margin: 8px 0 5px; }
.hero-card p { opacity: .86; max-width: 650px; font-size: 14px; }
.hero-icon { font-size: 60px; opacity: .75; }
.pill { display: inline-block; border: 1px solid rgba(255,255,255,.35); border-radius: 999px; padding: 3px 10px; font-size: 11px; }

.selector-card { background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 17px; display: grid; grid-template-columns: 1fr 1fr auto; gap: 14px; align-items: end; box-shadow: 0 8px 24px rgba(27,73,63,.05); }
.field-block label, .student-name-label { display: block; font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 5px; }
.field-block select, .field-block input, .student-name-input { width: 100%; background: #fbfefd; border: 1px solid #cfe0db; border-radius: 12px; padding: 11px 12px; color: var(--ink); outline: none; }
.field-block select:focus, .field-block input:focus, .student-name-input:focus, .score-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.custom-subject-field { grid-column: 1 / -1; }
.text-btn { border: 0; background: transparent; color: var(--teal); font-weight: 800; padding: 10px 4px; white-space: nowrap; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
.stat-card { background: #fff; border: 1px solid var(--line); padding: 15px 17px; border-radius: 18px; }
.stat-card span { font-size: 12px; color: var(--muted); }
.stat-card strong { display: block; color: var(--teal-dark); font-size: 25px; line-height: 1.3; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px 0 12px; }
.search-wrap { background: white; border: 1px solid var(--line); border-radius: 14px; display: flex; align-items: center; gap: 7px; padding: 0 12px; flex: 1; max-width: 390px; color: var(--muted); }
.search-wrap input { border: 0; outline: 0; padding: 11px 4px; width: 100%; background: transparent; }
.toolbar-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.primary-btn, .secondary-btn, .danger-btn { border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 800; min-height: 44px; }
.primary-btn { background: var(--teal); color: #fff; box-shadow: 0 5px 13px rgba(15,118,110,.18); }
.primary-btn:hover { background: var(--teal-dark); }
.secondary-btn { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.danger-btn { background: #fff0ef; color: var(--danger); }
.notice { min-height: 25px; color: var(--teal-dark); font-size: 12px; font-weight: 700; }
.notice.error { color: var(--danger); }

.student-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.student-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 17px; padding: 14px 15px; }
.student-card:hover { border-color: #9bc9bf; box-shadow: 0 8px 20px rgba(27,73,63,.07); }
.student-main { min-width: 0; }
.student-index { color: var(--teal); font-size: 11px; font-weight: 800; }
.student-name { font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.student-meta { font-size: 11px; color: var(--muted); }
.student-score { text-align: left; white-space: nowrap; }
.annual-score { display: block; color: var(--teal-dark); font-size: 19px; font-weight: 800; }
.status { font-size: 10px; border-radius: 999px; padding: 2px 7px; background: #edf4f1; color: var(--muted); }
.status.pass { background: #dff5e9; color: #137044; }
.status.follow { background: #fff0df; color: #a85d00; }
.edit-btn { border: 0; background: var(--mint); color: var(--teal); border-radius: 10px; padding: 9px; font-weight: 800; }
.empty-state { text-align: center; padding: 46px 18px; border: 1px dashed #b8d6cf; border-radius: 20px; margin-top: 12px; background: #fbfefd; }
.empty-icon { margin: auto auto 10px; width: 48px; height: 48px; border-radius: 16px; background: var(--mint); color: var(--teal); display: grid; place-items: center; font-size: 27px; }
.empty-state h3 { font-size: 16px; }
.empty-state p { font-size: 13px; color: var(--muted); margin: 4px 0 15px; }
.formula-card { margin-top: 22px; background: #eef8f5; border: 1px solid #cde8df; border-radius: 18px; padding: 15px 17px; }
.formula-card h3 { font-size: 14px; color: var(--teal-dark); margin-bottom: 4px; }
.formula-card p { font-size: 12px; color: #47645e; }
footer { text-align: center; color: var(--muted); font-size: 11px; padding: 0 18px 24px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15,34,39,.56); z-index: 20; display: grid; place-items: end center; padding: 12px; }
.modal-card { width: min(760px, 100%); max-height: 94vh; overflow: auto; background: #fff; border-radius: 24px; padding: 20px; box-shadow: 0 25px 80px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.modal-head h2 { font-size: 22px; }
.close-btn { border: 0; background: #f1f5f4; color: var(--muted); border-radius: 12px; width: 38px; height: 38px; font-size: 25px; }
.student-name-input { font-size: 16px; margin-bottom: 17px; }
.term-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.term-panel { border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #fbfefd; }
.term-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.term-title h3 { font-size: 15px; }
.term-title span, .annual-result strong { background: var(--mint); color: var(--teal-dark); border-radius: 9px; padding: 3px 8px; font-weight: 800; }
.score-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.score-grid label, .month-row label, .midyear-row label { font-size: 11px; color: var(--muted); font-weight: 700; }
.score-input { display: block; width: 100%; border: 1px solid #dfd6a6; background: var(--gold); border-radius: 10px; padding: 9px 7px; margin-top: 4px; text-align: center; outline: none; }
.computed-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; background: var(--mint); border-radius: 10px; padding: 7px 9px; font-size: 12px; }
.computed-row strong { color: var(--teal-dark); }
.month-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.midyear-row { display: flex; align-items: end; gap: 12px; margin-top: 12px; padding: 12px; background: #f9f8f0; border-radius: 14px; }
.midyear-row label { max-width: 180px; flex: 1; }
.annual-result { margin-right: auto; text-align: left; }
.annual-result span { display: block; font-size: 11px; color: var(--muted); }
.annual-result strong { font-size: 20px; display: inline-block; margin-top: 3px; }
.modal-hint { font-size: 11px; color: var(--muted); margin: 12px 0; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.modal-actions > div { display: flex; gap: 7px; }
.bulk-help { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.bulk-textarea { width: 100%; resize: vertical; min-height: 190px; border: 1px solid #cfe0db; border-radius: 14px; padding: 12px; outline: none; line-height: 2; color: var(--ink); background: #fbfefd; }
.bulk-textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
.bulk-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 12px; font-weight: 700; }
.bulk-actions > div { display: flex; gap: 7px; }

@media (max-width: 700px) {
  .topbar { padding-left: 14px; padding-right: 14px; }
  .ios-tip { margin: 10px 12px 0; }
  .app-shell { padding: 15px 12px calc(40px + env(safe-area-inset-bottom)); }
  .hero-card { padding: 19px; border-radius: 20px; }
  .hero-card h2 { font-size: 20px; }
  .hero-icon { font-size: 45px; }
  .selector-card { grid-template-columns: 1fr 1fr; padding: 14px; }
  .custom-subject-field { grid-column: 1 / -1; }
  .text-btn { grid-column: 1 / -1; text-align: right; }
  .stats-grid { gap: 7px; }
  .stat-card { padding: 11px 10px; }
  .stat-card span { font-size: 10px; }
  .stat-card strong { font-size: 21px; }
  .toolbar { display: block; margin-top: 14px; }
  .search-wrap { max-width: none; margin-bottom: 9px; }
  .toolbar-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
  .toolbar-actions #addStudentBtn, .toolbar-actions #bulkAddBtn { grid-column: span 2; }
  .toolbar-actions button { width: 100%; font-size: 11px; padding-inline: 5px; }
  .student-list { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .modal-card { padding: 16px; border-radius: 22px; }
  .term-grid { grid-template-columns: 1fr; }
  .midyear-row { align-items: stretch; flex-direction: column; }
  .midyear-row label { max-width: none; }
  .annual-result { margin-right: 0; text-align: right; }
  .modal-actions { align-items: stretch; flex-direction: column; }
  .modal-actions > div { width: 100%; }
  .modal-actions button { flex: 1; }
  .danger-btn { width: 100%; }
}

@media print {
  .topbar, .ios-tip, .hero-card, .selector-card, .toolbar, .formula-card, footer, .notice, .edit-btn { display: none !important; }
  .app-shell { padding: 0; }
  .stats-grid { margin: 0 0 10px; }
  .student-list { grid-template-columns: 1fr 1fr; }
  .student-card { break-inside: avoid; box-shadow: none; }
}
