/* =========================================================
   Oil Transport System — Material Admin Pro inspired theme
   Built on Bootstrap 5 with material elevation & accents.
   ========================================================= */

:root {
    --ma-primary: #5e72e4;
    --ma-primary-dark: #4453c4;
    --ma-sidebar-bg: #1f283e;
    --ma-sidebar-bg2: #2a3553;
    --ma-sidebar-text: #b7c0d8;
    --ma-sidebar-active: #5e72e4;
    --ma-body: #f4f6fb;
    --ma-card-radius: 14px;
    --ma-shadow: 0 6px 24px rgba(31, 40, 62, .08);
    --ma-shadow-sm: 0 2px 8px rgba(31, 40, 62, .06);
}

* { font-family: 'Sarabun', 'Inter', 'Segoe UI', 'Cordia New', system-ui, sans-serif; }

html[lang="th"] body {
    font-family: 'Sarabun', 'Cordia New', 'Inter', 'Segoe UI', system-ui, sans-serif;
}

body {
    background: var(--ma-body);
    color: #2d3748;
    margin: 0;
}

/* ---------- Layout shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--ma-sidebar-bg), var(--ma-sidebar-bg2));
    color: var(--ma-sidebar-text);
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 1040;
    transition: transform .25s ease;
    display: flex;
    flex-direction: column;
}

.sidebar .brand {
    display: flex; align-items: center; gap: .6rem;
    padding: 1.25rem 1.4rem;
    color: #fff; font-weight: 700; font-size: 1.15rem;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar .brand i { color: #ffb547; }

.sidebar .nav-section {
    padding: 1rem 1.4rem .35rem;
    font-size: .7rem; letter-spacing: .08em; text-transform: uppercase;
    color: #6b7591; font-weight: 700;
}

.sidebar .nav-link {
    display: flex; align-items: center; gap: .8rem;
    color: var(--ma-sidebar-text);
    padding: .7rem 1.4rem;
    border-radius: 0;
    font-size: .92rem;
    transition: all .15s ease;
    border-left: 3px solid transparent;
}
.sidebar .nav-link i { width: 20px; text-align: center; font-size: 1rem; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.sidebar .nav-link.active {
    color: #fff;
    background: rgba(94,114,228,.18);
    border-left-color: var(--ma-sidebar-active);
}
.sidebar .nav-link .badge { margin-left: auto; }

.sidebar-user {
    margin-top: auto;
    padding: 1rem 1.4rem;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex; align-items: center; gap: .7rem;
}
.sidebar-user .avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--ma-primary); color: #fff;
    display: grid; place-items: center; font-weight: 700;
}

/* ---------- Main content ---------- */
.main { flex: 1; margin-left: 260px; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: #fff;
    height: 64px;
    display: flex; align-items: center;
    padding: 0 1.5rem;
    box-shadow: var(--ma-shadow-sm);
    position: sticky; top: 0; z-index: 1030;
}
.topbar .page-title { font-weight: 700; font-size: 1.1rem; margin: 0; }
.topbar .menu-toggle { display: none; }

.content { padding: 1.6rem; flex: 1; }
.page-footer { padding: 1rem 1.6rem; color: #8895ad; font-size: .85rem; }

/* ---------- Cards ---------- */
.card {
    border: none;
    border-radius: var(--ma-card-radius);
    box-shadow: var(--ma-shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid #eef1f7;
    font-weight: 600;
    padding: 1rem 1.25rem;
}

/* Stat cards */
.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
    width: 54px; height: 54px; border-radius: 14px;
    display: grid; place-items: center; font-size: 1.4rem; color: #fff;
}
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { color: #8895ad; font-size: .85rem; }

.bg-grad-primary { background: linear-gradient(135deg,#5e72e4,#825ee4); }
.bg-grad-success { background: linear-gradient(135deg,#2dce89,#2dcecc); }
.bg-grad-warning { background: linear-gradient(135deg,#fb6340,#fbb140); }
.bg-grad-info    { background: linear-gradient(135deg,#11cdef,#1171ef); }
.bg-grad-dark    { background: linear-gradient(135deg,#212529,#4a5568); }

/* ---------- Buttons ---------- */
.btn-primary {
    background: var(--ma-primary); border-color: var(--ma-primary);
    box-shadow: 0 4px 10px rgba(94,114,228,.35);
}
.btn-primary:hover { background: var(--ma-primary-dark); border-color: var(--ma-primary-dark); }
.btn { border-radius: 8px; font-weight: 500; }

/* ---------- Status badges ---------- */
.status-badge {
    font-weight: 600;
    font-size: .72rem;
    padding: .4em .75em;
    letter-spacing: .01em;
    box-shadow: 0 2px 6px rgba(31, 40, 62, .12);
}
/* Colored left accent for order list rows */
tr.status-row > td:first-child { border-left: 4px solid transparent; }

/* ---------- Tables ---------- */
.table { vertical-align: middle; }
.table > :not(caption) > * > * { padding: .85rem 1rem; }
.table thead th {
    text-transform: uppercase; font-size: .72rem; letter-spacing: .04em;
    color: #8895ad; border-bottom: 1px solid #eef1f7; font-weight: 700;
}

/* ---------- Forms ---------- */
.form-control, .form-select {
    border-radius: 8px; border-color: #e2e8f0; padding: .6rem .85rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--ma-primary);
    box-shadow: 0 0 0 .2rem rgba(94,114,228,.15);
}
.form-label { font-weight: 600; font-size: .85rem; color: #4a5568; }

/* Fix: mobile browsers (especially iOS Safari) hide selected text in styled selects */
.form-select,
.form-control {
    color: #2d3748;
    background-color: #fff;
    -webkit-text-fill-color: #2d3748;
}
.form-select option {
    color: #2d3748;
    background-color: #fff;
}

/* Order form — mobile-friendly item rows */
.oil-picker-wrap { position: relative; }
.oil-picked-name {
    display: none;
    margin-top: .35rem;
    font-size: .875rem;
    font-weight: 600;
    color: var(--ma-primary);
}
.oil-picked-name.show { display: block; }

@media (max-width: 767.98px) {
    /* Native dropdown on mobile — remove Bootstrap SVG arrow to avoid double chevrons */
    .form-select,
    #itemsTable .oil-select {
        appearance: menulist;
        -webkit-appearance: menulist;
        background-image: none !important;
        background-repeat: unset;
        padding-right: .85rem;
        min-height: 44px;
        font-size: 16px;
        width: 100%;
        color: #2d3748 !important;
        background-color: #fff !important;
        -webkit-text-fill-color: #2d3748 !important;
    }

    #itemsTable thead,
    #itemsTable tfoot tr { display: none; }
    #itemsTable tbody { display: block; }
    #itemsTable tr.item-row {
        display: block;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        margin-bottom: .85rem;
        padding: .85rem;
        background: #fafbfe;
        box-shadow: var(--ma-shadow-sm);
    }
    #itemsTable tr.item-row > td {
        display: block;
        width: 100% !important;
        border: none;
        padding: .45rem 0;
        text-align: left !important;
    }
    #itemsTable tr.item-row > td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: .72rem;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: #8895ad;
        margin-bottom: .3rem;
    }
    #itemsTable tr.item-row > td.cell-action {
        text-align: right !important;
        padding-top: .5rem;
    }
    #itemsTable tr.item-row > td.cell-action::before { display: none; }

    /* Grand total bar below items on mobile */
    #itemsTable::after {
        content: '';
        display: block;
    }
    .order-mobile-total {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: .85rem 1rem;
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        margin-top: .5rem;
    }
    .order-form-card .card-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: .65rem;
    }
    .order-form-card .card-header #addRow { width: 100%; }
}

@media (min-width: 768px) {
    .order-mobile-total { display: none !important; }
    .oil-picked-name { display: none !important; }
}

/* ---------- Auth ---------- */
.auth-wrap {
    min-height: 100vh; display: grid; place-items: center;
    background: linear-gradient(135deg,#1f283e,#3a4a7a);
    padding: 1rem;
}
.auth-card { width: 100%; max-width: 410px; border-radius: 18px; }
.auth-logo {
    width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 1rem;
    display: grid; place-items: center; font-size: 1.8rem; color: #fff;
    background: linear-gradient(135deg,#5e72e4,#825ee4);
    box-shadow: 0 8px 20px rgba(94,114,228,.4);
}

.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline:before { content:''; position:absolute; left:11px; top:4px; bottom:4px; width:2px; background:#e6eaf3; }
.timeline li { position: relative; padding: 0 0 1.1rem 2.2rem; }
.timeline li .dot {
    position:absolute; left:3px; top:2px; width:18px; height:18px; border-radius:50%;
    background:#fff; border:3px solid var(--ma-primary);
}
.timeline li small { color:#8895ad; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .topbar .menu-toggle { display: inline-flex; }
    .sidebar-backdrop {
        position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1035; display: none;
    }
    .sidebar-backdrop.show { display: block; }
}
