:root {
    --primary: #353783;
    --primary-2: #4f46e5;
    --primary-3: #7067ff;
    --accent: #10b4d8;
    --bg: #f4f6fb;
    --bg-2: #eef2ff;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-soft: rgba(255,255,255,.78);
    --text: #111827;
    --text-2: #26324b;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d8ddf0;
    --success: #0f766e;
    --success-bg: #e6fffb;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --warning: #b45309;
    --warning-bg: #fff7ed;
    --info-bg: #eef2ff;
    --shadow: 0 22px 55px rgba(24, 32, 51, .10);
    --shadow-soft: 0 12px 30px rgba(24, 32, 51, .065);
    --radius-xl: 28px;
    --radius-lg: 22px;
    --radius-md: 16px;
    --sidebar-width: 308px;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, .12), transparent 28rem),
        radial-gradient(circle at 90% 8%, rgba(16, 180, 216, .10), transparent 24rem),
        linear-gradient(180deg, #f8faff 0%, var(--bg) 50%, #f7f8fc 100%);
    color: var(--text);
}

a { color: inherit; }
img { max-width: 100%; }
::selection { background: rgba(79, 70, 229, .18); }

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(53,55,131,.96), rgba(79,70,229,.88)),
        radial-gradient(circle at 18% 12%, rgba(255,255,255,.24), transparent 22rem),
        radial-gradient(circle at 88% 88%, rgba(16,180,216,.24), transparent 24rem);
    overflow: hidden;
}
.login-page::before,
.login-page::after {
    content: '';
    position: fixed;
    width: 440px;
    height: 440px;
    border-radius: 999px;
    filter: blur(10px);
    opacity: .38;
    pointer-events: none;
}
.login-page::before { left: -130px; top: -130px; background: rgba(255,255,255,.20); }
.login-page::after { right: -160px; bottom: -160px; background: rgba(16,180,216,.24); }
.login-card {
    width: min(460px, 100%);
    position: relative;
    z-index: 1;
    background: rgba(255,255,255,.92);
    border: 1px solid rgba(255,255,255,.55);
    box-shadow: 0 38px 90px rgba(5, 12, 38, .28);
    border-radius: 34px;
    padding: 36px;
    backdrop-filter: blur(20px);
}
.login-card h1 { margin: 0 0 6px; font-size: clamp(30px, 5vw, 40px); letter-spacing: -.04em; }
.login-card p { margin-top: 0; color: var(--muted); }
.login-footnote {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 16px;
    background: #f8f9ff;
    border: 1px solid #e4e7ff;
}

/* Layout */
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
}
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px;
    background: linear-gradient(180deg, #101332 0%, #161a46 48%, #11152f 100%);
    color: #e9ecff;
    overflow: hidden;
    border-right: 1px solid rgba(255,255,255,.08);
}
.sidebar::before {
    content: '';
    position: absolute;
    inset: -25% -40% auto auto;
    width: 300px;
    height: 300px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(112,103,255,.36), transparent 70%);
    pointer-events: none;
}
.sidebar-inner {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding-right: 3px;
    scrollbar-width: thin;
}
.sidebar-inner::-webkit-scrollbar { width: 7px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 999px; }
.brand {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 8px 8px 16px;
    text-decoration: none;
}
.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 18px;
    background: linear-gradient(135deg, #fff, #dfe3ff);
    color: var(--primary);
    font-weight: 950;
    letter-spacing: -.04em;
    box-shadow: 0 16px 28px rgba(0,0,0,.20);
}
.brand-copy strong { display: block; color: #fff; font-size: 18px; line-height: 1.1; }
.brand-copy span { display: block; color: rgba(233,236,255,.68); font-size: 12px; margin-top: 3px; }
.sidebar-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 4px 8px;
    padding: 12px;
    border-radius: 18px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.09);
}
.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 6px rgba(52,211,153,.12);
}
.sidebar-status strong { display: block; color: #fff; font-size: 13px; }
.sidebar-status small { display: block; color: rgba(233,236,255,.62); margin-top: 2px; }
.nav { display: grid; gap: 5px; }
.nav-section {
    margin: 14px 10px 6px;
    font-size: 10px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: rgba(233,236,255,.46);
    font-weight: 900;
}
.nav-link,
.nav-group summary,
.logout-link {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(233,236,255,.76);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 15px;
    font-weight: 750;
    font-size: 14px;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-link:hover,
.nav-group summary:hover,
.logout-link:hover {
    background: rgba(255,255,255,.10);
    color: #fff;
    transform: translateX(2px);
}
.nav-link.is-active {
    background: linear-gradient(135deg, rgba(255,255,255,.20), rgba(112,103,255,.24));
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.11);
}
.nav-icon {
    width: 23px;
    height: 23px;
    flex: 0 0 23px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: rgba(255,255,255,.09);
    color: #fff;
    font-size: 13px;
}
.nav-group { border-radius: 16px; }
.nav-group summary { list-style: none; }
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after {
    content: '⌄';
    margin-left: auto;
    color: rgba(233,236,255,.55);
    transition: transform .18s ease;
}
.nav-group[open] summary::after { transform: rotate(180deg); }
.nav-group[open] { background: rgba(0,0,0,.10); padding-bottom: 4px; }
.nav-group .nav-link {
    margin-left: 12px;
    padding-left: 12px;
    min-height: 38px;
    color: rgba(233,236,255,.68);
}
.logout-link {
    margin-top: auto;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.08);
}
.main {
    min-width: 0;
    padding: 24px;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin: -24px -24px 24px;
    padding: 18px 24px;
    background: rgba(246,248,253,.82);
    border-bottom: 1px solid rgba(229,231,235,.75);
    backdrop-filter: blur(18px);
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.sidebar-toggle {
    display: none;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--shadow-soft);
    color: var(--primary);
    font-weight: 900;
    cursor: pointer;
}
.user-pill {
    display: grid;
    justify-items: end;
    background: var(--surface-soft);
    border: 1px solid rgba(229,231,235,.85);
    border-radius: 18px;
    padding: 10px 15px;
    box-shadow: 0 10px 25px rgba(24,32,51,.045);
}
.user-pill span { font-weight: 850; }
.user-pill small { color: var(--muted); }

/* Generic UI */
.page-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}
.page-title h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1;
    letter-spacing: -.05em;
    color: #111827;
}
.page-title p { max-width: 780px; margin: 8px 0 0; color: var(--muted); line-height: 1.55; }
.page-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #eef2ff;
    color: var(--primary);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.hero-panel {
    position: relative;
    overflow: hidden;
    border-radius: 32px;
    padding: 28px;
    margin-bottom: 22px;
    background:
        linear-gradient(135deg, rgba(53,55,131,.98), rgba(79,70,229,.90)),
        radial-gradient(circle at 90% 20%, rgba(16,180,216,.28), transparent 24rem);
    color: #fff;
    box-shadow: 0 28px 60px rgba(53,55,131,.25);
}
.hero-panel::after {
    content: '';
    position: absolute;
    right: -80px;
    bottom: -100px;
    width: 280px;
    height: 280px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
}
.hero-panel > * { position: relative; z-index: 1; }
.hero-panel h1 { margin: 0; font-size: clamp(34px, 5vw, 56px); line-height: .95; letter-spacing: -.06em; }
.hero-panel p { max-width: 760px; margin: 12px 0 0; color: rgba(255,255,255,.76); line-height: 1.6; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
    background: var(--surface-soft);
    border: 1px solid rgba(229,231,235,.88);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 22px;
    backdrop-filter: blur(12px);
}
.card:hover { box-shadow: 0 18px 44px rgba(24,32,51,.085); }
.card h2, .card h3 { margin-top: 0; letter-spacing: -.02em; }
.card h2 { font-size: 22px; }
.card h3 { font-size: 18px; }
.card-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 12px;
}
.stat {
    position: relative;
    overflow: hidden;
    min-height: 132px;
    display: grid;
    align-content: space-between;
}
.stat::before {
    content: '';
    position: absolute;
    right: -48px;
    top: -48px;
    width: 118px;
    height: 118px;
    border-radius: 999px;
    background: rgba(79,70,229,.08);
}
.stat .number { position: relative; font-size: clamp(30px, 5vw, 44px); line-height: 1; font-weight: 950; color: var(--primary); letter-spacing: -.05em; }
.stat .label { position: relative; color: var(--muted); font-weight: 750; margin-top: 8px; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 8px; }
.stat.accent .number { color: var(--accent); }
.stat.success .number { color: var(--success); }
.stat.warning .number { color: var(--warning); }
.stat.danger .number { color: var(--danger); }
.kpi-strip { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
.workflow-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.workflow-card {
    display: grid;
    gap: 10px;
    text-decoration: none;
    border: 1px solid rgba(229,231,235,.9);
    border-radius: 22px;
    background: #fff;
    padding: 18px;
    min-height: 150px;
    box-shadow: var(--shadow-soft);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.workflow-card:hover { transform: translateY(-3px); border-color: rgba(79,70,229,.28); box-shadow: 0 18px 42px rgba(24,32,51,.11); }
.workflow-card .icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: #eef2ff;
    color: var(--primary);
    font-weight: 950;
}
.workflow-card strong { font-size: 17px; letter-spacing: -.02em; }
.workflow-card span { color: var(--muted); line-height: 1.45; font-size: 13px; }
.progress-pill {
    height: 10px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}
.progress-pill span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--accent)); }

/* Forms */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-full { grid-column: 1 / -1; }
label { display: block; font-size: 12px; color: #4b5563; font-weight: 850; margin-bottom: 7px; letter-spacing: .01em; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 15px;
    padding: 12px 13px;
    outline: none;
    font: inherit;
    color: var(--text);
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary-2); box-shadow: 0 0 0 4px rgba(79,70,229,.12); background: #fff; }
input[type="file"] { padding: 10px; background: #fff; }
.btn {
    border: 0;
    border-radius: 15px;
    padding: 12px 17px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-weight: 850;
    box-shadow: 0 16px 28px rgba(53,55,131,.22);
    transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}
.btn:hover { filter: brightness(1.04); transform: translateY(-1px); box-shadow: 0 20px 34px rgba(53,55,131,.26); }
.btn:active { transform: translateY(0); }
.btn-secondary { background: #eef2ff; color: var(--primary); box-shadow: inset 0 0 0 1px #dfe3ff; }
.btn-secondary:hover { box-shadow: inset 0 0 0 1px #cfd5ff, 0 12px 24px rgba(53,55,131,.09); }
.btn-danger { background: linear-gradient(135deg, #dc2626, #b91c1c); color: #fff; box-shadow: 0 14px 24px rgba(239, 68, 68, .20); }
.actions { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

/* Tables */
.table-wrap {
    overflow: auto;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: #fff;
}
.table-wrap table { margin: 0; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 14px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 11px;
    color: #667085;
    background: #f8faff;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 950;
}
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: #fbfcff; }
tbody tr:last-child td { border-bottom: 0; }
.table-wrap form { margin: 0; }

/* Badges and alerts */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 12px;
    font-weight: 900;
    background: #eef2ff;
    color: var(--primary);
    white-space: nowrap;
}
.badge-success, .badge.badge-success { background: #dcfce7; color: #166534; }
.badge-warning, .badge.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger, .badge.badge-danger { background: #fee2e2; color: #991b1b; }
.alert {
    border-radius: 18px;
    padding: 14px 16px;
    margin-bottom: 16px;
    background: #eef2ff;
    border: 1px solid #dfe3ff;
    color: #29306f;
    box-shadow: 0 12px 24px rgba(24,32,51,.045);
}
.alert-success { background: #ecfdf5; border-color: #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty-state {
    background: linear-gradient(180deg, #fbfcff, #f8fafc);
    border: 1px dashed var(--border-strong);
    border-radius: 20px;
    padding: 22px;
    color: var(--muted);
}

/* Module-specific */
.mini-stat { box-shadow: none; padding: 16px; }
.mini-stat .number { font-size: 26px; }
.card .page-title h2 { font-size: 22px; }
.table-wrap a.small { color: var(--primary); font-weight: 800; }
.photo-upload-form,
.material-add-form,
.checklist-item-form,
.checklist-apply-form,
.qaqc-form,
.qaqc-form-card,
.test-upload-form,
.parameter-form,
.parameter-rule-form,
.parameter-eval-form {
    background: linear-gradient(180deg, #fbfcff, #f8f9ff);
    border: 1px dashed #cfd5ff;
    border-radius: 20px;
    padding: 17px;
}
.qaqc-form-card .qaqc-form { background: transparent; border: 0; padding: 0; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.photo-card {
    border: 1px solid var(--border);
    border-radius: 22px;
    background: #fff;
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}
.photo-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #eef2ff; }
.photo-card-body { padding: 14px; }
.photo-card-body p { margin: 9px 0 0; }
.checklist-answer-list { display: grid; gap: 14px; }
.checklist-answer-item { border: 1px solid var(--border); border-radius: 20px; padding: 16px; background: #fff; box-shadow: 0 10px 22px rgba(24,32,51,.045); }
.checklist-answer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.map-card { padding-bottom: 18px; }
.fiberlynx-map {
    width: 100%;
    min-height: 590px;
    border: 1px solid var(--border);
    border-radius: 26px;
    overflow: hidden;
    background: #eef2ff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.75);
}
.map-popup { min-width: 220px; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.4; }
.map-popup a { display: inline-flex; margin-top: 8px; font-weight: 900; color: var(--primary); }
.leaflet-container { font: inherit; }
.test-file-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 999px; padding: 7px 11px; background: #fff; font-weight: 900; color: var(--primary); }
.evaluation-summary { border: 1px solid var(--border); border-radius: 20px; padding: 16px; background: #fff; }
.evaluation-pass { background: #ecfdf5; border-color: #bbf7d0; }
.evaluation-warning { background: #fffbeb; border-color: #fde68a; }
.evaluation-fail { background: #fef2f2; border-color: #fecaca; }
.card.stat .number:empty::after { content: '0'; }

/* Responsive */
@media (max-width: 1180px) {
    .grid-4, .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .workflow-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(88vw, var(--sidebar-width));
        z-index: 80;
        transform: translateX(-104%);
        transition: transform .22s ease;
        box-shadow: 40px 0 80px rgba(0,0,0,.26);
    }
    .app-shell.sidebar-open .sidebar { transform: translateX(0); }
    .app-shell.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(8,12,31,.45);
        z-index: 70;
        backdrop-filter: blur(2px);
    }
    .main { padding: 18px; }
    .topbar { margin: -18px -18px 18px; padding: 14px 18px; }
    .sidebar-toggle { display: grid; place-items: center; }
    .grid-2, .grid-3, .grid-4, .form-grid, .kpi-strip, .workflow-grid { grid-template-columns: 1fr; }
    .topbar { align-items: center; }
    .user-pill { display: none; }
    .page-title { flex-direction: column; }
    .hero-panel { padding: 24px; border-radius: 26px; }
}
@media (max-width: 700px) {
    .photo-grid { grid-template-columns: 1fr; }
    .checklist-answer-head { flex-direction: column; }
    .fiberlynx-map { min-height: 430px; }
    .login-card { padding: 28px 22px; border-radius: 28px; }
    th, td { padding: 12px 11px; }
}
