:root {
  --blue: #1d4ed8;
  --blue-dark: #1e3a8a;
  --blue-light: #eff6ff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
  font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Thai', sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--gray-50); color: var(--gray-900); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--blue); text-decoration: none; }

/* --- Login --- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--blue-dark), var(--blue)); padding: 16px; }
.login-card { background: white; border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-logo { width: 56px; height: 56px; border-radius: 14px; background: var(--blue); color: white; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; margin-bottom: 14px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.muted { color: var(--gray-500); font-size: 13px; margin: 0 0 20px; }
.login-card form label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--gray-700); }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 14px; }
.login-card input:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.login-hint { margin-top: 18px; font-size: 11px; color: var(--gray-500); background: var(--gray-100); padding: 10px 12px; border-radius: 8px; line-height: 1.6; }
.form-error { margin-top: 10px; color: var(--red); font-size: 13px; background: #fef2f2; padding: 8px 10px; border-radius: 6px; }

/* --- App shell --- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--blue-dark); color: white; display: flex; align-items: center; padding: 0 16px; gap: 12px; flex-shrink: 0; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 16px; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-badge { font-size: 13px; opacity: .9; }
.icon-btn { background: none; border: none; color: white; font-size: 20px; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: rgba(255,255,255,.1); }
.only-mobile { display: none; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 220px; background: white; border-right: 1px solid var(--gray-200); padding: 12px; flex-shrink: 0; overflow-y: auto; }
.sidebar a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--gray-700); font-size: 14px; font-weight: 500; margin-bottom: 2px; }
.sidebar a:hover { background: var(--gray-100); }
.sidebar a.active { background: var(--blue-light); color: var(--blue); font-weight: 700; }
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-500); margin: 14px 8px 6px; }
.badge-count { background: var(--red); color: white; font-size: 11px; border-radius: 10px; padding: 1px 7px; margin-left: auto; }

.main-content { flex: 1; padding: 20px 24px; overflow-y: auto; min-height: 0; }

/* --- Generic components --- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h2 { margin: 0; font-size: 20px; }
.page-header .sub { color: var(--gray-500); font-size: 13px; margin-top: 2px; }

.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat-card .label { font-size: 12px; color: var(--gray-500); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-card.warn .value { color: var(--amber); }
.stat-card.danger .value { color: var(--red); }
.stat-card.good .value { color: var(--green); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table th { text-align: left; padding: 10px 12px; background: var(--gray-100); color: var(--gray-700); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
table tr:hover td { background: var(--gray-50); }
.table-wrap { overflow-x: auto; }

.btn { border: 1px solid var(--gray-300); background: white; padding: 8px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--gray-700); }
.btn:hover { background: var(--gray-100); }
.btn-primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-danger { background: var(--red); color: white; border-color: var(--red); }
.btn-success { background: var(--green); color: white; border-color: var(--green); }
.btn-ghost { background: transparent; border: none; color: white; }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.pill-pending { background: #fef3c7; color: #92400e; }
.pill-issued { background: #dcfce7; color: #166534; }
.pill-partial { background: #dbeafe; color: #1e40af; }
.pill-rejected { background: #fee2e2; color: #991b1b; }
.pill-cancelled { background: #f1f5f9; color: #475569; }
.pill-instock { background: #dcfce7; color: #166534; }
.pill-assigned { background: #dbeafe; color: #1e40af; }
.pill-repair { background: #fef3c7; color: #92400e; }
.pill-retired { background: #f1f5f9; color: #475569; }
.pill-lost { background: #fee2e2; color: #991b1b; }
.pill-open { background: #fef3c7; color: #92400e; }
.pill-resolved { background: #dcfce7; color: #166534; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: white; border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal h3 { margin: 0 0 16px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--gray-700); }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 14px; font-family: inherit; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.line-item-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.line-item-row select { flex: 2; }
.line-item-row input { flex: 1; }

.toast-root { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--gray-900); color: white; padding: 10px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: var(--shadow); animation: slidein .2s ease; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.empty-state { text-align: center; padding: 40px 20px; color: var(--gray-500); }
.search-input { padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: 8px; font-size: 13.5px; min-width: 220px; }
.flex { display: flex; gap: 8px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.low-stock-row td { background: #fff7ed; }

@media (max-width: 760px) {
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; left: 0; top: 56px; bottom: 0; z-index: 30; transform: translateX(-100%); transition: transform .2s; width: 240px; }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .main-content { padding: 14px; }
}
