/* ============================================================
   Bilas Veteran - Calibration Certificate System
   Global stylesheet - navy/blue professional theme
   ============================================================ */

:root {
    --navy: #0f2a4a;
    --navy-dark: #0a1d33;
    --blue: #1d5fa3;
    --blue-light: #eaf2fb;
    --accent: #2f7fd1;
    --border: #d3dde8;
    --text: #1e2b3a;
    --text-muted: #5a6b7d;
    --bg: #f4f7fb;
    --white: #ffffff;
    --danger: #c0392b;
    --danger-bg: #fbeae8;
    --success: #1e7e34;
    --radius: 6px;
}

* { box-sizing: border-box; }

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

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

/* ---------- Login page ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 100%);
}

.login-wrap { width: 100%; max-width: 380px; padding: 20px; }

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 36px 32px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.login-title {
    margin: 0 0 4px;
    color: var(--navy);
    font-size: 24px;
    text-align: center;
}

.login-subtitle {
    margin: 0 0 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ---------- Form basics ---------- */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 13px;
    color: var(--navy);
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--white);
    color: var(--text);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47,127,209,0.15);
}

input[readonly], input[disabled], textarea[disabled] {
    background: #eef2f6;
    color: var(--text-muted);
}

textarea { resize: vertical; min-height: 70px; }

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--navy); text-decoration: none; }

.btn-secondary { background: var(--white); color: var(--blue); border: 1px solid var(--blue); }
.btn-secondary:hover { background: var(--blue-light); text-decoration: none; }

.btn-block { width: 100%; }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f1c3bd; }
.alert-success { background: #e7f6ea; color: var(--success); border: 1px solid #bfe6c8; }

/* ---------- App shell (logged in) ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    background: var(--navy);
    color: var(--white);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 22px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-brand h2 { margin: 0; font-size: 17px; }
.sidebar-brand span { font-size: 12px; color: #a9c2de; }

.sidebar-nav { flex: 1; padding: 14px 0; }

.sidebar-nav a {
    display: block;
    padding: 11px 20px;
    color: #d7e4f2;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.06);
    text-decoration: none;
}

.sidebar-nav a.active {
    background: rgba(255,255,255,0.1);
    border-left-color: var(--accent);
    color: var(--white);
    font-weight: 600;
}

.sidebar-nav a.disabled {
    color: #6d84a0;
    cursor: default;
}
.sidebar-nav a.disabled:hover { background: none; }

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar .user-info { font-size: 13px; color: var(--text-muted); }
.topbar .user-info strong { color: var(--navy); }
.topbar .role-badge {
    display: inline-block;
    background: var(--blue-light);
    color: var(--blue);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 600;
    margin-left: 6px;
}

.content { padding: 28px; flex: 1; }

.page-title {
    margin: 0 0 20px;
    color: var(--navy);
    font-size: 20px;
}

/* ---------- Dashboard cards ---------- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 8px;
}

.dash-card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: block;
}

.dash-card h3 {
    margin: 0 0 6px;
    color: var(--navy);
    font-size: 15px;
}

.dash-card p { margin: 0; color: var(--text-muted); font-size: 12.5px; }

.dash-card:not(.disabled):hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(29,95,163,0.12);
    text-decoration: none;
}

.dash-card.disabled { opacity: 0.55; cursor: default; }

/* ---------- Certificate form sections ---------- */
.cert-section {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.cert-section h2 {
    margin: 0 0 16px;
    font-size: 15px;
    color: var(--navy);
    border-bottom: 2px solid var(--blue-light);
    padding-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px 18px;
}

.form-grid .full-width { grid-column: 1 / -1; }

.cert-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.cert-table th, .cert-table td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    text-align: left;
}

.cert-table th {
    background: var(--blue-light);
    color: var(--navy);
    font-weight: 600;
    font-size: 12.5px;
}

.cert-table input {
    padding: 6px 8px;
    font-size: 13px;
}

.cert-table td.label-cell { background: #fafbfd; font-weight: 600; white-space: nowrap; }

.cert-table tr.energy-subhead td { background: var(--blue-light); font-weight: 600; }
.cert-table tr.energy-subhead select { width: auto; padding: 4px 8px; }

.hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
    font-weight: normal;
}

.footer-note {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
}

.footer-note .pass-line {
    font-weight: 700;
    color: var(--success);
    margin-bottom: 8px;
}

.sign-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 30px;
}

.sign-box {
    border-top: 1px solid var(--text);
    padding-top: 8px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 4px;
}

.readonly-preview {
    background: #eef2f6;
    font-weight: 600;
    color: var(--navy);
}

/* ---------- Mobile nav toggle (hidden on desktop) ---------- */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    margin-right: 12px;
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--navy);
    border-radius: 2px;
}

.nav-toggle span + span { margin-top: 4px; }

.nav-backdrop { display: none; }

/* ============================================================
   Responsive
   ============================================================ */

/* Wide data tables (history, users, the calibration grid) stay readable by
   scrolling sideways instead of squashing their columns. */
@media (max-width: 900px) {
    .cert-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .app-shell { display: block; overflow-x: hidden; max-width: 100%; }

    /* Flex/grid children default to min-content width, which lets a wide
       child (a table, a long value) stretch the whole shell sideways. */
    .main, .content { min-width: 0; max-width: 100%; }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -260px;
        width: 240px;
        z-index: 60;
        transition: left 0.2s ease;
        overflow-y: auto;
    }

    body.nav-open .sidebar { left: 0; }

    body.nav-open .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 55;
    }

    body.nav-open { overflow: hidden; }

    .nav-toggle { display: block; }

    .topbar {
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 20;
    }

    .topbar .user-info { flex: 1; min-width: 0; }

    .topbar .user-info strong {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar .role-badge { margin-left: 0; }

    .content { padding: 18px 16px; }

    .cert-section { padding: 16px 14px; }

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

    .sign-grid { grid-template-columns: 1fr; gap: 16px; margin-top: 18px; }

    .form-actions { flex-wrap: wrap; }

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

@media (max-width: 480px) {
    body { font-size: 13.5px; }

    .login-wrap { max-width: 100%; padding: 16px; }
    .login-card { padding: 26px 20px; }

    .page-title { font-size: 18px; }

    .content { padding: 14px 12px; }

    .cert-section { padding: 14px 12px; }

    /* Full-width tap targets for the primary actions. */
    .form-actions { flex-direction: column-reverse; }
    .form-actions .btn { width: 100%; }
}
