:root {
    --app-bg: #f3f4f6;
    --app-surface: #ffffff;
    --app-ink: #111827;
    --app-muted: #6b7280;
    --app-line: #e5e7eb;
    --app-accent: #e4002b;
    --app-accent-dark: #b80022;
    --app-accent-soft: #fee2e2;
    --app-radius: 8px;
    --app-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --app-shadow-soft: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
}

* {
    letter-spacing: inherit;
    scrollbar-width: thin;
    scrollbar-color: var(--app-line) transparent;
}

body {
    background: var(--app-bg);
    color: var(--app-ink);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(380px, 540px);
    background:
        linear-gradient(90deg, rgba(16, 17, 20, 0.06) 1px, transparent 1px),
        linear-gradient(0deg, rgba(16, 17, 20, 0.06) 1px, transparent 1px),
        linear-gradient(135deg, rgba(228, 0, 43, 0.14), transparent 38%),
        var(--app-surface);
    background-size: 64px 64px;
}

.login-panel {
    border-left: 1px solid var(--app-line);
    background: var(--app-surface);
    display: flex;
    align-items: center;
    padding: 48px;
}

.login-mark {
    align-self: end;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 48px;
    min-height: 100vh;
    border-top: 10px solid var(--app-accent);
}

.login-number {
    color: var(--app-accent);
    font-size: clamp(42px, 8vw, 132px);
    font-weight: 700;
    line-height: .9;
    max-width: 760px;
    word-break: break-word;
}

.login-logo {
    width: clamp(96px, 12vw, 170px);
    height: auto;
    display: block;
}

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

.app-sidebar {
    border-right: 1px solid var(--app-line);
    background: var(--app-surface);
}

.app-main {
    min-width: 0;
}

.app-navbar {
    border-bottom: 1px solid var(--app-line);
    background: var(--app-surface);
    min-height: 72px;
    border-top: 4px solid var(--app-accent);
    box-shadow: var(--app-shadow-soft);
    position: relative;
    z-index: 10;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.brand-logo-wrap {
    display: inline-flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--app-line);
    background: var(--app-surface);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow-soft);
}

.brand-logo {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.brand-title {
    color: var(--app-ink);
    font-weight: 700;
    font-size: 18px;
    text-transform: uppercase;
}

.sidebar-menu-head {
    padding: 16px 14px;
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    background:
        linear-gradient(90deg, var(--app-accent) 0 4px, transparent 4px),
        linear-gradient(135deg, rgba(228, 0, 43, 0.04), transparent 60%),
        var(--app-surface);
    box-shadow: var(--app-shadow-soft);
}

.sidebar-menu-title {
    font-weight: 700;
    line-height: 1.1;
    text-transform: uppercase;
    margin-top: 4px;
    letter-spacing: 0.5px;
}

.app-menu {
    border: 1px solid var(--app-line);
    background: var(--app-surface);
    border-radius: var(--app-radius);
    overflow: hidden;
    box-shadow: var(--app-shadow-soft);
}

.app-sidebar .nav-link {
    border: 0;
    border-bottom: 1px solid var(--app-line);
    border-radius: 0;
    color: var(--app-ink);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 46px;
    padding: 12px 14px;
    background: var(--app-surface);
    font-weight: 500;
    position: relative;
    transition: all 0.2s ease;
}

.app-sidebar .nav-link.disabled {
    color: var(--app-muted);
    background: #f7f7f8;
    opacity: 1;
}

.app-sidebar .nav-link.disabled small {
    border: 1px solid var(--app-line);
    color: var(--app-muted);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    text-transform: uppercase;
}

.app-sidebar .nav-link.active {
    background: var(--app-ink);
    color: #fff;
    padding-left: 20px;
}

.app-sidebar .nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: var(--app-accent);
}

.app-sidebar .nav-link:not(.active):hover {
    background: var(--app-accent-soft);
    color: var(--app-accent);
    padding-left: 20px;
}

.sync-track {
    border: 1px solid var(--app-line);
    background: var(--app-surface);
    display: grid;
    gap: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-radius: var(--app-radius);
    overflow: hidden;
    box-shadow: var(--app-shadow-soft);
}

.sync-track-item {
    border-right: 1px solid var(--app-line);
    padding: 16px;
    transition: background 0.2s ease;
}

.sync-track-item:last-child {
    border-right: 0;
}

.sync-track-item.is-active {
    background: var(--app-accent-soft);
    border-top: 4px solid var(--app-accent);
}

.sync-track-item.is-disabled {
    background: var(--app-bg);
    color: var(--app-muted);
}

.metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid var(--app-line);
    border-radius: var(--app-radius);
    overflow: hidden;
    box-shadow: var(--app-shadow-soft);
}

.metric-cell {
    border-right: 1px solid var(--app-line);
    border-bottom: 1px solid var(--app-line);
    padding: 14px;
    background: var(--app-surface);
    transition: background 0.2s ease;
}
.metric-cell:hover {
    background: var(--app-bg);
}

.metric-cell:nth-child(even) {
    border-right: 0;
}
/* Ensure bottom borders are handled nicely if there are odd elements or last row */
.metric-grid .metric-cell:nth-last-child(-n+2) {
    border-bottom: 0;
}

.metric-cell strong {
    display: block;
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
    color: var(--app-ink);
}

.metric-cell span,
.section-kicker {
    color: var(--app-muted);
    font-size: 13px;
    font-weight: 500;
    margin-top: 4px;
    display: inline-block;
}

.page-frame {
    max-width: 1680px;
}

.content-panel,
section.bg-white {
    background: var(--app-surface) !important;
    border: 1px solid var(--app-line) !important;
    border-radius: var(--app-radius) !important;
    box-shadow: var(--app-shadow-soft) !important;
    position: relative;
    transition: box-shadow 0.2s ease-in-out;
}

.content-panel::before,
section.bg-white::before {
    content: "";
    position: absolute;
    inset: -1px auto auto -1px;
    width: 6px;
    height: calc(100% + 2px);
    background: var(--app-accent);
    opacity: 0;
    transition: opacity 0.2s ease;
    border-top-left-radius: var(--app-radius);
    border-bottom-left-radius: var(--app-radius);
}

.content-panel:hover,
section.bg-white:hover {
    box-shadow: var(--app-shadow) !important;
}

.content-panel:hover::before,
section.bg-white:hover::before {
    opacity: 1;
}

.form-control,
.form-select,
.btn,
.alert,
.modal-content,
.badge,
.page-link,
.progress,
.border,
.rounded {
    border-radius: max(var(--app-radius) - 2px, 4px) !important;
}

.btn {
    transition: all 0.2s ease-in-out;
    font-weight: 500;
}

.btn-primary,
.btn-outline-primary:hover,
.page-item.active .page-link {
    background: var(--app-accent);
    border-color: var(--app-accent);
    color: #fff;
    box-shadow: 0 4px 6px -1px rgba(228, 0, 43, 0.2);
}

.btn-primary:hover {
    background: var(--app-accent-dark);
    border-color: var(--app-accent-dark);
    box-shadow: 0 4px 6px -1px rgba(184, 0, 34, 0.3);
    transform: translateY(-1px);
}

.btn-outline-primary {
    border-color: var(--app-accent);
    color: var(--app-accent);
}

.table {
    margin-bottom: 0;
    border-radius: var(--app-radius);
    overflow: hidden;
}

.table-responsive {
    border-radius: var(--app-radius);
    border: 1px solid var(--app-line);
    background: var(--app-surface);
}

.table thead th {
    background: #f9fafb;
    border-bottom: 1px solid var(--app-line);
    color: var(--app-muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px;
}
.table tbody td {
    padding: 12px 16px;
}

.sort-link {
    align-items: center;
    color: inherit;
    display: inline-flex;
    gap: 4px;
    text-decoration: none;
}

.sort-link:hover {
    color: #fff;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.table td,
.table th {
    border-color: var(--app-line);
    vertical-align: middle;
}

.modal-header,
.modal-footer {
    border-color: var(--app-line);
}

.sync-terminal {
    min-height: 360px;
    max-height: 520px;
    overflow: auto;
    background: #101114;
    color: #f7f7f8;
    border: 1px solid var(--app-line);
    padding: 16px;
    font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.app-navbar .btn {
    white-space: nowrap;
}

.content-panel .h4,
.content-panel .h5,
.content-panel .h6 {
    line-height: 1.2;
}

@media (max-width: 991.98px) {
    .app-shell,
    .login-shell,
    .sync-track {
        grid-template-columns: 1fr;
    }

    .app-sidebar,
    .login-panel {
        border-left: 0;
        border-right: 0;
    }

    .login-mark {
        min-height: auto;
        padding: 32px;
    }

    .brand-title {
        font-size: 15px;
    }

    .sync-track-item,
    .sync-track-item:last-child {
        border-right: 0;
        border-bottom: 1px solid var(--app-line);
    }
}
