:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #062148;
    --muted: #58595b;
    --line: #d9e4ef;
    --primary: #0084DD;
    --primary-dark: #062148;
    --accent: #f05a30;
    --accent-soft: #fff3ee;
    --warning: #F1B000;
    --danger: #b42318;
    --warning-bg: #fff4d8;
    --shadow: 0 14px 34px rgba(6, 33, 72, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    letter-spacing: 0;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font: inherit; min-width: 0; }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    min-height: 100vh;
    background: linear-gradient(180deg, #062148 0%, #07345f 100%);
    color: #fff;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 26px;
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: #fff;
    min-width: 0;
}

.brand:hover { text-decoration: none; }

.brand-logo-wrap {
    width: 106px;
    height: 48px;
    flex: 0 0 106px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, .55);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .14);
}

.brand-logo-wrap img {
    width: 94px;
    height: auto;
    object-fit: contain;
}

.brand strong {
    display: block;
    line-height: 1.15;
}

.brand small, .user-box span { display: block; color: #c9d9ee; margin-top: 3px; }

.sidebar nav { display: grid; gap: 6px; }

.sidebar nav a {
    color: #e8f0fb;
    padding: 11px 12px;
    border-radius: 8px;
}

.sidebar nav a.active,
.sidebar nav a:hover {
    background: rgba(0, 132, 221, .22);
    box-shadow: inset 3px 0 0 var(--accent);
    color: #fff;
    text-decoration: none;
}

.user-box {
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, .15);
}

.user-box a { display: inline-block; margin-top: 10px; color: #fff; }

.content {
    padding: 24px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; }
h2 { font-size: 18px; margin-bottom: 14px; }
.topbar p, .muted { color: var(--muted); margin: 5px 0 0; }

.panel, .detail-head {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 18px;
}

.detail-head {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

a.stat {
    display: block;
    color: var(--text);
    text-decoration: none;
    transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

a.stat:hover,
a.stat:focus-visible {
    border-color: #9ccbed;
    box-shadow: 0 12px 28px rgba(6, 33, 72, .11);
    text-decoration: none;
    transform: translateY(-1px);
}

a.stat:focus-visible {
    outline: 3px solid rgba(19, 160, 219, .24);
    outline-offset: 2px;
}

.stat::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), #16B4F2 55%, var(--accent));
}

.stat span { display: block; color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 8px; font-size: 24px; }
.stat small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.stat.danger-stat::before { background: linear-gradient(90deg, var(--danger), var(--accent)); }
.stat.success-stat::before { background: linear-gradient(90deg, var(--primary), #32AA53); }

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

.compact-dashboard {
    margin-bottom: 18px;
}

.wide-panel {
    grid-column: 1 / -1;
}

.chart-panel {
    min-height: 260px;
}

.bar-list {
    display: grid;
    gap: 13px;
}

.bar-row {
    display: grid;
    gap: 7px;
}

.bar-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
    font-size: 14px;
}

.bar-meta span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.bar-meta em {
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
}

.bar-meta strong {
    color: var(--primary-dark);
    white-space: nowrap;
}

.bar-track {
    height: 10px;
    border-radius: 999px;
    background: #e8f0f8;
    overflow: hidden;
}

.bar-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), #16B4F2);
}

.bar-track.accent span {
    background: linear-gradient(90deg, var(--accent), var(--warning));
}

.pipeline {
    display: grid;
    grid-template-columns: repeat(6, minmax(120px, 1fr));
    gap: 12px;
}

.pipeline-step {
    min-height: 116px;
    display: grid;
    align-content: space-between;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 13px;
    background: linear-gradient(180deg, #fff, #f7fbff);
    box-shadow: 0 8px 18px rgba(6, 33, 72, .05);
}

.pipeline-step span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.pipeline-step strong {
    font-size: 28px;
    color: var(--primary-dark);
}

.pipeline-step small,
td small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.grid-two {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
}

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

.stack { display: grid; gap: 14px; }
.wide { grid-column: 1 / -1; }

label {
    display: grid;
    gap: 7px;
    color: #344054;
    font-size: 14px;
    font-weight: 600;
}

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

input:focus, select:focus, textarea:focus {
    outline: 3px solid rgba(0, 132, 221, .16);
    border-color: var(--primary);
}

textarea { min-height: 96px; resize: vertical; }
input[list] {
    min-width: 0;
}
.check { display: flex; align-items: center; gap: 9px; }
.check input { width: auto; min-height: auto; }

.actions, .section-title {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; border-color: #98b9d8; }
.btn.primary {
    background: linear-gradient(135deg, var(--primary), #16B4F2);
    border-color: var(--primary);
    color: #fff;
}
.btn.primary:hover { background: linear-gradient(135deg, #057BCD, var(--primary-dark)); }
.btn.small { min-height: 32px; padding: 6px 10px; font-size: 13px; }

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 1.4fr) repeat(5, minmax(130px, 1fr)) auto;
    gap: 10px;
    margin-bottom: 16px;
}

.filters.compact {
    grid-template-columns: minmax(220px, 1fr) auto;
}

.import-panel {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(180px, 240px) minmax(220px, 320px) auto;
    gap: 14px;
    align-items: end;
}

.import-panel h2 { margin-bottom: 6px; }
.import-panel p { margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    overflow-wrap: anywhere;
}
th { font-size: 12px; color: var(--muted); text-transform: uppercase; }
tr.overdue td { background: #fff8f7; }

.companies-table {
    table-layout: fixed;
    min-width: 1280px;
}

.companies-table th,
.companies-table td {
    overflow-wrap: normal;
    word-break: normal;
}

.companies-table th:nth-child(1),
.companies-table td:nth-child(1) { width: 8%; }
.companies-table th:nth-child(2),
.companies-table td:nth-child(2) {
    width: 38%;
    overflow-wrap: anywhere;
}
.companies-table th:nth-child(3),
.companies-table td:nth-child(3) { width: 7%; }
.companies-table th:nth-child(4),
.companies-table td:nth-child(4) { width: 7%; }
.companies-table th:nth-child(5),
.companies-table td:nth-child(5) { width: 9%; }
.companies-table th:nth-child(6),
.companies-table td:nth-child(6) { width: 5%; }
.companies-table th:nth-child(7),
.companies-table td:nth-child(7) { width: 7%; }
.companies-table th:nth-child(8),
.companies-table td:nth-child(8) { width: 6%; }
.companies-table th:nth-child(9),
.companies-table td:nth-child(9) { width: 6%; }
.companies-table th:nth-child(10),
.companies-table td:nth-child(10) {
    width: 7%;
    text-align: right;
}

.opportunities-table {
    table-layout: fixed;
    min-width: 1180px;
}

.opportunities-table th:nth-child(1),
.opportunities-table td:nth-child(1) { width: 19%; }
.opportunities-table th:nth-child(2),
.opportunities-table td:nth-child(2) { width: 11%; }
.opportunities-table th:nth-child(3),
.opportunities-table td:nth-child(3) { width: 9%; }
.opportunities-table th:nth-child(4),
.opportunities-table td:nth-child(4) { width: 15%; }
.opportunities-table th:nth-child(5),
.opportunities-table td:nth-child(5) { width: 18%; }
.opportunities-table th:nth-child(6),
.opportunities-table td:nth-child(6) { width: 10%; }
.opportunities-table th:nth-child(7),
.opportunities-table td:nth-child(7) { width: 9%; }
.opportunities-table th:nth-child(8),
.opportunities-table td:nth-child(8) { width: 9%; }
.opportunities-table th:nth-child(9),
.opportunities-table td:nth-child(9) {
    width: 8%;
    text-align: right;
}

.opportunities-table td:nth-child(3),
.opportunities-table td:nth-child(6),
.opportunities-table td:nth-child(8),
.opportunities-table td:nth-child(9) {
    overflow-wrap: normal;
    word-break: normal;
}

.badge {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #e8f4ff;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
}

.badge.success {
    background: #e8f8ed;
    color: #1f7a3a;
}

.inline-form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.inline-form input {
    min-height: 32px;
    min-width: 190px;
    padding: 6px 9px;
}

.calendar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.calendar-title {
    margin: 10px 0 14px;
    font-size: 18px;
}

.task-calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.calendar-weekday {
    padding: 10px;
    background: #f3f7fb;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    border-right: 1px solid var(--line);
}

.calendar-day {
    min-height: 118px;
    padding: 10px;
    border-top: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: #fff;
}

.calendar-day.today {
    background: #f0f8ff;
    box-shadow: inset 0 0 0 2px rgba(0, 132, 221, .18);
}

.calendar-day.muted-day {
    background: #f8fafc;
    color: var(--muted);
}

.calendar-day strong {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
}

.calendar-task {
    display: grid;
    gap: 3px;
    margin-bottom: 6px;
    padding: 7px;
    border-radius: 7px;
    background: #e8f4ff;
    color: var(--primary-dark);
}

.calendar-task span {
    font-weight: 800;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.calendar-task small {
    color: #315c80;
    font-size: 11px;
    line-height: 1.35;
}

.calendar-complete {
    display: grid;
    gap: 5px;
    margin-top: 4px;
}

.calendar-complete input {
    min-height: 30px;
    padding: 5px 7px;
    font-size: 12px;
}

.meta {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 11px 14px;
    margin: 0;
}

.meta dt { color: var(--muted); font-weight: 700; }
.meta dd { margin: 0; }

.timeline { display: grid; gap: 12px; }
.timeline article { border-left: 3px solid var(--primary); padding: 4px 0 4px 14px; }
.timeline span { display: block; color: var(--muted); margin-top: 4px; font-size: 13px; }
.timeline p { margin: 8px 0 0; }

.report-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    background:
        linear-gradient(135deg, rgba(6, 33, 72, .96), rgba(0, 132, 221, .84)),
        #062148;
    color: #fff;
}

.report-hero h2 {
    margin: 4px 0 6px;
    font-size: 24px;
}

.report-hero p {
    margin: 0;
    color: #dbe9f8;
}

.eyebrow {
    color: #F1B000;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.report-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.report-actions .btn {
    background: rgba(255, 255, 255, .12);
    border-color: rgba(255, 255, 255, .28);
    color: #fff;
}

.report-actions .btn:hover {
    background: rgba(255, 255, 255, .2);
}

.field-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: linear-gradient(135deg, #ffffff, #eef8ff);
}

.field-hero h2 {
    margin: 4px 0 6px;
    color: var(--primary-dark);
}

.field-hero p {
    margin: 0;
    color: var(--muted);
}

.quick-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.field-focus-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.25fr) minmax(240px, .7fr);
    gap: 18px;
}

.focus-card {
    min-height: 220px;
}

.compact-focus {
    align-self: start;
}

.mini-card-list {
    display: grid;
    gap: 10px;
}

.mini-card {
    display: grid;
    gap: 5px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}

.mini-card:hover {
    text-decoration: none;
    border-color: #9ccbed;
    box-shadow: 0 10px 22px rgba(6, 33, 72, .08);
}

.mini-card.late {
    background: #fff8f7;
    border-color: #f3c8c4;
}

.mini-card strong {
    color: var(--primary-dark);
}

.mini-card span,
.mini-card small {
    color: var(--muted);
    font-size: 13px;
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid #a9d8f7;
    background: #edf8ff;
    color: #00437f;
}

.alert-danger {
    border-color: #f3b5b0;
    background: #fff1f0;
    color: var(--danger);
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(6, 33, 72, .94), rgba(0, 132, 221, .82)),
        url("brand/bilnex-office.webp") center / cover;
}

.login-shell {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
    gap: 18px;
    align-items: stretch;
}

.login-panel {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-logo {
    width: 220px;
    height: 92px;
    object-fit: cover;
    object-position: center;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

.login-panel h1 { margin-top: 18px; color: var(--primary-dark); }
.login-panel p { color: var(--muted); margin: 7px 0 22px; }

.login-visual {
    margin: 0;
    min-height: 420px;
    border: 1px solid rgba(255, 255, 255, .34);
    border-radius: 8px;
    background: rgba(255, 255, 255, .92);
    box-shadow: var(--shadow);
    display: grid;
    place-items: center;
    padding: 26px;
    overflow: hidden;
}

.login-visual img {
    width: 100%;
    max-height: 320px;
    object-fit: contain;
}

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar {
        position: static;
        height: auto;
        min-height: auto;
        padding: 16px;
        gap: 14px;
        overflow: visible;
    }
    .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .brand-logo-wrap { width: 78px; flex-basis: 78px; }
    .user-box { margin-top: 0; }
    .content { padding: 16px; }
    .topbar, .detail-head, .actions, .section-title, .report-hero, .field-hero { align-items: stretch; flex-direction: column; }
    .report-actions, .quick-actions { justify-content: stretch; }
    .report-actions .btn, .quick-actions .btn { width: 100%; }
    .stats-grid, .grid-two, .form-grid, .filters, .import-panel, .dashboard-grid, .pipeline, .field-focus-grid { grid-template-columns: 1fr; }
    .wide-panel { grid-column: auto; }
    .meta { grid-template-columns: 1fr; }
    h1 { font-size: 23px; }
    .login-shell { grid-template-columns: 1fr; }
    .login-visual { display: none; }

    .brand {
        align-items: flex-start;
    }

    .brand-logo-wrap {
        width: 110px;
        flex-basis: 110px;
    }

    .brand-logo-wrap img {
        width: 98px;
    }

    .topbar .btn,
    .actions .btn,
    .section-title .btn,
    .import-panel .btn,
    .filters .btn,
    .filters button {
        width: 100%;
    }

    .filters {
        gap: 10px;
    }

    input,
    select,
    textarea,
    .btn {
        min-height: 44px;
    }

    .calendar-actions {
        width: 100%;
        justify-content: stretch;
    }

    .calendar-actions .btn {
        flex: 1 1 120px;
    }

    .task-calendar {
        display: block;
        border: 0;
        background: transparent;
    }

    .calendar-weekday {
        display: none;
    }

    .calendar-day {
        min-height: auto;
        margin-bottom: 10px;
        border: 1px solid var(--line);
        border-radius: 8px;
        box-shadow: 0 8px 18px rgba(6, 33, 72, .05);
    }

    .table-wrap {
        overflow: visible;
    }

    table,
    .opportunities-table {
        display: block;
        width: 100%;
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody,
    tr,
    td {
        display: block;
        width: 100%;
    }

    tr {
        margin-bottom: 12px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: #fff;
        box-shadow: 0 8px 18px rgba(6, 33, 72, .05);
        overflow: hidden;
    }

    th,
    td,
    .opportunities-table th,
    .opportunities-table td {
        width: auto;
        text-align: left;
    }

    td {
        display: grid;
        grid-template-columns: minmax(104px, 38%) minmax(0, 1fr);
        gap: 10px;
        padding: 9px 12px;
        border-bottom: 1px solid var(--line);
        overflow-wrap: anywhere;
    }

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

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 12px;
        font-weight: 800;
        text-transform: uppercase;
    }

    td[colspan] {
        display: block;
    }

    td[colspan]::before {
        content: none;
    }

    td .btn {
        width: 100%;
    }

    .inline-form {
        display: grid;
        gap: 8px;
    }
}

@media (max-width: 420px) {
    .content { padding: 12px; }
    .sidebar { padding: 12px; }
    .sidebar nav { grid-template-columns: 1fr; }
    .brand-logo-wrap {
        width: 96px;
        flex-basis: 96px;
    }
    .brand-logo-wrap img { width: 86px; }
    td {
        grid-template-columns: 1fr;
        gap: 4px;
    }
}
