:root {
    --brand: #3caee0;
    --brand-dark: #168fc4;
    --brand-soft: rgba(60, 174, 224, 0.14);
    --black: #0f172a;
    --sidebar: #08111f;
    --sidebar-panel: #0d1a2e;
    --sidebar-hover: #10233c;
    --sidebar-line: rgba(255,255,255,0.13);
    --sidebar-text: #e5eef9;
    --sidebar-muted: #a9bad0;
    --white: #ffffff;
    --page-bg: #f4f7fa;
    --panel-bg: #ffffff;
    --border: #d8e1ea;
    --border-soft: #edf1f5;
    --text: #111827;
    --text-muted: #5f6f85;
    --danger: #b42318;
    --success: #027a48;
    --warning: #b54708;
    --sidebar-width: 250px;
    --topbar-height: 64px;
    --radius: 9px;
}

* { box-sizing: border-box; }
html { min-height: 100%; font-size: 15px; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--page-bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { color: var(--brand); }

body.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: linear-gradient(135deg, #f7fbfd 0%, #eef7fb 100%);
}

.portal-layout { min-height: 100vh; }

.portal-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: var(--white);
    position: fixed;
    inset: 0 auto 0 0;
    overflow-y: auto;
    z-index: 10;
    border-right: 1px solid var(--sidebar-line);
}

.portal-brand-wrap {
    padding: 1.15rem 1rem 1rem;
    border-bottom: 1px solid var(--sidebar-line);
    background: rgba(255,255,255,0.02);
}

.portal-brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-size: 1.08rem;
    font-weight: 850;
    letter-spacing: .2px;
    line-height: 1.2;
    color: var(--white);
}
.portal-brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    box-shadow: 0 0 0 3px rgba(60,174,224,0.14);
}
.portal-brand span { color: var(--brand); }
.portal-brand-subtitle {
    color: var(--sidebar-muted);
    font-size: .82rem;
    margin-top: .25rem;
    margin-left: 2.6rem;
}

.portal-menu {
    padding: .8rem .7rem 1rem;
}

.menu-section-label {
    color: #8fa8c6;
    font-size: .72rem;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: .95rem .65rem .42rem;
}

.portal-menu a,
.portal-menu button,
.portal-menu summary {
    width: 100%;
    border: 0;
    color: var(--sidebar-text);
    background: transparent;
    padding: .62rem .72rem;
    border-radius: 7px;
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .93rem;
    font-weight: 650;
    text-align: left;
    cursor: pointer;
    min-height: 39px;
}

.portal-menu a:hover,
.portal-menu button:hover,
.portal-menu summary:hover,
.portal-menu a.active {
    background: var(--sidebar-hover);
    color: var(--white);
}

.portal-menu a.active {
    background: rgba(60, 174, 224, 0.20);
    border-left: 3px solid var(--brand);
    padding-left: calc(.72rem - 3px);
    color: var(--white);
}

.menu-group {
    border-top: 1px solid transparent;
    border-bottom: 1px solid transparent;
    margin: .12rem 0;
}
.menu-group[open] {
    background: var(--sidebar-panel);
    border-top-color: var(--sidebar-line);
    border-bottom-color: var(--sidebar-line);
    border-radius: 8px;
    padding-bottom: .28rem;
}
.menu-group summary {
    list-style: none;
    justify-content: space-between;
    color: var(--sidebar-text);
}
.menu-group summary::-webkit-details-marker { display: none; }
.menu-group summary::after {
    content: '›';
    color: #b7c8dd;
    font-size: 1.15rem;
    transition: transform .16s ease;
}
.menu-group[open] summary::after { transform: rotate(90deg); }
.submenu {
    margin-left: .75rem;
    padding-left: .68rem;
    border-left: 1px solid rgba(60, 174, 224, 0.38);
}
.submenu a {
    font-size: .88rem;
    min-height: 34px;
    padding: .48rem .62rem;
    color: #d0dbea;
}

.portal-menu form { margin: .8rem 0 0; }
.portal-menu button.logout-btn {
    color: #fecaca;
    border-top: 1px solid var(--sidebar-line);
    border-radius: 0;
    margin-top: .45rem;
    padding-top: .85rem;
}

.portal-main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.portal-topbar {
    min-height: var(--topbar-height);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: .85rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 5;
}
.portal-page-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 850;
    color: var(--black);
}
.portal-muted { color: var(--text-muted); font-size: .9rem; }
.portal-content { padding: 1.15rem; }

.portal-card,
article.portal-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .05);
    margin-bottom: 1rem;
}
.portal-card h2,
.portal-card h3 { margin-top: 0; }
.portal-card h2 { font-size: 1.08rem; margin-bottom: .4rem; }

.portal-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .9rem;
    margin: 1rem 0;
}
.stat-card { padding: 1rem; }
.stat-card h3 {
    margin: 0 0 .18rem;
    font-size: 1.65rem;
    line-height: 1.1;
    color: var(--brand-dark);
}
.stat-card p { margin: 0; color: var(--text-muted); font-size: .9rem; }

.erp-toolbar,
.page-title,
.portal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .85rem;
    margin-bottom: .9rem;
}

button,
.button,
input[type="submit"] {
    background: var(--brand);
    border: 1px solid var(--brand);
    color: var(--white);
    border-radius: 7px;
    padding: .56rem .85rem;
    cursor: pointer;
    font-weight: 750;
    font-size: .92rem;
    line-height: 1.2;
    display: inline-block;
}
button:hover,
.button:hover,
input[type="submit"]:hover {
    background: var(--brand-dark);
    border-color: var(--brand-dark);
    color: var(--white);
}
button.secondary,
.button.secondary,
.secondary.outline {
    background: var(--white);
    color: var(--text);
    border: 1px solid var(--border);
}

input,
select,
textarea {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: .58rem .7rem;
    width: 100%;
    background: var(--white);
    color: var(--text);
    font-size: .95rem;
    min-height: 40px;
}
textarea { min-height: 100px; }
input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    outline: 2px solid rgba(60, 174, 224, .18);
}
label { font-weight: 700; color: var(--text); font-size: .92rem; }

.table-wrap {
    overflow-x: auto;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
}
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    font-size: .92rem;
}
th,
td {
    padding: .68rem .78rem;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
    vertical-align: middle;
}
th {
    font-weight: 850;
    background: #f8fafc;
    color: #334155;
}
tr:last-child td { border-bottom: 0; }

.status-badge,
.badge {
    display: inline-block;
    padding: .22rem .5rem;
    border-radius: 999px;
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-size: .78rem;
    font-weight: 850;
}

.notice {
    padding: .7rem .85rem;
    border-radius: 8px;
    margin-bottom: .9rem;
    background: var(--white);
    border: 1px solid var(--border);
    font-size: .92rem;
}
.notice.success { border-left: 4px solid var(--success); }
.notice.error { border-left: 4px solid var(--danger); }

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.7rem;
    box-shadow: 0 12px 34px rgba(15, 23, 42, .12);
}
.auth-brand { text-align: center; margin-bottom: 1.1rem; }
.auth-brand h1 { margin: 0; font-size: 1.5rem; color: var(--black); }
.auth-brand h1 span { color: var(--brand); }
.auth-brand p { margin: .4rem 0 0; color: var(--text-muted); font-size: .9rem; }
.auth-card form { display: grid; gap: .85rem; }
.auth-card button { width: 100%; margin-top: .15rem; }

.module-list { margin: 0; padding-left: 1rem; }
.module-list li { margin: .32rem 0; }
small { color: var(--text-muted); }

@media (max-width: 1100px) {
    .portal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .portal-sidebar {
        position: relative;
        width: 100%;
        inset: auto;
    }
    .portal-main { margin-left: 0; }
    .portal-topbar { position: relative; flex-direction: column; align-items: flex-start; }
}
@media (max-width: 620px) {
    body.auth-body { padding: .8rem; }
    .portal-content { padding: .85rem; }
    .portal-grid { grid-template-columns: 1fr; }
    .erp-toolbar,
    .page-title,
    .portal-actions { flex-direction: column; align-items: flex-start; }
}
