/* ============ ระบบเคลมสินค้า — Stylesheet ============ */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;600;700&display=swap');

:root {
    --brand:        #1f5f8b;
    --brand-dark:   #164a6e;
    --brand-light:  #e8f1f8;
    --bg:           #f4f6f9;
    --card:         #ffffff;
    --text:         #24303a;
    --muted:        #74818c;
    --border:       #e2e7ec;
    --danger:       #c0392b;
    --ok:           #1e8f57;

    --st-open:      #d97706;
    --st-progress:  #2563eb;
    --st-done:      #1e8f57;
    --st-cancel:    #98a2ad;

    --radius: 10px;
    --shadow: 0 1px 3px rgba(20,40,60,.08), 0 1px 2px rgba(20,40,60,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Sarabun', -apple-system, 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
code { background: #eef2f6; padding: 1px 6px; border-radius: 5px; font-size: .9em; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px; background: linear-gradient(135deg, #1f5f8b 0%, #2b7ba8 100%);
}
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-card h1 { margin: 0 0 4px; font-size: 26px; color: var(--brand-dark); }
.login-card .sub { margin: 0 0 22px; color: var(--muted); }

/* ---------- Card ---------- */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 22px; margin-bottom: 18px;
}

/* ---------- Forms ---------- */
.form-row { margin-bottom: 14px; text-align: left; }
.form-row label, .lbl {
    display: block; font-weight: 600; font-size: 13.5px;
    color: #445; margin-bottom: 5px;
}
input[type=text], input[type=password], input[type=date], input[type=number],
select, textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border);
    border-radius: 8px; font-family: inherit; font-size: 14.5px; background: #fff;
    color: var(--text); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(31,95,139,.12);
}
textarea { resize: vertical; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
    font-family: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: #445; }
.btn-ghost:hover { background: #f2f5f8; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a5321f; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* ---------- Boxes ---------- */
.error-box {
    background: #fdecea; border: 1px solid #f5c6c0; color: #b23c2c;
    padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; text-align: left; font-size: 14px;
}
.ok-box {
    background: #e7f6ee; border: 1px solid #b8e2ca; color: #1e7a4b;
    padding: 11px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
}
.readonly-box {
    background: #f7f9fb; border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 12px; min-height: 42px; white-space: pre-wrap;
}

/* ---------- Topbar ---------- */
.topbar { background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.topbar-inner {
    max-width: 1180px; margin: 0 auto; padding: 0 20px; height: 56px;
    display: flex; align-items: center; gap: 22px;
}
.brand { font-size: 17px; font-weight: 700; white-space: nowrap; }
.mainnav { display: flex; gap: 6px; flex: 1; }
.mainnav a {
    color: #dceaf3; padding: 7px 13px; border-radius: 7px; font-weight: 500; font-size: 14.5px;
}
.mainnav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.2); color: #fff; }
.userbox { display: flex; align-items: center; gap: 12px; }
.uinfo { text-align: right; line-height: 1.25; }
.uname { display: block; font-size: 14px; font-weight: 600; }
.urole {
    display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 20px;
    background: rgba(255,255,255,.2);
}
.role-admin { background: #c0392b; }
.role-purchase { background: #2563eb; }
.userbox .btn-ghost { background: rgba(255,255,255,.14); border-color: transparent; color: #fff; }
.userbox .btn-ghost:hover { background: rgba(255,255,255,.26); }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 22px auto; padding: 0 20px; }
.page-head { margin-bottom: 18px; }
.page-head h2 { margin: 0 0 3px; font-size: 22px; }
.page-head .muted { margin: 0; }
.muted { color: var(--muted); font-size: 13.5px; }
.with-actions { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; }
.site-footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 24px 0 30px; }

.section-title {
    font-weight: 700; font-size: 15px; color: var(--brand-dark);
    padding: 8px 0 8px 12px; border-left: 4px solid var(--brand);
    background: var(--brand-light); border-radius: 0 6px 6px 0; margin-bottom: 16px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 20px; }
.info-grid .lbl { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 2px; }

/* ---------- Stat cards ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; text-align: center; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 3px; border-top: 3px solid var(--muted);
}
.stat:hover { border-color: var(--brand); }
.stat.sel { outline: 2px solid var(--brand); }
.stat .num { font-size: 24px; font-weight: 700; }
.stat .cap { font-size: 12.5px; color: var(--muted); }
.stat.st-open    { border-top-color: var(--st-open); }
.stat.st-progress{ border-top-color: var(--st-progress); }
.stat.st-done    { border-top-color: var(--st-done); }
.stat.st-cancel  { border-top-color: var(--st-cancel); }

/* ---------- Search ---------- */
.searchbar { display: flex; gap: 8px; margin-bottom: 16px; }
.searchbar input[type=text] { max-width: 420px; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.list-table th, .list-table td {
    padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px;
}
.list-table thead th { background: #f7f9fb; color: #556; font-weight: 600; font-size: 13px; white-space: nowrap; }
.list-table tbody tr:hover { background: #f9fbfc; }
.list-table .center { text-align: center; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 26px 0; }

.items-table th, .items-table td {
    border: 1px solid var(--border); padding: 7px 8px; font-size: 13.5px; vertical-align: top;
}
.items-table thead th { background: #f2f5f8; font-weight: 600; font-size: 12.5px; }
.items-table input, .items-table textarea, .items-table select { font-size: 13px; padding: 6px 8px; }
.items-table.view td.wrap { max-width: 220px; white-space: pre-wrap; }
.handling-cell .radio-line { display: block; font-size: 12.5px; margin-bottom: 3px; font-weight: 400; cursor: pointer; }
.handling-cell .prt { margin-top: 4px; }
.btn-del {
    background: #fbeae7; color: var(--danger); border: none; border-radius: 6px;
    width: 28px; height: 28px; cursor: pointer; font-weight: 700;
}
.btn-del:hover { background: #f6d5d0; }

/* ---------- Status badge ---------- */
.status-badge {
    display: inline-block; padding: 3px 11px; border-radius: 20px;
    font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap;
}
.st-open    { background: var(--st-open); }
.st-progress{ background: var(--st-progress); }
.st-done    { background: var(--st-done); }
.st-cancel  { background: var(--st-cancel); }

/* ---------- Images ---------- */
.thumb-sm { max-width: 54px; max-height: 54px; border-radius: 6px; border: 1px solid var(--border); object-fit: cover; }
.img-wrap .thumb { margin-top: 6px; }
.img-wrap img { max-width: 90px; border-radius: 6px; display: block; margin-bottom: 3px; }
.img-wrap .rm { font-size: 11.5px; color: var(--danger); font-weight: 400; }

/* ---------- Form bits ---------- */
.claim-form .form-actions, .form-actions {
    display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px;
}
#addRow { margin-top: 12px; }
.note-remark { color: var(--danger); font-size: 12.5px; margin: 14px 0 0; }
.inline-role-form { display: flex; gap: 8px; align-items: center; }
.inline-role-form select { max-width: 240px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.timeline li:last-child { border-bottom: none; }
.tl-time { color: var(--muted); font-size: 12px; font-family: ui-monospace, monospace; }
.tl-act { font-weight: 600; }
.tl-note { color: #556; }
.tl-by { color: var(--muted); font-size: 12px; margin-left: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .info-grid { grid-template-columns: 1fr 1fr; }
    .topbar-inner { gap: 12px; }
    .uinfo { display: none; }
}
@media (max-width: 560px) {
    .grid-4, .grid-2, .info-grid { grid-template-columns: 1fr; }
    .mainnav a { padding: 6px 9px; font-size: 13.5px; }
    .brand span { display: none; }
}
