* {
    box-sizing: border-box;
}

:root {
    --sidebar-width: 286px;
    --sidebar-collapsed-width: 82px;
    --topbar-height: 68px;
    --primary: #b31217;
    --primary-dark: #8f0e12;
    --primary-soft: rgba(179, 18, 23, 0.12);
    --bg: #f5f7fb;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --sidebar-bg: #101827;
    --sidebar-panel: rgba(255,255,255,0.055);
    --sidebar-text: #f9fafb;
    --sidebar-muted: #cbd5e1;
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-active: rgba(179,18,23,0.38);
    --shadow: 0 8px 24px rgba(0,0,0,0.06);
}

html, body {
    margin: 0;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
    max-width: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    font: inherit;
}

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eef2f7;
}

.login-wrapper {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 14px;
    padding: 30px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.08);
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 24px;
}

.login-subtitle {
    color: #666;
    margin-bottom: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #d8dce3;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.btn {
    border: 0;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    display: inline-block;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

.btn-secondary:hover {
    background: #d1d5db;
}

.btn-full {
    width: 100%;
}

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 14px;
}

.alert-danger {
    background: #ffe7e7;
    color: #9b1c1c;
}

.alert-warning {
    background: #fff2cc;
    color: #7a5200;
}

.alert-success {
    background: #eaf8ee;
    color: #166534;
}

.alert-info {
    background: #e7f0ff;
    color: #1d4ed8;
}

.login-note {
    margin-top: 16px;
    font-size: 13px;
    color: #777;
    text-align: center;
}

.app-shell {
    min-height: 100vh;
    max-width: 100%;
    overflow-x: hidden;
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 90;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #111827 0%, #0b1220 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.25s ease, transform 0.25s ease;
    overflow: hidden;
    border-right: 1px solid rgba(255,255,255,0.06);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: 82px;
}

.sidebar-logo-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.sidebar-logo {
    width: 46px;
    height: 46px;
    object-fit: contain;
    border-radius: 14px;
    background: #fff;
    padding: 5px;
    box-shadow: 0 8px 22px rgba(0,0,0,0.18);
}

.sidebar-logo-fallback {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.sidebar-brand-text {
    min-width: 0;
}

.sidebar-brand-title {
    font-size: 17px;
    font-weight: 800;
    white-space: nowrap;
}

.sidebar-brand-subtitle {
    font-size: 12px;
    color: var(--sidebar-muted);
    white-space: nowrap;
    margin-top: 2px;
}

.page-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.page-title-row > div:first-child {
    min-width: 0;
}

.page-title-row h1 {
    margin: 0 0 6px;
    font-size: 22px;
    line-height: 1.2;
}

.page-title-row p {
    margin: 0;
    color: #64748b;
    font-size: 14px;
    line-height: 1.45;
}

.page-source-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 10px;
    margin: 10px 0 18px;
}

.page-source-chip {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 7px 11px;
    border: 1px solid #e8edf4;
    border-radius: 999px;
    background: #fff;
    color: #334155;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.25;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.03);
}

.page-source-chip strong {
    color: #0f172a;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.page-source-chip .muted {
    color: #64748b;
    font-size: 12px;
}

.ops-worklist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
}

.ops-worklist-card {
    display: grid;
    gap: 10px;
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 10px 26px rgba(16, 24, 40, .05);
}

.ops-worklist-card h3 {
    margin: 0;
    font-size: 16px;
}

.ops-worklist-card p {
    margin: 0;
    color: #64748b;
    font-size: 13px;
    line-height: 1.45;
}

.ops-worklist-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
    color: #334155;
}

.ops-worklist-meta strong {
    color: #0f172a;
}

.sidebar-collapse-btn,
.topbar-toggle-btn {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 8px;
    border-radius: 10px;
}

.sidebar-collapse-btn:hover,
.topbar-toggle-btn:hover {
    background: rgba(255,255,255,0.08);
}

.sidebar-user {
    margin: 12px 12px 8px;
    padding: 12px;
    border-radius: 14px;
    background: var(--sidebar-panel);
    display: flex;
    gap: 10px;
    align-items: center;
}

.sidebar-user-avatar,
.topbar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex: 0 0 auto;
}

.sidebar-user-info {
    min-width: 0;
}

.sidebar-user-name {
    font-weight: bold;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role,
.sidebar-user-scope {
    font-size: 12px;
    color: var(--sidebar-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-menu {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.sidebar-menu::-webkit-scrollbar {
    width: 7px;
}

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.16);
    border-radius: 999px;
}

.menu-group {
    margin-bottom: 7px;
    border-radius: 14px;
    position: relative;
}

.menu-parent-btn {
    width: 100%;
    background: transparent;
    color: var(--sidebar-text);
    border: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px;
    cursor: pointer;
    border-radius: 12px;
}

.menu-parent-btn:hover {
    background: var(--sidebar-hover);
}

.menu-icon-badge {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255,255,255,0.10);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    flex: 0 0 auto;
}

.menu-parent-label {
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-parent-arrow {
    font-size: 13px;
    transition: transform 0.2s ease;
    color: var(--sidebar-muted);
}

.menu-group.open .menu-parent-arrow {
    transform: rotate(180deg);
}

.menu-children {
    display: none;
    padding: 3px 0 8px 42px;
}

.menu-group.open .menu-children {
    display: block;
}

.menu-child {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 3px 4px 0 0;
    padding: 9px 10px;
    color: var(--sidebar-muted);
    border-radius: 10px;
    font-size: 14px;
}

.menu-child-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: rgba(255,255,255,0.28);
    flex: 0 0 auto;
}

.menu-child-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-child:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.menu-child.active {
    background: var(--sidebar-active);
    color: #fff;
}

.menu-child.active .menu-child-dot {
    background: #fff;
}

.menu-empty {
    padding: 12px;
    color: var(--sidebar-muted);
    font-size: 13px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,0.08);
    color: #fff;
    text-align: center;
    font-weight: bold;
}

.logout-btn:hover {
    background: rgba(255,255,255,0.14);
}

.sidebar-footer .logout-btn + .logout-btn {
    margin-top: 8px;
}

.main-wrapper {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    max-width: calc(100vw - var(--sidebar-width));
    min-width: 0;
    min-height: 100vh;
    transition: margin-left 0.25s ease;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.topbar {
    height: var(--topbar-height);
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-toggle-btn {
    color: var(--text);
}

.topbar-toggle-btn:hover {
    background: #f3f4f6;
}

.topbar-page-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text);
}

.topbar-page-subtitle {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-user-pill {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 10px 6px 6px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
}

.topbar-user-name {
    font-size: 14px;
    color: var(--text);
    font-weight: 600;
}

.content,
.main-content,
.page-content {
    padding: 20px;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

.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,
.stat-card,
.panel {
    background: var(--card);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 18px;
    border: 1px solid #eef2f7;
    min-width: 0;
}

.stat-card {
    min-height: 96px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.card + .card {
    margin-top: 18px;
}

.stat-title {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1.15;
    word-break: break-word;
}

.dashboard-info-icon,
.ap24-info-icon,
.cpnl-info-icon {
    flex: 0 0 auto;
    transform: translateY(-1px);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid #eef2f7;
}

.table-standard,
table {
    width: 100%;
    border-collapse: collapse;
}

.table-standard th,
.table-standard td,
table th,
table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eef2f7;
    text-align: left;
    font-size: 14px;
    vertical-align: top;
}

.table-standard th,
table th {
    background: #fafafa;
    font-weight: 800;
    white-space: nowrap;
}

.table-standard tr:hover td,
table tr:hover td {
    background: #fcfcfd;
}

.info-table th {
    width: 220px;
    color: #555;
}

.filter-card {
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 16px;
    border: 1px solid #eef2f7;
    margin-bottom: 18px;
}

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

.filter-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: bold;
    background: #eef2ff;
    color: #3730a3;
}

.site-footer {
    margin-top: auto;
    padding: 14px 20px;
}

.site-footer-inner {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    font-size: 12px;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

/* Collapsed desktop sidebar */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
    max-width: calc(100vw - var(--sidebar-collapsed-width));
}

body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .sidebar-user-info,
body.sidebar-collapsed .menu-parent-label,
body.sidebar-collapsed .menu-parent-arrow,
body.sidebar-collapsed .menu-children,
body.sidebar-collapsed .logout-text {
    display: none;
}

body.sidebar-collapsed .sidebar-header {
    justify-content: center;
    padding: 16px 8px;
    flex-direction: column;
    gap: 8px;
}

body.sidebar-collapsed .sidebar-logo-wrap {
    justify-content: center;
}

body.sidebar-collapsed .sidebar-collapse-btn {
    background: rgba(255,255,255,0.08);
    font-size: 16px;
}

body.sidebar-collapsed .sidebar-user {
    justify-content: center;
    padding: 10px 8px;
}

body.sidebar-collapsed .menu-parent-btn {
    justify-content: center;
    padding: 11px 8px;
}

body.sidebar-collapsed .menu-icon-badge {
    width: 36px;
    height: 36px;
}

body.sidebar-collapsed .sidebar-footer {
    padding: 10px 8px;
}

body.sidebar-collapsed .logout-btn {
    padding: 10px 0;
}

body.sidebar-collapsed .menu-parent-btn:hover::after,
body.sidebar-collapsed .logout-btn:hover::after {
    content: attr(title);
    position: fixed;
    left: calc(var(--sidebar-collapsed-width) + 8px);
    background: #111827;
    color: #fff;
    padding: 7px 10px;
    border-radius: 8px;
    white-space: nowrap;
    font-size: 12px;
    box-shadow: var(--shadow);
    z-index: 300;
}

/* Mobile */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }

    .main-wrapper {
        margin-left: 0;
        width: 100%;
        max-width: 100vw;
    }

    body.sidebar-mobile-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-mobile-open .mobile-overlay {
        display: block;
    }

    body.sidebar-collapsed .sidebar {
        width: var(--sidebar-width);
    }

    body.sidebar-collapsed .main-wrapper {
        margin-left: 0;
        width: 100%;
        max-width: 100vw;
    }

    body.sidebar-collapsed .sidebar-brand-text,
    body.sidebar-collapsed .sidebar-user-info,
    body.sidebar-collapsed .menu-parent-label,
    body.sidebar-collapsed .menu-parent-arrow,
    body.sidebar-collapsed .logout-text {
        display: initial;
    }

    body.sidebar-collapsed .menu-children {
        display: none;
    }

    body.sidebar-collapsed .menu-group.open .menu-children {
        display: block;
    }

    body.sidebar-collapsed .sidebar-header {
        justify-content: space-between;
        padding: 16px;
        flex-direction: row;
        gap: 8px;
    }

    body.sidebar-collapsed .sidebar-user {
        justify-content: flex-start;
        padding: 12px;
    }

    body.sidebar-collapsed .menu-parent-btn {
        justify-content: flex-start;
        padding: 10px;
    }

    .filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-4,
    .grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .topbar {
        padding: 0 12px;
    }

    .content,
    .main-content,
    .page-content {
        padding: 14px;
    }

    .filter-grid,
    .grid-4,
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr;
    }

    .topbar-page-title {
        font-size: 16px;
    }

    .topbar-page-subtitle,
    .topbar-user-name {
        display: none;
    }

    .page-title-row {
        flex-direction: column;
        align-items: flex-start;
    }
}
