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

:root {
    --blue: #2457d6;
    --navy: #15233b;
    --bg: #f4f7fb;
    --line: #e4e9f1;
    --text: #1d2939;
    --muted: #667085
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Vazirmatn, Tahoma, sans-serif;
    font-size: 14px
}

a {
    color: var(--blue);
    text-decoration: none
}

h1 {
    font-size: 23px;
    margin: 8px 0 22px
}

h3 {
    margin: 0 0 16px;
    font-size: 17px
}

.topbar {
    height: 64px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 26px;
    position: sticky;
    top: 0;
    z-index: 5
}

.brand {
    font-size: 18px;
    font-weight: 800;
    color: var(--navy)
}

.logout {
    margin-right: 14px;
    color: #c0392b
}

.muted,
small {
    color: var(--muted)
}

.layout {
    display: flex;
    min-height: calc(100vh - 100px)
}

.sidebar {
    width: 230px;
    background: var(--navy);
    padding: 22px 14px;
    display: flex;
    flex-direction: column;
    gap: 7px
}

.sidebar a {
    color: #dbe5f7;
    padding: 12px 14px;
    border-radius: 9px
}

.sidebar a:hover {
    background: #263a5b
}

.content {
    flex: 1;
    padding: 28px;
    min-width: 0
}

.panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 22px;
    margin: 0 0 20px;
    box-shadow: 0 4px 18px #1d35570a
}

.panel form {
    max-width: 100%
}

label {
    display: block;
    font-weight: 600;
    margin: 12px 0 6px
}

input,
select {
    font: inherit;
    border: 1px solid #d0d7e2;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    width: 100%;
    min-height: 42px
}

input:focus,
select:focus {
    outline: 2px solid #c9d8ff;
    border-color: var(--blue)
}

.btn {
    display: inline-block;
    border: 0;
    background: var(--blue);
    color: #fff;
    padding: 10px 19px;
    border-radius: 9px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px
}

.btn:hover {
    filter: brightness(.95)
}

.btn.secondary {
    background: #edf2ff;
    color: var(--blue)
}

.notice {
    background: #eef5ff;
    border: 1px solid #c9dcff;
    color: #17469d;
    padding: 12px 15px;
    border-radius: 10px;
    margin-bottom: 18px
}

.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 15px;
    margin-bottom: 20px
}

.stat {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 7px
}

.stat strong {
    font-size: 27px;
    color: var(--blue)
}

.stat span {
    color: var(--muted)
}

.grade-card strong {
    font-size: 20px
}

.table-wrap {
    overflow: auto
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px
}

th,
td {
    text-align: right;
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap
}

th {
    background: #f8faff;
    font-weight: 700
}

tr:last-child td {
    border-bottom: 0
}

.inline {
    display: inline
}

.linkbtn {
    background: none;
    border: 0;
    color: #c0392b;
    font: inherit;
    cursor: pointer;
    margin-right: 8px
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 16px
}

.checks {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px
}

.checks label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 400
}

.checks input {
    width: auto;
    min-height: auto
}

.filter {
    display: flex;
    align-items: end;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px
}

.filter>div {
    min-width: 160px;
    flex: 1
}

.filter input,
.filter select {
    min-width: 150px
}

.attendance-list {
    display: flex;
    flex-direction: column;
    gap: 9px
}

.attendance-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 130px minmax(160px, 1fr);
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 10px
}

.student-name {
    display: flex;
    flex-direction: column;
    gap: 3px
}

.student-name small {
    font-size: 11px
}

.save-btn {
    position: sticky;
    bottom: 12px;
    box-shadow: 0 4px 16px #0002
}

.login-bg {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #eaf0ff, #f7f9fc)
}

.login-card {
    width: min(430px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 30px;
    box-shadow: 0 15px 50px #20345b18
}

.login-card h1 {
    text-align: center
}

.login-card p {
    color: var(--muted);
    line-height: 1.9
}

.login-card .btn {
    width: 100%
}

footer {
    text-align: center;
    padding: 18px;
    color: var(--muted);
    font-size: 12px
}

@media(max-width:850px) {
    .layout {
        display: block
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        overflow: auto;
        padding: 8px
    }

    .sidebar a {
        white-space: nowrap;
        padding: 9px 12px
    }

    .content {
        padding: 16px
    }

    .cards {
        grid-template-columns: repeat(2, minmax(0, 1fr))
    }

    .attendance-row {
        grid-template-columns: 1fr 115px
    }

    .attendance-row input {
        grid-column: 1/-1
    }

    .topbar {
        padding: 0 14px
    }
}

@media(max-width:520px) {
    .form-grid {
        grid-template-columns: 1fr
    }

    .cards {
        gap: 9px
    }

    .stat {
        padding: 14px
    }

    .topbar {
        font-size: 12px
    }

    .brand {
        font-size: 15px
    }

    .content {
        padding: 12px
    }

    .panel {
        padding: 15px
    }
}

.attendance-row {
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    flex-wrap: wrap
}

.attendance-row select,
.attendance-row input {
    min-width: 130px;
    flex: 1
}

.save-btn {
    margin-top: 18px;
    min-height: 48px
}

footer {
    text-align: center;
    padding: 18px;
    color: #667085
}

@media print {

    .topbar,
    .sidebar,
    .filter,
    .btn,
    .logout,
    button,
    footer {
        display: none !important
    }

    .layout {
        display: block !important
    }

    .content {
        padding: 0 !important
    }

    .panel {
        box-shadow: none !important;
        border: 0 !important
    }

    .table-wrap {
        overflow: visible !important
    }

    table {
        width: 100%;
        font-size: 11px
    }

    body {
        background: #fff !important
    }
}


.toast-message {
    position: fixed;
    top: 78px;
    left: 22px;
    z-index: 9999;
    max-width: min(440px, calc(100vw - 32px));
    padding: 13px 18px;
    border: 1px solid #b9d5ff;
    border-radius: 12px;
    background: #eff6ff;
    color: #17469d;
    box-shadow: 0 10px 30px #14294b24;
    animation: toast-in-out 3s ease forwards;
    pointer-events: none
}

@keyframes toast-in-out {
    0% {
        opacity: 0;
        transform: translateY(-14px)
    }

    10%,
    78% {
        opacity: 1;
        transform: translateY(0)
    }

    100% {
        opacity: 0;
        transform: translateY(-10px);
        visibility: hidden
    }
}

@media(max-width:520px) {
    .toast-message {
        top: 72px;
        left: 12px;
        right: 12px;
        max-width: none;
        text-align: center
    }
}
/* SMS settings dropdown and per-student send action */
.sidebar .nav-dropdown{display:block;color:inherit;margin:0;}
.sidebar .nav-dropdown summary{cursor:pointer;list-style:none;padding:12px 14px;border-radius:8px;color:inherit;}
.sidebar .nav-dropdown summary::-webkit-details-marker{display:none;}
.sidebar .nav-dropdown summary:after{content:'⌄';float:left;opacity:.8;}
.sidebar .nav-dropdown[open] summary:after{content:'⌃';}
.sidebar .nav-dropdown div{padding:2px 10px 8px 0;}
.sidebar .nav-dropdown div a{display:block;padding:9px 14px;font-size:.92em;opacity:.9;}
.sms-sent{color:#16834a;font-weight:700;}
.btn.small{padding:6px 10px;font-size:.85rem;}


/* Navigation dropdown and responsive collapsible sidebar */
.sidebar .nav-dropdown { display:block; width:100%; margin:0; color:inherit; }
.sidebar .nav-dropdown summary { display:block; cursor:pointer; list-style:none; padding:12px 14px; border-radius:9px; color:#dbe5f7; user-select:none; }
.sidebar .nav-dropdown summary:hover { background:#263a5b; }
.sidebar .nav-dropdown summary::-webkit-details-marker { display:none; }
.sidebar .nav-dropdown summary:after { content:'⌄'; float:left; opacity:.85; }
.sidebar .nav-dropdown[open] summary:after { content:'⌃'; }
.sidebar .nav-dropdown > div { padding:2px 10px 8px 0; }
.sidebar .nav-dropdown > div a { display:block; padding:9px 14px; font-size:.92em; color:#dbe5f7; }
.menu-toggle { display:none; border:1px solid var(--line); background:#fff; color:var(--navy); border-radius:8px; padding:7px 10px; font:inherit; cursor:pointer; }
@media(max-width:850px) {
  .topbar { gap:10px; }
  .menu-toggle { display:inline-flex; align-items:center; gap:7px; flex:0 0 auto; }
  .layout { display:flex; flex-direction:column; min-height:calc(100vh - 64px); }
  /* Mobile navigation drawer: opens from the RIGHT in RTL layout */
  .sidebar {
    display:none;
    position:fixed;
    top:64px;
    right:0;
    bottom:0;
    width:min(82vw, 300px);
    max-width:300px;
    height:calc(100dvh - 64px);
    flex-direction:column;
    overflow-x:hidden;
    overflow-y:auto;
    padding:14px 12px 24px;
    order:initial;
    z-index:20;
    box-shadow:-10px 0 28px rgba(15, 23, 42, .22);
    border-left:1px solid rgba(255,255,255,.08);
  }
  .sidebar.is-open { display:flex; }
  .sidebar a { white-space:normal; width:100%; flex:0 0 auto; }
  .sidebar .nav-dropdown summary { width:100%; }
  .sidebar .nav-dropdown > div a { white-space:normal; }
  .content { width:100%; }
}
@media(max-width:520px) {
  .topbar { min-height:64px; height:auto; padding:9px 12px; flex-wrap:wrap; }
  .topbar > div { margin-right:auto; }
  .menu-toggle { font-size:12px; padding:6px 8px; }
}

/* Mobile header refinement: keep school name, account and logout aligned */
.topbar { gap:18px; min-width:0; }
.topbar-main { display:flex; align-items:center; gap:12px; min-width:0; flex:1 1 auto; }
.topbar .brand { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.topbar-user { display:flex; align-items:center; justify-content:flex-end; gap:8px; flex:0 0 auto; white-space:nowrap; min-width:0; }
.topbar-user .user-name { overflow:hidden; text-overflow:ellipsis; max-width:190px; }
.topbar-user .user-role { white-space:nowrap; }
.topbar-user .logout { margin:0 6px 0 0; padding:6px 10px; border:1px solid #f1d5d2; border-radius:8px; flex:0 0 auto; }
@media (max-width:850px) {
  .topbar { height:auto; min-height:64px; padding:10px 14px; display:flex; flex-direction:column; align-items:stretch; justify-content:center; gap:9px; }
  .topbar-main { width:100%; flex-direction:row; justify-content:flex-start; }
  .topbar .brand { flex:1 1 auto; font-size:clamp(13px, 3.8vw, 17px); line-height:1.5; text-align:right; }
  .topbar-user { width:100%; justify-content:flex-start; padding:7px 2px 0; border-top:1px solid var(--line); font-size:12px; }
  .topbar-user .user-name { max-width:45vw; }
  .topbar-user .user-role { margin-right:2px; }
  .topbar-user .logout { margin-right:auto; }
  .menu-toggle { flex:0 0 auto; }
  .sidebar { top:0; height:100dvh; padding-top:max(18px, env(safe-area-inset-top)); }
}
@media (max-width:360px) {
  .topbar { padding:8px 10px; }
  .topbar-user .user-name { max-width:39vw; }
  .topbar .brand { font-size:13px; }
}

/* IPPanel API response floating modal */
.api-response-modal{display:none;position:fixed;inset:0;z-index:3000;align-items:center;justify-content:center;padding:18px;direction:rtl}
.api-response-modal.is-open{display:flex}
.api-response-backdrop{position:absolute;inset:0;background:rgba(15,23,42,.58);backdrop-filter:blur(3px)}
.api-response-dialog{position:relative;z-index:1;width:min(680px,100%);max-height:min(82vh,760px);overflow:hidden;display:flex;flex-direction:column;background:#fff;border:1px solid #e5e7eb;border-radius:18px;box-shadow:0 24px 80px rgba(0,0,0,.25)}
.api-response-head{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:18px 22px;border-bottom:1px solid #e5e7eb}
.api-response-head h2{font-size:17px;margin:0 0 5px;color:#172033}.api-response-head small{color:#64748b}
.api-response-close{width:36px;height:36px;border:0;border-radius:10px;background:#f1f5f9;font-size:25px;cursor:pointer;color:#334155;flex:none}
.api-response-content{padding:18px 22px;overflow:auto;min-height:0}.api-response-content p{font-weight:700;margin:0 0 10px;color:#334155}
.api-response-content pre{margin:0;padding:16px;border-radius:12px;background:#111827;color:#e5e7eb;direction:ltr;text-align:left;white-space:pre-wrap;overflow-wrap:anywhere;max-height:48vh;overflow:auto;font:13px/1.8 ui-monospace,SFMono-Regular,Consolas,monospace}
.api-response-actions{display:flex;justify-content:flex-start;gap:10px;padding:14px 22px;border-top:1px solid #e5e7eb;background:#f8fafc}
body.modal-open{overflow:hidden}
@media(max-width:600px){.api-response-modal{padding:10px;align-items:center}.api-response-dialog{width:100%;max-height:88vh;border-radius:15px}.api-response-head{padding:14px 16px}.api-response-content{padding:14px 16px}.api-response-actions{padding:12px 16px}.api-response-content pre{max-height:55vh;font-size:12px}}
