/* DigiKunal styles */
:root {
    --primary: #1a237e;
    --primary-light: #3949ab;
    --accent: #6a1b9a;
    --green: #1b5e20;
    --bg: #f1f4f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --danger: #dc2626;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* ---------- Buttons ---------- */
.btn-primary, .btn-green, .btn-outline {
    border: none; border-radius: 8px; cursor: pointer; font-weight: 600;
    font-size: 0.9rem; padding: 0.6rem 1.2rem; transition: opacity .15s, transform .05s;
    display: inline-flex; align-items: center; gap: 0.5rem;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-green { background: #16a34a; color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-primary:hover, .btn-green:hover { opacity: .9; }
.btn-primary:active, .btn-green:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; }

.form-control {
    width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border);
    border-radius: 8px; font-size: 0.9rem; font-family: inherit; background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(57,73,171,.12); }
label { font-weight: 600; font-size: 0.85rem; display: block; margin-bottom: 0.35rem; }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem;
    background: linear-gradient(135deg, #1a237e 0%, #6a1b9a 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 420px;
    box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .brand { font-size: 1.8rem; font-weight: 800; color: var(--primary); letter-spacing: -.5px; }
.login-logo .brand span { color: var(--accent); }
.login-logo p { color: var(--text-secondary); font-size: 0.85rem; margin-top: 0.25rem; }
.login-form-title { font-size: 1.1rem; margin-bottom: 1.25rem; text-align: center; }
.form-group { margin-bottom: 1.1rem; }
.error-text { color: var(--danger); font-size: 0.8rem; margin-top: 0.35rem; display: none; }
.login-hint { margin-top: 1.25rem; font-size: 0.78rem; color: var(--text-secondary); text-align: center; }

/* ---------- App shell ---------- */
.app-header { background: var(--primary); color: #fff; padding: 0.9rem 1.5rem; display: flex;
    align-items: center; justify-content: space-between; }
.app-header .brand { font-weight: 800; font-size: 1.25rem; }
.app-header .brand span { color: #b388ff; }
.logout-btn { background: rgba(255,255,255,.15); color: #fff; border: none; padding: 0.5rem 1rem;
    border-radius: 8px; cursor: pointer; font-weight: 600; display: inline-flex; gap: 0.5rem; align-items: center; }
.container { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; }
.card-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; display: flex; gap: 0.5rem; align-items: center; color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.badge { padding: 0.25rem 0.7rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.badge.cbse { background: #e3f2fd; color: #1565c0; }
.badge.cisce { background: #f3e5f5; color: #6a1b9a; }
.badge.connected { background: #dcfce7; color: #166534; }
.badge.disconnected { background: #fef3c7; color: #92400e; }

table.admin-table { width: 100%; border-collapse: collapse; }
table.admin-table th, table.admin-table td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
table.admin-table th { background: #f8fafc; font-weight: 700; color: var(--text-secondary); }
table.admin-table tr:hover td { background: #f8fafc; }

/* collapsible supabase config */
.config-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }

/* photo */
.photo-box { width: 110px; height: 130px; border: 2px dashed var(--border); border-radius: 8px;
    display: flex; align-items: center; justify-content: center; overflow: hidden; background: #f8fafc; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }

/* modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none;
    align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; z-index: 50; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 760px; padding: 1.75rem; }
.modal h3 { margin-bottom: 1.25rem; color: var(--primary); }

/* toast */
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: #fff; border-radius: 10px;
    padding: 0.9rem 1.2rem; box-shadow: 0 10px 30px rgba(0,0,0,.2); display: none; align-items: center;
    gap: 0.6rem; font-weight: 600; font-size: 0.88rem; z-index: 80; border-left: 4px solid #16a34a; }
.toast.show { display: flex; }
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-error i { color: var(--danger); }
.toast.toast-success i { color: #16a34a; }

/* subject editor table */
.subj-table { width: 100%; border-collapse: collapse; margin-top: 0.5rem; }
.subj-table th, .subj-table td { border: 1px solid var(--border); padding: 0.3rem; font-size: 0.8rem; }
.subj-table input { width: 100%; border: none; padding: 0.3rem; font-size: 0.8rem; }
.subj-table input:focus { outline: 2px solid var(--primary-light); border-radius: 4px; }

/* =================== CERTIFICATE RENDERING =================== */
.cert-wrap { background: #fff; max-width: 850px; margin: 0 auto; padding: 2rem; border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,.08); }

/* CBSE */
.cbse-wrap {
    border: 1px solid #8ba569;
    outline: 2px solid #8ba569;
    outline-offset: -6px;
    padding: 2rem;
    background: #fff;
    max-width: 820px;
    margin: 0 auto;
    box-shadow: 0 4px 18px rgba(0,0,0,.08);
    position: relative;
    box-sizing: border-box;
}
.cbse-head {
    text-align: center;
    margin-bottom: 1.25rem;
}
.cbse-head .logo {
    width: 90px;
    height: 90px;
    object-fit: contain;
    margin: 0 auto 0.4rem;
    display: block;
}
.cbse-head h1 {
    color: #0b328a;
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 0.15rem;
}
.cbse-head h2 {
    color: #0b328a;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.15rem;
}
.cbse-head h3 {
    color: #0b328a;
    font-size: 0.95rem;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 0.15rem;
}
.cbse-info {
    margin-top: 1.25rem;
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
}
.cbse-details {
    flex: 1;
}
.info-line {
    margin-bottom: 0.45rem;
    font-size: 0.82rem;
    color: #1e293b;
    line-height: 1.4;
}
.info-label {
    font-weight: 700;
    color: #1e293b;
    margin-right: 0.5rem;
}
.info-value {
    font-weight: 700;
    color: #0f172a;
}
.info-value.name-value {
    font-size: 0.9rem;
    text-transform: uppercase;
}
.cbse-photo-container {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.cbse-photo {
    width: 95px;
    height: 110px;
    border: 1px solid #64748b;
    object-fit: cover;
}
.photo-date {
    font-size: 0.55rem;
    color: #64748b;
    margin-top: 0.15rem;
}
.cbse-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    border: 1px solid #64748b;
}
.cbse-table th, .cbse-table td {
    border: 1px solid #64748b;
    padding: 0.45rem 0.5rem;
    font-size: 0.72rem;
    text-align: center;
    vertical-align: middle;
}
.cbse-table th {
    background: #f1f5f9;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.2;
}
.cbse-table td {
    color: #0f172a;
    font-weight: 600;
}
.cbse-table td.subj-name {
    text-align: left;
}
.cbse-table td.text-left {
    text-align: left;
}
.cbse-result-bar {
    border: 1px solid #64748b;
    border-top: none;
    padding: 0.5rem 0.75rem;
    font-weight: 700;
    font-size: 0.8rem;
    background-color: #f1f5f9;
    color: #0f172a;
}
.cbse-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
    gap: 1rem;
}
.footer-qr-sec {
    flex-shrink: 0;
}
.footer-qr-sec .qr-box {
    width: 95px;
    height: 95px;
    display: block;
}
.footer-badge-sec {
    flex-shrink: 0;
}
.dl-badge-img {
    width: 150px;
    height: auto;
    display: block;
    object-fit: contain;
}
.footer-sign-sec {
    flex-shrink: 0;
}
.cbse-signature-box {
    border: 1px solid #000;
    width: 240px;
    height: 80px;
    position: relative;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'><line x1='0' y1='0' x2='100%' y2='100%' stroke='%23cbd5e1' stroke-width='1'/><line x1='0' y1='100%' x2='100%' y2='0' stroke='%23cbd5e1' stroke-width='1'/></svg>");
    background-size: 100% 100%;
    padding: 0.5rem;
    box-sizing: border-box;
}
.sig-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    position: relative;
    z-index: 2;
}
.sig-text {
    font-size: 0.55rem;
    line-height: 1.3;
    color: #1e293b;
    font-weight: 500;
}
.sig-tick {
    flex-shrink: 0;
    margin-left: 0.25rem;
}
.cbse-meta-row {
    margin-top: 1.25rem;
    font-size: 0.8rem;
    color: #1e293b;
    display: flex;
    justify-content: space-between;
}
.cbse-place-date .place {
    font-weight: 700;
}
.cbse-place-date .decl-date {
    margin-top: 0.25rem;
}
.cbse-note-box {
    margin-top: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 0.68rem;
    color: #475569;
    line-height: 1.4;
}
.cbse-note-box b {
    color: var(--text);
}
.cbse-note-box ol {
    margin-left: 1.1rem;
    margin-top: 0.25rem;
}
.cbse-note-box li {
    margin-bottom: 0.35rem;
}
.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.25rem 1rem;
    margin-top: 0.35rem;
    font-size: 0.62rem;
    color: #64748b;
}

@media (max-width: 680px) {
    .cbse-wrap {
        padding: 1rem;
        outline-offset: -3px;
    }
    .cbse-info {
        flex-direction: column-reverse;
        align-items: center;
        gap: 1rem;
    }
    .cbse-photo-container {
        margin-bottom: 0.5rem;
    }
    .cbse-footer-row {
        flex-direction: column;
        align-items: center;
        gap: 1.25rem;
        text-align: center;
    }
    .cbse-signature-box {
        width: 240px;
    }
    .cbse-meta-row {
        flex-direction: column;
        gap: 0.5rem;
    }
    .legend-grid {
        grid-template-columns: 1fr 1fr;
    }
}
@media (max-width: 480px) {
    .legend-grid {
        grid-template-columns: 1fr;
    }
}

/* CISCE */
.cisce-wrap {
    border: 1px solid #d1d5db;
    padding: 2rem;
    background: #fff;
    max-width: 820px;
    margin: 0 auto;
    box-shadow: 0 4px 18px rgba(0,0,0,.08);
    position: relative;
    box-sizing: border-box;
}
.cisce-head {
    text-align: center;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.cisce-head .logo {
    width: 85px;
    height: 85px;
    object-fit: contain;
    margin-bottom: 0.5rem;
}
.cisce-head h1 {
    font-size: 1.15rem;
    font-weight: 800;
    color: #111;
    line-height: 1.3;
}
.cisce-head h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #374151;
    margin-top: 0.15rem;
}
.cisce-head h3 {
    font-size: 0.95rem;
    font-weight: 800;
    color: #4b5563;
    margin-top: 0.15rem;
}
.cisce-info {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    margin-top: 1.25rem;
}
.cisce-info .row {
    font-size: 0.85rem;
    margin-bottom: 0.45rem;
    color: #1f2937;
}
.cisce-info .row b {
    display: inline-block;
    min-width: 110px;
    font-weight: 700;
}
.cisce-photo {
    width: 95px;
    height: 110px;
    border: 1px solid #9ca3af;
    object-fit: cover;
}
.cisce-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.25rem;
    border: 1px solid #64748b;
}
.cisce-table th, .cisce-table td {
    border: 1px solid #64748b;
    padding: 0.5rem 0.6rem;
    font-size: 0.78rem;
    text-align: center;
    vertical-align: middle;
}
.cisce-table th {
    background: #f1f5f9;
    font-weight: 700;
    color: #1e293b;
}
.cisce-table td {
    color: #0f172a;
    font-weight: 600;
}
.cisce-table td.subj-name {
    text-align: left;
}
.cisce-result {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #0f172a;
}
.cisce-result b {
    font-weight: 800;
}
.cisce-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
    gap: 1rem;
}
.cisce-signature-box {
    border: 1px solid #000;
    width: 240px;
    height: 80px;
    position: relative;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100%' height='100%'><line x1='0' y1='0' x2='100%' y2='100%' stroke='%23cbd5e1' stroke-width='1'/><line x1='0' y1='100%' x2='100%' y2='0' stroke='%23cbd5e1' stroke-width='1'/></svg>");
    background-size: 100% 100%;
    padding: 0.5rem;
    box-sizing: border-box;
}
.cisce-meta-row {
    margin-top: 1.25rem;
    font-size: 0.8rem;
    color: #1e293b;
}
.cisce-place-date .place {
    font-weight: 700;
}
.cisce-place-date .decl-date {
    margin-top: 0.25rem;
}
.cisce-note-box {
    margin-top: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    font-size: 0.68rem;
    color: #475569;
    line-height: 1.4;
}
.cisce-note-box b {
    color: var(--text);
}
.cisce-note-box ol {
    margin-left: 1.1rem;
    margin-top: 0.25rem;
}
.cisce-note-box li {
    margin-bottom: 0.35rem;
}

@media (max-width: 680px) {
    .cisce-wrap {
        padding: 1rem;
    }
    .cisce-info {
        flex-direction: column-reverse;
        align-items: center;
        gap: 1rem;
    }
    .cisce-footer-row {
        flex-direction: column;
        align-items: center;
        gap: 1.25rem;
        text-align: center;
    }
    .cisce-signature-box {
        width: 240px;
    }
}
