:root {
    --csim-blue: #005b91;
    --csim-blue-deep: #003f67;
    --csim-blue-soft: #eaf4fa;
    --csim-orange: #f47b20;
    --csim-orange-soft: #fff2e8;
    --ink: #17212b;
    --muted: #667085;
    --line: #d9e2ea;
    --surface: #ffffff;
    --surface-alt: #f6f9fb;
    --danger: #b42318;
    --success: #067647;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: #eef3f7;
    font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(0,91,145,.08), transparent 32rem),
        #eef3f7;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 3px solid var(--csim-orange);
    background: linear-gradient(90deg, var(--csim-blue-deep), var(--csim-blue));
    color: #fff;
    box-shadow: 0 6px 18px rgba(0,63,103,.18);
}

.app-topbar-inner {
    width: min(100%, 1180px);
    min-height: 66px;
    margin: 0 auto;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    color: #fff;
    text-decoration: none;
}

.app-brand-symbol {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
}

.app-brand-text strong,
.app-brand-text span { display: block; }
.app-brand-text strong { font-size: 1rem; letter-spacing: .06em; }
.app-brand-text span { margin-top: 1px; font-size: .72rem; color: rgba(255,255,255,.78); }

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 999px;
    background: rgba(255,255,255,.1);
    color: #fff;
    font-size: .82rem;
    font-weight: 700;
    text-decoration: none;
}

.user-chip::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--csim-orange);
}

.user-menu {
    position: relative;
}

.user-menu-toggle {
    border: 1px solid rgba(255,255,255,.2);
    cursor: pointer;
}

.user-menu-arrow {
    font-size: .7rem;
    opacity: .8;
}

.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1000;
    min-width: 170px;
    padding: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(0,0,0,.12);
}

.user-menu-dropdown a {
    display: block;
    padding: 9px 12px;
    border-radius: 7px;
    color: #344054;
    text-decoration: none;
    font-size: .88rem;
    font-weight: 600;
}

.user-menu-dropdown a:hover {
    background: #f2f4f7;
}

.user-menu-logout-form {
    margin: 0;
}

.user-menu-dropdown .user-menu-logout {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #b42318;
    text-align: left;
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
}

.user-menu-dropdown .user-menu-logout:hover {
    background: #f2f4f7;
}

.app-shell {
    width: min(100%, 1180px);
    margin: 0 auto;
    padding: 26px 20px 36px;
}

h1, h2, p { margin-top: 0; }
h1 {
    margin-bottom: 5px;
    color: var(--csim-blue-deep);
    font-size: clamp(1.65rem, 4vw, 2.25rem);
    line-height: 1.12;
    letter-spacing: -.025em;
}
h2 { margin-bottom: 16px; color: var(--csim-blue-deep); font-size: 1.08rem; }
.muted { margin-bottom: 0; color: var(--muted); }
.eyebrow {
    margin-bottom: 5px;
    color: var(--csim-orange);
    font-size: .74rem;
    font-weight: 900;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 2px 2px 0;
}
.dashboard-header { align-items: center; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
    color: var(--csim-blue);
    font-size: .9rem;
    font-weight: 800;
    text-decoration: none;
}
.back-link:hover { color: var(--csim-orange); }

.panel,
.login-card {
    margin-bottom: 18px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(28,55,75,.07);
}

.panel { border-top: 4px solid var(--csim-blue); }

.alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 10px;
    font-weight: 700;
}
.alert-error { border: 1px solid #fecdca; color: #912018; background: #fff6f5; }
.alert-success { border: 1px solid #abefc6; color: #05603a; background: #ecfdf3; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; min-width: 0; }
.field label { color: #344054; font-size: .88rem; font-weight: 800; }
input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #c7d3dd;
    border-radius: 9px;
    color: var(--ink);
    background: #fff;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input[type="text"], input[type="date"], input[type="number"], input[type="search"], input[type="password"], select {
    height: 44px;
    min-height: 44px;
}
select { padding: 0 12px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: var(--csim-blue);
    box-shadow: 0 0 0 3px rgba(0,91,145,.13);
}

.date-input-wrap { width: 100%; max-width: 100%; min-width: 0; overflow: hidden; }
.date-input-wrap input[type="date"] {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}

.btn {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 10px 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-weight: 800;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn-primary {
    color: #fff;
    background: linear-gradient(180deg, #0870aa, var(--csim-blue));
    box-shadow: 0 5px 12px rgba(0,91,145,.2);
}
.btn-primary:hover:not(:disabled) { background: var(--csim-blue-deep); }
.btn-secondary {
    border-color: #bdd0dd;
    color: var(--csim-blue-deep);
    background: #fff;
}
.btn-secondary:hover:not(:disabled) { border-color: var(--csim-blue); background: var(--csim-blue-soft); }
.btn-text-danger { min-height: auto; padding: 8px; color: var(--danger); background: transparent; }
.btn-block { width: 100%; }

.login-page {
    display: grid;
    min-height: calc(100vh - 150px);
    place-items: center;
}
.login-card {
    width: min(100%, 430px);
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    box-shadow: 0 22px 55px rgba(0,63,103,.18);
}
.login-card::before {
    content: "";
    display: block;
    height: 7px;
    background: linear-gradient(90deg, var(--csim-blue) 0 78%, var(--csim-orange) 78% 100%);
}
.login-card-inner { padding: 30px; }
.login-card form { display: grid; gap: 16px; }
.brand-block {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 26px;
}
.brand-block h1 { margin-bottom: 3px; font-size: 1.55rem; }
.brand-block p { margin-bottom: 0; color: var(--muted); }
.brand-mark {
    display: grid;
    width: 58px;
    height: 58px;
    border-radius: 17px;
    background: linear-gradient(145deg, var(--csim-blue-deep), var(--csim-blue));
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: .04em;
    place-items: center;
}
.login-note {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: .78rem;
    text-align: center;
}

.dashboard-hero {
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
    padding: 26px;
    border-radius: 18px;
    color: #fff;
    background: linear-gradient(120deg, var(--csim-blue-deep), var(--csim-blue));
    box-shadow: 0 14px 34px rgba(0,63,103,.18);
}
.dashboard-hero::after {
    content: "";
    position: absolute;
    width: 240px;
    height: 240px;
    right: -70px;
    top: -100px;
    border: 28px solid rgba(255,255,255,.08);
    border-radius: 50%;
}
.dashboard-hero h1 { color: #fff; }
.dashboard-hero .muted { color: rgba(255,255,255,.78); }
.dashboard-hero-actions { position: relative; z-index: 1; display: flex; gap: 10px; align-items: center; }
.dashboard-hero .btn-secondary { border-color: rgba(255,255,255,.42); color: #fff; background: rgba(255,255,255,.1); }
.dashboard-hero .btn-secondary:hover { background: rgba(255,255,255,.18); }

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.menu-card {
    position: relative;
    display: flex;
    min-height: 124px;
    align-items: center;
    gap: 16px;
    padding: 20px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    color: inherit;
    background: #fff;
    box-shadow: 0 8px 22px rgba(28,55,75,.06);
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.menu-card::after {
    content: "→";
    position: absolute;
    right: 18px;
    bottom: 14px;
    color: var(--csim-orange);
    font-size: 1.15rem;
    font-weight: 900;
}
.menu-card:hover {
    transform: translateY(-2px);
    border-color: #a9c7d9;
    box-shadow: 0 13px 28px rgba(28,55,75,.11);
}
.menu-card strong, .menu-card small { display: block; }
.menu-card strong { margin-bottom: 5px; color: var(--csim-blue-deep); font-size: 1.02rem; }
.menu-card small { color: var(--muted); }
.menu-icon {
    display: grid;
    width: 52px;
    height: 52px;
    flex: 0 0 52px;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(145deg, var(--csim-blue-deep), var(--csim-blue));
    font-size: 1.5rem;
    font-weight: 900;
    place-items: center;
    box-shadow: inset 0 -4px 0 rgba(244,123,32,.9);
}

.search-form { display: flex; align-items: flex-end; gap: 10px; }
.field-grow { flex: 1; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.section-heading h2, .section-heading p { margin-bottom: 0; }
.record-count { color: var(--muted); font-size: .85rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 11px 10px; border-bottom: 1px solid #e7edf2; text-align: left; vertical-align: top; }
th {
    color: #fff;
    background: var(--csim-blue-deep);
    font-size: .76rem;
    letter-spacing: .04em;
    text-transform: uppercase;
}
tbody tr:nth-child(even) { background: #f9fbfc; }
tbody tr:hover { background: var(--csim-blue-soft); }
.item-table td { vertical-align: middle; }
.item-table td:nth-child(2) { width: 100%; }
.item-table th:nth-child(4),
.item-table td:nth-child(4) {
    width: 100px;
    min-width: 100px;
}
.number { text-align: right; }
.mono, .item-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.empty-state { padding: 28px 12px; color: var(--muted); text-align: center; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-wide { grid-column: 1 / -1; }
.line-table, .stock-line { display: grid; grid-template-columns: minmax(280px, 1fr) 140px 90px 90px; gap: 10px; align-items: center; }
.line-table-header { margin-bottom: 8px; padding: 0 2px; color: var(--csim-blue-deep); font-size: .78rem; font-weight: 900; text-transform: uppercase; }
.stock-line { padding: 10px 0; border-top: 1px solid #e5ebf0; }
.line-unit { color: #475467; font-weight: 700; }
.line-action { text-align: right; }
.submit-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid #e5ebf0;
}

.submit-bar .btn {
    min-width: 150px;
}

.btn-submit {
    min-width: 190px;
}

@media (max-width: 720px) {
    .app-topbar-inner { min-height: 60px; padding: 8px 14px; }
    .app-brand-text span { display: none; }
    .user-chip { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .app-shell { padding: 16px 14px 28px; }
    .dashboard-header, .page-header { align-items: flex-start; }
    .dashboard-grid, .form-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .dashboard-hero { padding: 20px; }
    .dashboard-hero-actions { align-items: stretch; flex-direction: column; }
    .dashboard-hero-actions .btn { width: 100%; }
    .menu-card { min-height: 102px; padding: 16px; }
    .search-form { display: grid; grid-template-columns: 1fr 1fr; }
    .search-form .field-grow { grid-column: 1 / -1; }
    .item-lines-heading { align-items: flex-start; flex-direction: column; }
    .item-lines-heading .btn { width: 100%; }
    .stock-line { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin-bottom: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 5px 14px rgba(28,55,75,.05); }
    .line-item-field, .stock-line > .field:nth-child(2) { grid-column: 1 / -1; }
    .line-unit, .line-action { align-self: center; }
    .submit-bar {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .submit-bar .btn,
    .btn-submit {
        width: 100%;
    }

    .item-table-wrap { overflow: visible; border: 0; }
    .item-table, .item-table tbody, .item-table tr, .item-table td { display: block; width: 100%; }
    .item-table thead { display: none; }
    .item-table tr { margin-bottom: 12px; padding: 13px 14px; border: 1px solid var(--line); border-left: 4px solid var(--csim-blue); border-radius: 12px; background: #fff; box-shadow: 0 5px 14px rgba(28,55,75,.05); }
    .item-table td { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 10px; padding: 5px 0; border: 0; text-align: left; background: transparent; }
    .item-table td::before { content: attr(data-label); color: var(--csim-blue-deep); font-size: .76rem; font-weight: 800; }
    .item-table td[data-label="Name"] { margin-bottom: 5px; font-weight: 800; }
    .item-table td.number { text-align: left; }
    .item-table tr:last-child { margin-bottom: 0; }
}

@media (max-width: 420px) {
    .app-shell { padding: 12px 10px 24px; }
    .panel, .login-card-inner { padding: 17px; }
    .panel { border-radius: 13px; }
    .dashboard-header { flex-direction: column; }
    .dashboard-header form, .dashboard-header .btn { width: 100%; }
    .app-brand-symbol { width: 38px; height: 38px; border-radius: 10px; }
}
