/* ============================================================
   AS Broker Back Office — Shared Stylesheet
   CI อ้างอิงจาก asbroker.co.th (ส.ค. 2026)
   ห้าม inline <style> ในแต่ละ view — เพิ่ม/แก้สไตล์ที่ไฟล์นี้ที่เดียว
   ============================================================ */

:root {
    /* ── Brand ─────────────────────────────────────────── */
    --asb-primary:       #009989;   /* teal เข้ม — พื้นหลัง header ของเว็บบริษัท */
    --asb-primary-dark:  #007A6D;
    --asb-primary-light: #0FABA0;   /* teal ในโลโก้ */
    --asb-primary-pale:  #E6F5F3;
    --asb-yellow:        #FFDD15;   /* สีเด่นในโลโก้ (47% ของพิกเซล) */
    --asb-yellow-dark:   #E0C000;
    --asb-orange:        #F05922;

    /* ── Text & surface (light theme) ──────────────────── */
    --asb-text:      #4A4A4A;
    --asb-heading:   #1A1A1A;
    --asb-muted:     #888888;
    --asb-faint:     #AAAAAA;
    --asb-bg:        #F5F6F7;
    --asb-surface:   #FFFFFF;
    --asb-border:    #E4E6E8;
    --asb-border-dk: #CFD3D6;

    /* ── Status ────────────────────────────────────────── */
    --asb-success:   #1E9E5A;
    --asb-warning:   #E8A317;
    --asb-danger:    #D64535;
    --asb-info:      #3B7DD8;

    /* ── Shape & type ──────────────────────────────────── */
    --asb-radius:    12px;
    --asb-radius-sm: 8px;
    --asb-shadow:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --asb-shadow-lg: 0 8px 28px rgba(0,0,0,.10);
    --asb-font:      "Mitr", "Barlow Condensed", "Segoe UI", sans-serif;
    --asb-font-num:  "Barlow Condensed", "Mitr", sans-serif;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--asb-font);
    font-weight: 300;
    font-size: 14px;
    line-height: 1.8;
    color: var(--asb-text);
    background: var(--asb-bg);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { color: var(--asb-heading); font-weight: 400; margin: 0 0 12px; line-height: 1.4; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
a { color: var(--asb-primary); text-decoration: none; transition: color .15s; }
a:hover { color: var(--asb-primary-dark); }
p { margin: 0 0 12px; }

/* ── Layout ────────────────────────────────────────────── */
.page      { max-width: 1240px; margin: 0 auto; padding: 24px 28px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .subtitle { color: var(--asb-muted); font-size: 13px; margin: 0; }

/* ── Navbar ────────────────────────────────────────────── */
.navbar {
    background: var(--asb-primary);
    border-bottom: 3px solid var(--asb-yellow);
    padding: 0 28px;
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 100;
}
.navbar .brand { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.navbar .brand img { height: 38px; width: auto; display: block; }
.navbar .brand-text { display: flex; flex-direction: column; line-height: 1.15; border-left: 1px solid rgba(255,255,255,.28); padding-left: 12px; }
.navbar .brand-text .company { color: rgba(255,255,255,.75); font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase; }
.navbar .brand-text .product { color: #fff; font-size: 15px; font-weight: 400; letter-spacing: .5px; }
.navbar .nav-left  { display: flex; align-items: center; gap: 28px; }
.navbar .nav-links { display: flex; gap: 4px; }
.navbar .nav-links a {
    color: rgba(255,255,255,.82); font-size: 14px; padding: 20px 14px; display: block;
    border-bottom: 3px solid transparent; margin-bottom: -3px;
}
.navbar .nav-links a:hover  { color: #fff; background: rgba(255,255,255,.08); }
.navbar .nav-links a.active { color: #fff; border-bottom-color: var(--asb-yellow); }

.nav-user { display: flex; align-items: center; gap: 14px; }
.nav-user .who { text-align: right; line-height: 1.25; }
.nav-user .who .name { color: #fff; font-size: 13px; display: block; }
.nav-user .who .role { color: var(--asb-yellow); font-size: 11px; }
.nav-user .logout {
    color: rgba(255,255,255,.85); font-size: 13px; border: 1px solid rgba(255,255,255,.35);
    padding: 5px 14px; border-radius: 20px; background: none; cursor: pointer;
    font-family: var(--asb-font); font-weight: 300; transition: all .15s;
}
.nav-user .logout:hover { background: rgba(255,255,255,.15); color: #fff; border-color: #fff; }

/* ── Card ──────────────────────────────────────────────── */
.card {
    background: var(--asb-surface); border: 1px solid var(--asb-border);
    border-radius: var(--asb-radius); box-shadow: var(--asb-shadow);
    padding: 22px 24px; margin-bottom: 20px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px;
             padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--asb-border); }
.card-head h2, .card-head h3 { margin: 0; }

/* ── Form ──────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--asb-heading); margin-bottom: 6px; }
.field label .req { color: var(--asb-danger); }
.input, input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
    width: 100%; padding: 10px 14px;
    font-family: var(--asb-font); font-weight: 300; font-size: 14px; color: var(--asb-text);
    background: var(--asb-surface); border: 1px solid var(--asb-border-dk);
    border-radius: var(--asb-radius-sm); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
    border-color: var(--asb-primary);
    box-shadow: 0 0 0 3px rgba(0,153,137,.14);
}
.input::placeholder, input::placeholder { color: var(--asb-faint); }
.field-hint { font-size: 12px; color: var(--asb-muted); margin-top: 4px; }

/* ── Button ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 22px; border: 1px solid transparent; border-radius: var(--asb-radius);
    font-family: var(--asb-font); font-weight: 400; font-size: 14px; line-height: 1.4;
    cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.btn-primary   { background: var(--asb-primary); color: #fff; }
.btn-primary:hover { background: var(--asb-primary-dark); color: #fff; }
.btn-accent    { background: var(--asb-yellow); color: #1A1A1A; }
.btn-accent:hover  { background: var(--asb-yellow-dark); color: #1A1A1A; }
.btn-outline   { background: transparent; color: var(--asb-primary); border-color: var(--asb-primary); }
.btn-outline:hover { background: var(--asb-primary-pale); }
.btn-ghost     { background: var(--asb-surface); color: var(--asb-text); border-color: var(--asb-border-dk); }
.btn-ghost:hover   { border-color: var(--asb-muted); }
.btn-block     { width: 100%; }
.btn:disabled  { opacity: .55; cursor: not-allowed; }

/* ── Badge ─────────────────────────────────────────────── */
.badge {
    display: inline-block; padding: 2px 12px; border-radius: 20px;
    font-size: 12px; font-weight: 400; border: 1px solid transparent; white-space: nowrap;
}
.badge-teal   { background: var(--asb-primary-pale); color: var(--asb-primary-dark); border-color: #B6E3DD; }
.badge-yellow { background: #FFF8D6; color: #8A6D00; border-color: #F2E08A; }
.badge-grey   { background: #F0F1F2; color: #5F676D; border-color: #DDE0E2; }
.badge-green  { background: #E6F5EC; color: #17703F; border-color: #B7E0C7; }
.badge-red    { background: #FDECEA; color: #A32C1F; border-color: #F5C2BB; }

/* ── Alert ─────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--asb-radius-sm); font-size: 13px;
         border: 1px solid transparent; margin-bottom: 16px; }
.alert-error   { background: #FDECEA; color: #A32C1F; border-color: #F5C2BB; }
.alert-success { background: #E6F5EC; color: #17703F; border-color: #B7E0C7; }
.alert-info    { background: var(--asb-primary-pale); color: var(--asb-primary-dark); border-color: #B6E3DD; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* ── Table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--asb-border); border-radius: var(--asb-radius); background: var(--asb-surface); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
    background: #FAFBFB; color: var(--asb-heading); font-weight: 400; text-align: left;
    padding: 12px 14px; border-bottom: 1px solid var(--asb-border); white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid #F0F1F2; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #FAFCFC; }
table.data .num { text-align: right; font-family: var(--asb-font-num); font-size: 15px; font-variant-numeric: tabular-nums; }

/* ── Login page ────────────────────────────────────────── */
.login-wrap { display: flex; min-height: 100vh; }
.login-brand {
    flex: 0 0 46%; background: var(--asb-primary); color: #fff;
    display: flex; flex-direction: column; justify-content: center; padding: 60px 64px;
    position: relative; overflow: hidden;
}
.login-brand::after {
    content: ""; position: absolute; right: -120px; bottom: -120px;
    width: 380px; height: 380px; border-radius: 50%;
    background: rgba(255,255,255,.05);
}
.login-brand .logo { height: 92px; width: auto; margin-bottom: 32px; align-self: flex-start; }
.login-brand h1 { color: #fff; font-size: 27px; font-weight: 400; margin-bottom: 6px; }
.login-brand .company-en { color: rgba(255,255,255,.7); font-size: 13px; letter-spacing: 1.6px;
                           text-transform: uppercase; margin-bottom: 30px; }
.login-brand .tagline {
    font-size: 17px; font-weight: 300; color: #fff; line-height: 1.7;
    border-left: 3px solid var(--asb-yellow); padding-left: 18px; max-width: 380px;
}
.login-brand .sys-name { margin-top: auto; padding-top: 40px; color: rgba(255,255,255,.65); font-size: 12px; }

.login-form-side { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 28px; background: var(--asb-surface); }
.login-box { width: 100%; max-width: 380px; }
.login-box .logo-sm { display: none; }
.login-box h2 { font-size: 22px; margin-bottom: 4px; }
.login-box .sub { color: var(--asb-muted); font-size: 13px; margin-bottom: 26px; }
.login-foot { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--asb-border);
              font-size: 11px; color: var(--asb-faint); line-height: 1.7; }

@media (max-width: 860px) {
    .login-brand { display: none; }
    .login-box .logo-sm { display: block; height: 64px; margin: 0 auto 22px; }
}

/* ── Error page ────────────────────────────────────────── */
.err-wrap { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 20px; }
.err-code { font-family: var(--asb-font-num); font-size: 86px; font-weight: 600; color: var(--asb-primary); line-height: 1; }
.err-msg  { font-size: 18px; color: var(--asb-heading); margin: 8px 0 6px; }
.err-hint { color: var(--asb-muted); font-size: 13px; margin-bottom: 24px; }

/* ── Utilities ─────────────────────────────────────────── */
.muted    { color: var(--asb-muted); }
.text-sm  { font-size: 12px; }
.num      { font-family: var(--asb-font-num); font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; }
.stat .label { font-size: 12px; color: var(--asb-muted); }
.stat .value { font-family: var(--asb-font-num); font-size: 30px; font-weight: 600; color: var(--asb-primary); line-height: 1.2; }

/* ── Form grid (ฟอร์มหลายคอลัมน์) ──────────────────────── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 20px; }

/* ── ปุ่มขนาดเล็กในตาราง ───────────────────────────────── */
.btn-xs { padding: 3px 12px; font-size: 12px; border-radius: 20px; }
table.data td.actions { white-space: nowrap; }
table.data td.actions form { display: inline; }
table.data tr.row-inactive td { opacity: .5; }

/* ── แถวซ้ำในหน้าตรวจสอบก่อนบันทึก ─────────────────────── */
table.data tr.row-dup td { background: #FAFBFB; color: var(--asb-faint); }
table.data tr.row-dup td .badge { opacity: .8; }
#preview-table.hide-dup tr.row-dup { display: none; }
.table-wrap.scroll-y { max-height: 560px; overflow-y: auto; }
.table-wrap.scroll-y table.data thead th { position: sticky; top: 0; z-index: 2; }

/* ── Dropzone (แนบไฟล์) ────────────────────────────────── */
.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    padding: 34px 20px; text-align: center; cursor: pointer;
    border: 2px dashed var(--asb-border-dk); border-radius: var(--asb-radius);
    background: #FCFDFD; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--asb-primary); background: var(--asb-primary-pale); }
.dropzone.has-file { border-color: var(--asb-primary); border-style: solid; background: var(--asb-primary-pale); }
.dropzone .dz-icon { font-size: 30px; line-height: 1; }
.dropzone .dz-text { color: var(--asb-heading); font-size: 14px; }
.dropzone .dz-hint { color: var(--asb-muted); font-size: 12px; }

/* ── Filter bar ────────────────────────────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 16px; }
.filter-bar .field { margin-bottom: 12px; min-width: 150px; }
.filter-bar .field-grow { flex: 1; min-width: 220px; }
.filter-bar .field-actions { display: flex; gap: 8px; }

/* ── แถบปุ่มยืนยัน ─────────────────────────────────────── */
.action-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.action-bar form { margin: 0; }

/* ── Pagination ────────────────────────────────────────── */
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }

/* ── Progress bar (ความคืบหน้าการกระทบยอด) ─────────────── */
.progress {
    display: block; height: 7px; border-radius: 4px;
    background: #EDEFF0; overflow: hidden; margin: 6px 0 2px;
}
.progress .bar { display: block; height: 100%; border-radius: 4px; transition: width .3s; }
.progress .bar.none    { background: var(--asb-border-dk); }
.progress .bar.partial { background: var(--asb-yellow); }
.progress .bar.done    { background: var(--asb-success); }

/* stat card ที่มี progress bar ไม่ต้องเว้นล่างมาก */
.card.stat .progress { margin-bottom: 0; }

/* ── User menu (dropdown บน navbar) ─────────────────────── */
.user-menu { position: relative; }
.user-trigger {
    display: flex; align-items: center; gap: 10px;
    background: none; border: 1px solid rgba(255,255,255,.28); border-radius: 22px;
    padding: 5px 14px; cursor: pointer; font-family: var(--asb-font); transition: all .15s;
}
.user-trigger:hover { background: rgba(255,255,255,.12); border-color: #fff; }
.user-trigger .caret { color: rgba(255,255,255,.7); font-size: 11px; }
.user-dropdown {
    display: none; position: absolute; right: 0; top: calc(100% + 10px);
    min-width: 230px; background: var(--asb-surface);
    border: 1px solid var(--asb-border); border-radius: var(--asb-radius);
    box-shadow: var(--asb-shadow-lg); overflow: hidden; z-index: 200;
}
.user-menu.open .user-dropdown { display: block; }
.user-dropdown .dd-head { padding: 12px 16px; background: #FAFBFB; border-bottom: 1px solid var(--asb-border); }
.user-dropdown .dd-name { color: var(--asb-heading); font-size: 14px; }
.user-dropdown .dd-sub  { color: var(--asb-muted); font-size: 12px; }
.user-dropdown a,
.user-dropdown button {
    display: block; width: 100%; text-align: left; padding: 11px 16px;
    font-family: var(--asb-font); font-weight: 300; font-size: 14px;
    color: var(--asb-text); background: none; border: none; cursor: pointer;
    border-top: 1px solid #F2F3F4; transition: background .12s;
}
.user-dropdown a:first-of-type { border-top: none; }
.user-dropdown a:hover,
.user-dropdown button:hover { background: var(--asb-primary-pale); color: var(--asb-primary-dark); }
.user-dropdown form { margin: 0; }

/* ── หน้าแบบแคบ (ฟอร์มเดี่ยว) ──────────────────────────── */
.page-narrow { max-width: 720px; }

/* ── checkbox / radio แบบมี label ข้างหลัง ───────────────── */
.check-line { display: flex; align-items: center; gap: 9px; font-size: 14px;
              color: var(--asb-text); margin-bottom: 6px; cursor: pointer; }
.check-line input { width: auto; margin: 0; }

/* ── กล่องแสดงรหัสผ่านชั่วคราว ──────────────────────────── */
.credential-box {
    background: var(--asb-surface); border: 1px solid #B6E3DD;
    border-radius: var(--asb-radius-sm); padding: 12px 16px; margin: 10px 0;
    display: flex; flex-wrap: wrap; gap: 8px 32px;
}
.credential-box code {
    font-family: Consolas, "Courier New", monospace; font-size: 15px;
    background: #F5F6F7; border: 1px solid var(--asb-border);
    padding: 2px 10px; border-radius: 6px; color: var(--asb-heading);
    user-select: all;
}

/* ── เกณฑ์รหัสผ่าน (แสดงสดขณะพิมพ์) ─────────────────────── */
.pw-rules { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; }
.pw-rules span { font-size: 12px; color: var(--asb-faint); }
.pw-rules span.pass { color: var(--asb-success); }
.hint-ok  { color: var(--asb-success) !important; }
.hint-bad { color: var(--asb-danger)  !important; }
