/* Components: buttons, forms, cards, tables, badges, alerts, modal, toast, pager */

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 18px; border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--brand-600); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-med) var(--ease), background var(--t-fast); box-shadow: 0 1px 2px rgba(79,70,229,.3), 0 6px 14px -6px rgba(79,70,229,.55); }
.btn:hover { background: var(--brand-700); text-decoration: none; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn[disabled], .btn.is-busy { opacity: .6; pointer-events: none; }
.btn-secondary { background: var(--surface); color: var(--ink-800); border-color: var(--line); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--brand-600); box-shadow: none; }
.btn-ghost:hover { background: var(--brand-50); }
.btn-danger { background: var(--err); box-shadow: 0 6px 14px -6px rgba(220,38,38,.55); } .btn-danger:hover { background: #b91c1c; }
.btn-ok { background: var(--ok); box-shadow: 0 6px 14px -6px rgba(22,163,74,.55); } .btn-ok:hover { background: #15803d; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--r-sm); }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 16px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; } .btn-sm.btn-icon { width: 34px; }

.field { margin-bottom: var(--s4); }
.field > label, .label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-700); margin-bottom: 6px; }
.req::after { content: " *"; color: var(--err); }
.input, .select, .textarea { width: 100%; min-height: 44px; padding: 10px 14px; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast); appearance: none; }
.select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 38px; }
.textarea { min-height: 96px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-500) 18%, transparent); }
.input::placeholder { color: var(--ink-400); }
.input-sm { min-height: 36px; padding: 6px 10px; border-radius: var(--r-sm); font-size: 14px; }
.input-group { display: flex; gap: 8px; } .input-group .input { flex: 1; }
.help { font-size: 12px; color: var(--ink-500); margin-top: 4px; }
.field-error { font-size: 12px; color: var(--err); margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-600); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 40px; height: 24px; border-radius: 99px; background: var(--ink-300); position: relative; transition: background var(--t-med); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--t-med) var(--ease); }
.switch input:checked + i { background: var(--brand-600); } .switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 3px solid color-mix(in srgb, var(--brand-500) 45%, transparent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: 20px; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.stack > * + * { margin-top: var(--s4); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; } .between { justify-content: space-between; } .grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--s4); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } .grid-keep2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-500); font-weight: 700; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--brand-50) 55%, transparent); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 720px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .table-cards td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: right !important; }
  .table-cards td::before { content: attr(data-label); color: var(--ink-500); font-size: 12px; font-weight: 600; text-align: left; }
  .table-cards td:not([data-label])::before { content: none; }
}

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-700); border: 1px solid var(--line); }
.badge-ok { background: var(--ok-50); color: var(--ok); border-color: transparent; } .badge-warn { background: var(--warn-50); color: var(--warn); border-color: transparent; }
.badge-err { background: var(--err-50); color: var(--err); border-color: transparent; } .badge-info { background: var(--info-50); color: var(--info); border-color: transparent; }
.badge-brand { background: var(--brand-50); color: var(--brand-600); border-color: transparent; } .badge-muted { color: var(--ink-500); }

.alert { display: flex; gap: 10px; padding: 12px 16px; border-radius: var(--r-md); font-size: 14px; border: 1px solid transparent; margin-bottom: var(--s4); }
.alert-ok { background: var(--ok-50); color: #166534; } .alert-err, .alert-error { background: var(--err-50); color: #991b1b; }
.alert-warn { background: var(--warn-50); color: #92400e; } .alert-info { background: var(--info-50); color: #075985; }
:root[data-theme="dark"] .alert { color: var(--ink-800); }

.kpi { padding: 18px 20px; position: relative; overflow: hidden; }
.kpi .k-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-500); }
.kpi .k-value { font-size: 28px; font-weight: 800; color: var(--ink-900); margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .k-sub { font-size: 12px; color: var(--ink-500); }
.kpi::after { content: ""; position: absolute; right: -24px; top: -24px; width: 90px; height: 90px; border-radius: 50%; background: var(--brand-50); }
.kpi.is-ok::after { background: var(--ok-50); } .kpi.is-warn::after { background: var(--warn-50); }

.empty { text-align: center; padding: 48px 20px; color: var(--ink-500); }
.empty .e-ico { width: 64px; height: 64px; border-radius: 50%; background: var(--brand-50); color: var(--brand-600); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { color: var(--ink-800); margin-bottom: 6px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; } .chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); color: var(--ink-700); font-weight: 600; font-size: 13px; white-space: nowrap; cursor: pointer; transition: all var(--t-fast); }
.chip:hover { text-decoration: none; border-color: var(--brand-500); color: var(--brand-600); }
.chip.is-on { background: var(--brand-600); color: #fff; border-color: var(--brand-600); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: var(--s4); overflow-x: auto; }
.tabs a { padding: 10px 14px; font-weight: 600; color: var(--ink-500); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.is-on { color: var(--brand-600); border-color: var(--brand-600); } .tabs a:hover { text-decoration: none; color: var(--ink-800); }

.pager { display: flex; gap: 6px; justify-content: center; margin: 20px 0 4px; }
.pager a { min-width: 38px; height: 38px; display: grid; place-items: center; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--line); color: var(--ink-700); font-weight: 600; }
.pager a.is-cur { background: var(--brand-600); color: #fff; border-color: var(--brand-600); } .pager a:hover { text-decoration: none; border-color: var(--brand-500); }

.modal-back { position: fixed; inset: 0; background: rgba(11,18,32,.55); backdrop-filter: blur(4px); z-index: 90; display: flex; align-items: flex-start; justify-content: center; padding: max(14px, env(safe-area-inset-top)) 12px 12px; overflow-y: auto; animation: fade var(--t-med) var(--ease); }
.modal { width: 100%; max-width: 520px; max-height: calc(100dvh - 28px); overflow: auto; background: var(--surface); border-radius: 22px; padding: 22px; box-shadow: var(--shadow-3); border: 1px solid var(--line); animation: drop var(--t-med) var(--ease); margin: 0 auto; }
@media (min-width: 700px) { .modal-back { padding-top: 48px; } }
.modal h3 { font-size: 18px; } .modal-actions { display: flex; gap: 10px; margin-top: var(--s4); } .modal-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } } @keyframes drop { from { transform: translateY(-28px); opacity: 0; } } @keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: 84px; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 1024px) { .toasts { bottom: 28px; } }
.toast { pointer-events: auto; background: var(--ink-900); color: #fff; padding: 12px 16px; border-radius: 14px; box-shadow: var(--shadow-3); display: flex; gap: 10px; align-items: center; font-weight: 500; animation: rise var(--t-med) var(--ease); }
.toast.ok { background: #14532d; } .toast.err { background: #7f1d1d; } .toast.warn { background: #78350f; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); flex: none; }
.pill-tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; }
.pill-tabs button, .pill-tabs a { border: 0; background: transparent; padding: 7px 16px; border-radius: var(--r-pill); font-weight: 600; font-size: 13px; color: var(--ink-500); cursor: pointer; }
.pill-tabs .is-on { background: var(--surface); color: var(--brand-600); box-shadow: var(--shadow-1); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: var(--s5); }
.page-head h1 { margin: 0; } .page-head .sub { color: var(--ink-500); font-size: 14px; margin-top: 2px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: var(--s4); }
.toolbar .input, .toolbar .select { width: auto; min-width: 160px; } .toolbar .grow { flex: 1; min-width: 200px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 10px; }
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
.barcode { height: 40px; width: 100%; display: block; }

/* modern confirm dialog */
.cmodal-back { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-start; justify-content: center; padding: max(16px, env(safe-area-inset-top)) 16px 16px; background: rgba(15,23,42,.45); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: cm-fade .18s ease both; }
@media (min-width: 700px) { .cmodal-back { padding-top: 12vh; } }
.cmodal-back.is-out { animation: cm-fade-out .16s ease both; }
.cmodal { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 28px 24px 22px; text-align: center; box-shadow: 0 30px 70px -20px rgba(15,23,42,.45), 0 6px 18px rgba(15,23,42,.12); animation: cm-pop .26s cubic-bezier(.2,.9,.3,1.2) both; }
.cm-ico { width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; color: var(--brand-600); background: var(--brand-50); box-shadow: 0 0 0 8px rgba(99,102,241,.08); }
.cmodal.is-danger .cm-ico { color: #dc2626; background: #fef2f2; box-shadow: 0 0 0 8px rgba(220,38,38,.07); }
.cmodal h3 { font-size: 19px; margin: 0 0 6px; letter-spacing: -.01em; }
.cmodal p { margin: 0 0 22px; color: var(--ink-500); font-size: 14.5px; line-height: 1.55; }
.cm-actions { display: flex; gap: 10px; flex-direction: row-reverse; }
.cm-actions .btn { flex: 1; min-height: 46px; border-radius: 14px; font-weight: 600; }
:root[data-theme="dark"] .cmodal { background: #111a2e; border-color: rgba(255,255,255,.1); }
:root[data-theme="dark"] .cmodal.is-danger .cm-ico { background: rgba(220,38,38,.14); }
@keyframes cm-fade { from { opacity: 0; } to { opacity: 1; } } @keyframes cm-fade-out { to { opacity: 0; } }
@keyframes cm-pop { from { opacity: 0; transform: translateY(-18px) scale(.94); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .cmodal, .cmodal-back { animation: none; } }
