/* ==========================================================================
   Challan — base + primitives
   Button · Input · Select · Segmented · Chip · Switch · Tabs · Popover
   Modal · Drawer · Toast · Tooltip · StatusBadge · Kbd · Inline message
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--t-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--brand); text-underline-offset: 3px; }
h1, h2, h3, h4, p { margin: 0; }
[hidden] { display: none !important; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 1000; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: var(--r-sm); }
.skip-link:focus { top: 12px; }

:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* Icon ------------------------------------------------------------------- */
.i { width: var(--i-md); height: var(--i-md); flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: var(--i-sm); height: var(--i-sm); }
.i-lg { width: var(--i-lg); height: var(--i-lg); }

/* Button ----------------------------------------------------------------- */
.btn {
  --h: 36px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--h); padding: 0 14px;
  border-radius: var(--r-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink);
  font-weight: 500; font-size: var(--t-md); white-space: nowrap;
  transition: background var(--d-fast) var(--ease), border-color var(--d-fast), color var(--d-fast), box-shadow var(--d-fast);
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: #C2C8D0; }
.btn:active { background: #F2F4F7; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-primary:active { background: var(--brand-press); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: rgba(16, 24, 40, .05); border-color: transparent; }
.btn-soft { background: var(--brand-tint); border-color: transparent; color: var(--brand); }
.btn-soft:hover { background: var(--brand-tint-2); border-color: transparent; }
.btn-danger { color: var(--err); }
.btn-sm { --h: 30px; padding: 0 10px; font-size: var(--t-sm); gap: 6px; }
.btn-lg { --h: 48px; padding: 0 22px; font-size: var(--t-lg); border-radius: var(--r-field); }
.btn-icon { width: var(--h); padding: 0; }
.btn-block { width: 100%; }

/* Fields ----------------------------------------------------------------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--t-sm); font-weight: 500; color: var(--ink-2); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.label .opt { color: var(--faint); font-weight: 400; }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: var(--r-field);
  transition: border-color var(--d-fast), box-shadow var(--d-fast), background var(--d-fast);
  font-size: var(--t-md);
}
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .select:hover, .textarea:hover { border-color: #B9C0CA; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667085' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input.is-num { text-align: right; font-variant-numeric: tabular-nums; }
.input-group { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--r-field); background: var(--surface); transition: border-color var(--d-fast), box-shadow var(--d-fast); }
.input-group:focus-within { border-color: var(--brand); box-shadow: var(--focus); }
.input-group .input { border: 0; box-shadow: none !important; background: transparent; }
.input-group .affix { display: grid; place-items: center; padding: 0 10px; color: var(--muted); font-size: var(--t-sm); border-inline-end: 1px solid var(--border); white-space: nowrap; }
.input-group .affix:last-child { border-inline-end: 0; border-inline-start: 1px solid var(--border); }

/* Example (sample) data — visibly different until replaced */
.is-sample { color: var(--muted) !important; font-style: italic; background: repeating-linear-gradient(135deg, #fff, #fff 6px, #FAFBFC 6px, #FAFBFC 12px) !important; }
.sample-tag { font-size: 10.5px; font-weight: 500; color: var(--muted); background: #F2F4F7; border-radius: var(--r-xs); padding: 1px 6px; font-style: normal; }

/* Inline validation */
.msg { display: flex; gap: 6px; align-items: flex-start; font-size: var(--t-sm); line-height: 1.35; }
.msg .i { width: 14px; height: 14px; margin-top: 1px; }
.msg-err { color: var(--err); }
.msg-warn { color: var(--warn); }
.msg-tip { color: var(--muted); }
.has-err .input, .has-err .input-group { border-color: var(--err); }
.has-warn .input, .has-warn .input-group { border-color: #E9B36B; }

/* Segmented control ------------------------------------------------------ */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: #F0F2F5; border-radius: var(--r-field); width: 100%; }
.seg button { flex: 1; height: 30px; padding: 0 10px; border-radius: 7px; font-size: var(--t-sm); font-weight: 500; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--e-1), 0 0 0 1px rgba(16,24,40,.04); }

/* Chip ------------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface); font-size: var(--t-sm); color: var(--ink-2); font-weight: 500; }
.chip:hover { border-color: var(--border-strong); background: var(--surface-2); }
.chip[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-tint); color: var(--brand); }
.chip-dashed { border-style: dashed; color: var(--muted); }
.chip .i { width: 13px; height: 13px; }

/* Switch ----------------------------------------------------------------- */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: var(--t-md); color: var(--ink-2); cursor: pointer; min-height: 28px; }
.switch input { appearance: none; width: 32px; height: 18px; border-radius: 999px; background: #D0D5DD; position: relative; flex: none; cursor: pointer; transition: background var(--d-fast); margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform var(--d-fast) var(--ease); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(14px); }
.switch input:focus-visible { outline: var(--focus-ring); outline-offset: 2px; }

/* Tabs ------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 12px; }
.tab { position: relative; height: 44px; padding: 0 10px; font-weight: 500; color: var(--muted); font-size: var(--t-md); }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--ink); border-radius: 2px; }

/* Popover / menu --------------------------------------------------------- */
.popover {
  position: fixed; z-index: 60; min-width: 220px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: var(--e-3); padding: 6px;
  transform-origin: top; animation: pop-in var(--d-med) var(--ease);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.985); } }
.menu-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; font-size: var(--t-md); color: var(--ink-2); text-align: start; }
.menu-item:hover, .menu-item[aria-selected="true"], .menu-item:focus-visible { background: #F2F4F7; color: var(--ink); outline: none; }
.menu-item .meta { margin-inline-start: auto; color: var(--faint); font-size: var(--t-sm); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-heading { font-size: var(--t-xs); color: var(--faint); padding: 8px 10px 4px; font-weight: 500; }

/* Modal ------------------------------------------------------------------ */
.scrim { position: fixed; inset: 0; z-index: 80; background: rgba(17, 24, 39, .38); display: grid; place-items: center; padding: 24px; animation: fade-in var(--d-med) var(--ease); }
@keyframes fade-in { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--e-3); width: min(560px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; animation: modal-in var(--d-med) var(--ease); overflow: hidden; }
.modal-lg { width: min(1080px, 100%); }
.modal-md { width: min(720px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 14px; }
.modal-head h2 { font-size: var(--t-lg); font-weight: 600; letter-spacing: -.01em; }
.modal-head p { color: var(--muted); font-size: var(--t-sm); }
.modal-head .btn-icon { margin-inline-start: auto; }
.modal-body { padding: 4px 20px 20px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* Drawer ----------------------------------------------------------------- */
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(360px, 92vw); background: var(--surface); box-shadow: var(--e-3); z-index: 70; display: flex; flex-direction: column; animation: drawer-in var(--d-med) var(--ease); }
@keyframes drawer-in { from { transform: translateX(16px); opacity: 0; } }

/* Toast ------------------------------------------------------------------ */
.toasts { position: fixed; z-index: 100; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--r-md); box-shadow: var(--e-3); font-size: var(--t-md); animation: toast-in var(--d-med) var(--ease); }
.toast .btn { --h: 26px; background: transparent; color: #A6F4C5; border-color: transparent; padding: 0 6px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* Tooltip (CSS-only, for icon buttons with aria-label) ------------------- */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 12px; font-weight: 500; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 90; pointer-events: none;
}

/* Status badge ----------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: var(--r-pill); font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge .i { width: 12px; height: 12px; stroke-width: 2.2; }
.badge-paid { background: var(--ok-tint); color: var(--ok); }
.badge-partial { background: var(--warn-tint); color: var(--warn); }
.badge-unpaid { background: var(--err-tint); color: var(--err); }
.badge-neutral { background: #F2F4F7; color: var(--ink-2); }

.kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; font-size: 11px; color: var(--muted); background: var(--surface); font-family: var(--font-ui); }

/* Empty state ------------------------------------------------------------ */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); display: grid; justify-items: center; gap: 10px; }
.empty h3 { color: var(--ink); font-size: var(--t-lg); font-weight: 600; }
.empty p { max-width: 42ch; }

/* Brand mark ------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 600; font-size: 17px; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.brand img { width: 26px; height: 26px; }
