/* ===== คลังสินค้า — shared design system ===== */

:root {
    --brand-1: #2451c4;
    --brand-2: #5b7fe8;
    --brand-3: #7c5cf0;
    --ink: #1c2536;
    --muted: #8a93a6;
    --muted-2: #aab1c0;
    --bg: #eef1f8;
    --card: #ffffff;
    --border: #e7eaf2;
    --success: #16a34a;
    --success-bg: #e7f7ed;
    --danger: #e0384a;
    --danger-bg: #fdeaec;
    --info: #2f6fed;
    --info-bg: #e9f0ff;
    --warning: #d68b00;
    --warning-bg: #fff4e0;
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 3px rgba(23, 35, 66, .06), 0 1px 2px rgba(23, 35, 66, .04);
    --shadow-md: 0 8px 24px rgba(23, 35, 66, .08), 0 2px 6px rgba(23, 35, 66, .05);
    --shadow-lg: 0 20px 50px rgba(23, 35, 66, .16), 0 6px 16px rgba(23, 35, 66, .08);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    background:
        radial-gradient(1100px 480px at 8% -8%, #e4ebff 0%, rgba(228, 235, 255, 0) 60%),
        radial-gradient(900px 420px at 100% 0%, #eef1ff 0%, rgba(238, 241, 255, 0) 55%),
        var(--bg);
    font-family: 'Prompt', 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* ---------- layout ---------- */
.wrap {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px 64px;
    animation: fadeUp .35s ease both;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.page-title {
    font-weight: 700;
    font-size: 1.28rem;
    margin: 4px 0 18px;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-sub {
    color: var(--muted);
    font-size: .86rem;
    margin-top: -12px;
    margin-bottom: 18px;
}

/* ---------- navbar ---------- */
.app-nav {
    background: linear-gradient(120deg, #16265e 0%, var(--brand-1) 52%, var(--brand-3) 130%);
    padding: 12px 20px;
    margin-bottom: 28px;
    box-shadow: 0 6px 24px rgba(20, 40, 110, .22);
    position: sticky;
    top: 0;
    z-index: 40;
}

.app-nav-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    row-gap: 8px;
}

.app-brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.02rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 6px;
    letter-spacing: .2px;
    white-space: nowrap;
}
.app-brand:hover { color: #fff; }
.app-brand .logo-badge {
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,.16);
    border-radius: 9px;
    font-size: 1rem;
}

.app-nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1 1 auto;
}

.app-nav-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex: 0 0 auto;
}

.nav-pill {
    color: rgba(255,255,255,.86);
    text-decoration: none;
    font-size: .82rem;
    font-weight: 500;
    padding: 7px 13px;
    border-radius: 999px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.10);
    transition: background .15s ease, color .15s ease, transform .15s ease;
    white-space: nowrap;
}
.nav-pill:hover {
    background: rgba(255,255,255,.20);
    color: #fff;
    transform: translateY(-1px);
}
.nav-pill.active {
    background: #fff;
    color: var(--brand-1);
    font-weight: 700;
    border-color: #fff;
}
.nav-pill.accent {
    background: rgba(255,255,255,.92);
    color: var(--brand-1);
    font-weight: 700;
}
.nav-pill.accent:hover { background: #fff; }
.nav-pill.warn {
    background: linear-gradient(120deg, #ffb020, #ff8a00);
    color: #402400;
    border-color: transparent;
    font-weight: 700;
}
.nav-pill.back-pill {
    background: #fff;
    color: var(--brand-1);
    font-weight: 700;
    border-color: #fff;
}
.nav-pill.back-pill:hover { background: #eef2ff; color: var(--brand-1); }
.nav-pill.danger-ghost {
    background: rgba(224,56,74,.18);
    color: #ffd7db;
    border-color: rgba(224,56,74,.3);
}
.nav-pill.danger-ghost:hover { background: rgba(224,56,74,.32); color:#fff; }

.nav-user {
    color: rgba(255,255,255,.75);
    font-size: .8rem;
    padding: 0 4px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.role-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .92rem;
    line-height: 1;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,.22), inset 0 0 0 1.5px rgba(255,255,255,.35);
    flex: 0 0 auto;
}
.role-avatar-user  { background: rgba(255,255,255,.16); }
.role-avatar-admin { background: linear-gradient(135deg, #ff8fc7, #a06bff, #5b7fe8); }
.role-avatar-head  { background: linear-gradient(135deg, #ffd166, #ff8fc7, #a06bff); }
.role-avatar .crown {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    font-size: .8rem;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,.35));
}

.role-tag {
    display: inline-block;
    font-size: .66rem;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 999px;
    letter-spacing: .02em;
    margin-left: 2px;
    vertical-align: middle;
}
.role-tag.role-head  { background: linear-gradient(120deg, #ffb020, #ff8a00); color: #402400; }
.role-tag.role-admin { background: rgba(255,255,255,.18); color: #fff; }

/* ---------- cards ---------- */
.sec-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    padding: 22px 22px;
    margin-bottom: 18px;
    transition: box-shadow .15s ease;
}

.sec-title {
    font-weight: 700;
    font-size: .72rem;
    color: var(--muted);
    letter-spacing: .07em;
    text-transform: uppercase;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sec-title::before {
    content: "";
    width: 4px; height: 14px;
    background: linear-gradient(180deg, var(--brand-2), var(--brand-3));
    border-radius: 3px;
    display: inline-block;
}

/* ---------- buttons ---------- */
.btn {
    border-radius: 999px !important;
    font-weight: 600;
    letter-spacing: .1px;
    transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-sm { border-radius: 999px !important; }

.btn-primary {
    background: linear-gradient(120deg, var(--brand-1), var(--brand-3));
    border: none;
    box-shadow: 0 6px 16px rgba(36, 81, 196, .28);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 8px 20px rgba(36, 81, 196, .34); }

.btn-success {
    background: linear-gradient(120deg, #17a558, #22c56a);
    border: none;
    box-shadow: 0 6px 16px rgba(23, 165, 88, .26);
}
.btn-success:hover { filter: brightness(1.05); }

.btn-danger {
    background: linear-gradient(120deg, #d92e42, #f0596b);
    border: none;
    box-shadow: 0 6px 16px rgba(217, 46, 66, .24);
}
.btn-danger:hover { filter: brightness(1.05); }

.btn-outline-primary, .btn-outline-secondary, .btn-outline-danger {
    background: #fff;
}
.btn-outline-primary { color: var(--brand-1); border-color: #cdd9fb; }
.btn-outline-primary:hover { background: var(--info-bg); color: var(--brand-1); border-color: var(--brand-1); }
.btn-outline-secondary { color: #566078; border-color: var(--border); }
.btn-outline-secondary:hover { background: #f2f4f9; color: var(--ink); border-color: #c9d0e0; }
.btn-outline-danger { color: var(--danger); border-color: #f6c7cd; }
.btn-outline-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

/* ---------- badges ---------- */
.badge-in, .badge-out, .badge-return {
    padding: 4px 13px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    letter-spacing: .02em;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.badge-in     { background: var(--success-bg); color: var(--success); }
.badge-out    { background: var(--danger-bg);  color: var(--danger); }
.badge-return { background: var(--info-bg);    color: var(--info); }

.stock-zero { color: var(--danger); font-weight: 700; }

/* ---------- forms ---------- */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid #dde1ec;
    font-size: .92rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--brand-2);
    box-shadow: 0 0 0 .18rem rgba(91, 127, 232, .18);
}
.form-label { font-size: .82rem; font-weight: 600; color: #4b5468; }

/* ---------- tables ---------- */
.table {
    --bs-table-hover-bg: #f4f6fd;
    vertical-align: middle;
}
.table thead.table-light th, .table thead th {
    background: #f6f7fb !important;
    color: #64708a;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
}
.table td, .table th { border-color: var(--border); }
.table-responsive { border-radius: var(--radius-md); overflow: hidden; }

.prod-img {
    width: 56px; height: 56px;
    object-fit: cover;
    border-radius: 12px;
    background: #eef1fa;
    box-shadow: var(--shadow-sm);
}

/* ---------- pagination ---------- */
.pagination .page-link {
    border-radius: 999px !important;
    margin: 0 3px;
    border: 1px solid var(--border);
    color: #4b5468;
}
.pagination .page-item.active .page-link {
    background: linear-gradient(120deg, var(--brand-1), var(--brand-3));
    border-color: transparent;
}

/* ---------- misc ---------- */
.alert { border-radius: var(--radius-md); border: none; }
.alert-success { background: var(--success-bg); color: #0f7a3d; }
.alert-danger  { background: var(--danger-bg);  color: #b5202f; }
.alert-warning { background: var(--warning-bg); color: #8a5c00; }

.empty-state {
    text-align: center;
    color: var(--muted-2);
    font-size: .88rem;
    padding: 22px 0;
}

.modal-content { border-radius: var(--radius-lg); border: none; box-shadow: var(--shadow-lg); }
.modal-header, .modal-footer { border-color: var(--border); }

a { color: var(--brand-1); }

/* ---------- auth pages ---------- */
body.auth-page {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background:
        radial-gradient(900px 500px at 12% 8%, rgba(124,92,240,.20) 0%, rgba(124,92,240,0) 60%),
        radial-gradient(900px 500px at 90% 90%, rgba(47,111,237,.20) 0%, rgba(47,111,237,0) 55%),
        linear-gradient(160deg, #0f1c46 0%, #16265e 45%, #2451c4 100%);
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 380px; background: #fff; border-radius: 22px;
    box-shadow: var(--shadow-lg);
    padding: 42px 36px;
    animation: fadeUp .4s ease both;
}
.login-avatar {
    width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 18px;
    background: linear-gradient(120deg, var(--brand-1), var(--brand-3));
    display: flex; align-items: center; justify-content: center;
    font-size: 1.7rem; box-shadow: 0 10px 24px rgba(36,81,196,.35);
}
.login-title { text-align: center; margin-bottom: 28px; font-size: 1.28rem; font-weight: 700; color: var(--ink); }
.login-title small { display: block; font-weight: 400; font-size: .78rem; color: var(--muted); margin-top: 4px; }

/* ---------- profile ---------- */
.profile-avatar {
    position: relative;
    width: 120px; height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff8fc7, #a06bff, #5b7fe8);
    display: flex; align-items: center; justify-content: center;
    font-size: 3rem;
    box-shadow: var(--shadow-md), inset 0 0 0 3px rgba(255,255,255,.6);
}
.profile-avatar.is-head { background: linear-gradient(135deg, #ffd166, #ff8fc7, #a06bff); }
.profile-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 3px solid #fff; }
.profile-avatar .crown { position: absolute; top: -26px; left: 50%; transform: translateX(-50%); font-size: 2rem; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.role-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
.preset-opt {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 10px 6px 8px; border-radius: var(--radius-md);
    border: 2px solid var(--border); cursor: pointer; font-size: .74rem; color: var(--muted);
    transition: border-color .12s ease, transform .12s ease, background .12s ease;
}
.preset-opt:hover { transform: translateY(-2px); border-color: #c9d4f5; }
.preset-opt input[type=radio] { display: none; }
.preset-opt img { width: 56px; height: 56px; border-radius: 50%; }
.preset-opt:has(input:checked), .preset-opt.picked { border-color: var(--brand-2); background: var(--info-bg); color: var(--brand-1); font-weight: 600; }
.preset-upload .upload-icon {
    width: 56px; height: 56px; border-radius: 50%; background: #eef1fa;
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
    border: 2px dashed #c9d0e0;
}
a.nav-user { text-decoration: none; border-radius: 999px; padding: 3px 8px 3px 3px; transition: background .15s ease; }
a.nav-user:hover { background: rgba(255,255,255,.14); color: #fff; }
.nav-pill .count-badge {
    display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px;
    border-radius: 999px; background: var(--danger); color: #fff; font-size: .68rem; text-align: center;
}

/* ---------- home: module launcher ---------- */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}
.module-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 26px 24px 22px;
    border-radius: 22px;
    color: #fff;
    text-decoration: none;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: transform .18s ease, box-shadow .18s ease;
    min-height: 220px;
}
.module-card::after {
    content: "";
    position: absolute;
    width: 220px; height: 220px;
    right: -70px; top: -70px;
    border-radius: 50%;
    background: rgba(255,255,255,.12);
}
.module-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); color: #fff; }
.mod-stock { background: linear-gradient(135deg, #2451c4, #5b7fe8); }
.mod-media { background: linear-gradient(135deg, #c2338a, #ff7a8a); }
.mod-ot    { background: linear-gradient(135deg, #0f8a6a, #34c29a); }
.module-icon {
    width: 56px; height: 56px;
    border-radius: 16px;
    background: rgba(255,255,255,.22);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.7rem;
    margin-bottom: 8px;
}
.module-name { font-size: 1.25rem; font-weight: 700; }
.module-desc { font-size: .86rem; opacity: .88; }
.module-stat {
    margin-top: auto;
    padding-top: 14px;
    font-size: .82rem;
    border-top: 1px solid rgba(255,255,255,.25);
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.stat-alert {
    background: #fff; color: var(--danger);
    font-weight: 700; font-size: .72rem;
    padding: 2px 9px; border-radius: 999px;
}

/* ---------- summary stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.stat-grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: var(--ink);
    border-top: 4px solid #c9d0e0;
    transition: transform .12s ease, box-shadow .12s ease;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: var(--ink); }
.stat-card.on { outline: 2px solid var(--brand-2); }
.stat-num { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.stat-card.tone-green  { border-top-color: var(--success); }
.stat-card.tone-green .stat-num { color: var(--success); }
.stat-card.tone-blue   { border-top-color: var(--info); }
.stat-card.tone-blue .stat-num { color: var(--info); }
.stat-card.tone-red    { border-top-color: var(--danger); }
.stat-card.tone-red .stat-num { color: var(--danger); }
.stat-card.tone-yellow { border-top-color: var(--warning); }
.stat-card.tone-yellow .stat-num { color: var(--warning); }

/* ---------- media: status & condition ---------- */
.st-badge, .cond-badge {
    display: inline-block;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: .73rem;
    font-weight: 700;
    white-space: nowrap;
}
.st-free     { background: var(--success-bg); color: var(--success); }
.st-borrowed { background: var(--info-bg); color: var(--info); }
.st-overdue  { background: var(--danger-bg); color: var(--danger); }
.cond-ok    { background: var(--success-bg); color: var(--success); }
.cond-minor { background: #eef1f6; color: #566078; }
.cond-warn  { background: var(--warning-bg); color: #9a6400; }
.cond-bad   { background: var(--danger-bg); color: var(--danger); }
.cond-none  { background: #eef1f6; color: var(--muted); }
.owner-ext  { color: #7c3aed; font-weight: 600; margin-left: 6px; }
td.owner-ext { margin-left: 0; }

.loc-badge {
    display: inline-block;
    padding: 3px 11px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    white-space: nowrap;
}
.loc-yellow { background: #fff3c4; color: #8a6200; }
.loc-aqua   { background: #d5f5f0; color: #0b7a6c; }
.loc-pink   { background: #fde3ef; color: #b02a6b; }
.loc-purple { background: #ece5ff; color: #6b46c1; }
.loc-blue   { background: #e1ecff; color: #2451c4; }
.loc-orange { background: #ffe7d6; color: #b5520f; }
.loc-green  { background: #e3f6e3; color: #2f7d32; }
.loc-gray   { background: #eef1f6; color: #566078; }

.btn-faded {
    background: #f1f3f8;
    color: #b4bac8;
    border: 1px solid #e5e8f0;
    cursor: not-allowed;
    box-shadow: none;
}
.btn-faded:hover { color: #b4bac8; }

.zoomable { cursor: zoom-in; }
.zoom-pop {
    position: fixed;
    z-index: 2000;
    pointer-events: none;
    background: #fff;
    padding: 6px;
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: scale(.96);
    transition: opacity .12s ease, transform .12s ease;
    left: -9999px;
}
.zoom-pop.show { opacity: 1; transform: scale(1); }
.zoom-pop img { display: block; max-width: 340px; max-height: 340px; border-radius: 10px; }

.pick-list { max-height: 440px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
.pick-group { font-size: .72rem; font-weight: 700; color: var(--muted); letter-spacing: .03em; background: #f6f7fb; padding: 6px 12px; position: sticky; top: 0; z-index: 1; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-top: 1px solid var(--border); cursor: pointer; margin: 0; }
.pick-item:hover { background: #f4f6fd; }
.pick-item > img, .pick-item > .ph { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; background: #eef1fa; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.pick-item.checked { background: var(--info-bg); }

/* ---------- OT ---------- */
.hrs-ot    { color: var(--success); }
.hrs-leave { color: var(--danger); }
.th-ot     { background: var(--success-bg) !important; color: #0f7a3d !important; }
.th-leave  { background: var(--danger-bg) !important; color: #b5202f !important; }
.ot-table thead th { vertical-align: middle; }
.bal-badge {
    display: inline-block;
    min-width: 64px;
    text-align: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: .85rem;
    background: #eef1f6;
    color: #566078;
}
.bal-badge.pos { background: var(--success-bg); color: var(--success); }
.bal-badge.neg { background: var(--danger-bg); color: var(--danger); }
.row-mine td { background: #f3f7ff; }
.my-balance {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 20px 24px;
    margin-bottom: 18px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, #0f8a6a, #34c29a);
    color: #fff;
    text-decoration: none;
    box-shadow: var(--shadow-md);
}
.my-balance:hover { color: #fff; }
.my-balance.neg { background: linear-gradient(135deg, #b5202f, #f0596b); }
.my-balance-label { font-size: .85rem; opacity: .9; }
.my-balance-num { font-size: 2.1rem; font-weight: 700; line-height: 1.1; }
.my-balance-num small { font-size: .9rem; font-weight: 500; }
.my-balance-sub { font-size: .8rem; opacity: .85; }
.type-toggle { display: flex; gap: 8px; flex-wrap: wrap; }
.team-row td {
    background: #f1f4fb !important;
    font-weight: 700; font-size: .78rem; color: #4b5468;
    letter-spacing: .02em;
}
.calc-box {
    border-radius: var(--radius-md);
    padding: 14px 18px;
    background: var(--success-bg);
    border: 1px solid #c6ecd3;
}
.calc-box.is-leave { background: var(--danger-bg); border-color: #f6c7cd; }
.calc-box.is-zero { background: #f1f3f8; border-color: var(--border); }
.calc-label { font-size: .78rem; color: var(--muted); }
.calc-num { font-size: 2rem; font-weight: 700; line-height: 1.15; color: var(--success); }
.calc-box.is-leave .calc-num { color: var(--danger); }
.calc-box.is-zero .calc-num { color: var(--muted); }
.calc-note { font-size: .82rem; color: #4b5468; }

@media (max-width: 576px) {
    .sec-card { padding: 16px; border-radius: var(--radius-md); }
    .app-nav { padding: 10px 12px; }
    .module-card { min-height: 0; }
}
