/* =========================================================
   CR-Kaswa — base.css
   Design tokens, reset, typography, buttons, forms,
   toasts, modals and shared utility classes.
   ========================================================= */

:root {
  /* Brand */
  --brand: #5b3fd1;
  --brand-600: #4a30b8;
  --brand-50: #f1edff;
  --accent: #ffd54f;
  --accent-600: #f5c518;

  /* Neutrals */
  --ink: #161827;
  --ink-2: #3d4152;
  --muted: #6b7082;
  --line: #e6e8ef;
  --surface: #ffffff;
  --bg: #f6f7fb;
  --bg-2: #eef0f6;

  /* Feedback */
  --success: #138a52;
  --success-50: #e7f6ee;
  --warning: #b86e00;
  --warning-50: #fff4e0;
  --danger: #c8283c;
  --danger-50: #fdecee;
  --info: #1f6fd1;
  --info-50: #e8f1fd;

  /* Shape & depth */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(22, 24, 39, .06);
  --shadow: 0 4px 16px rgba(22, 24, 39, .07);
  --shadow-lg: 0 18px 48px rgba(22, 24, 39, .14);

  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --container: 1240px;
  --header-h: 72px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 2.4vw, 2.1rem); font-weight: 800; }
h2 { font-size: 1.35rem; font-weight: 750; }
h3 { font-size: 1.08rem; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
code { background: var(--bg-2); padding: 2px 6px; border-radius: 6px; font-size: .88em; }

:focus-visible { outline: 3px solid rgba(91, 63, 209, .45); outline-offset: 2px; border-radius: 6px; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 20px; }
.page-section { padding: 32px 0 56px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.icon { width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -0.2em; }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-border: var(--line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit; font-weight: 650; font-size: .94rem;
  cursor: pointer;
  text-decoration: none !important;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { --btn-bg: var(--brand); --btn-fg: #fff; --btn-border: var(--brand); }
.btn-primary:hover { --btn-bg: var(--brand-600); }
.btn-accent { --btn-bg: var(--accent); --btn-fg: var(--ink); --btn-border: var(--accent); }
.btn-accent:hover { --btn-bg: var(--accent-600); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-border: var(--danger); }
.btn-ghost { --btn-bg: transparent; --btn-border: transparent; }
.btn-ghost:hover { --btn-bg: var(--bg-2); box-shadow: none; }
.btn-outline { --btn-bg: transparent; --btn-border: var(--brand); --btn-fg: var(--brand); }
.btn-sm { padding: 7px 12px; font-size: .84rem; border-radius: 8px; }
.btn-lg { padding: 14px 24px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

/* Loading state for buttons */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px;
  border: 2.5px solid currentColor; border-color: var(--btn-fg) transparent var(--btn-fg) transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field-label { font-weight: 650; font-size: .88rem; color: var(--ink-2); }
.field .req { color: var(--danger); }
.field .hint { font-size: .8rem; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  padding: 11px 13px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #d6d9e3;
  border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { resize: vertical; min-height: 96px; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91, 63, 209, .15);
}
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .8rem; font-weight: 600; min-height: 0; }
.field-error:empty { display: none; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: 10px 0 0 10px; }
.input-group .btn { border-radius: 0 10px 10px 0; }

.choice-list { display: grid; gap: 10px; }
.choice {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.choice:hover { border-color: #c9c3ef; }
.choice input { accent-color: var(--brand); width: 18px; height: 18px; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-50); }
.choice .choice-main { flex: 1; }
.choice .choice-title { font-weight: 700; }
.choice .choice-sub { font-size: .82rem; color: var(--muted); }
.choice .choice-aside { font-weight: 750; }

/* ---------- Cards, badges, alerts ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-body { padding: 22px; }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header h2, .card-header h3 { margin: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; line-height: 1.6;
  background: var(--bg-2); color: var(--ink-2);
}
.badge-success { background: var(--success-50); color: var(--success); }
.badge-warning { background: var(--warning-50); color: var(--warning); }
.badge-danger { background: var(--danger-50); color: var(--danger); }
.badge-info { background: var(--info-50); color: var(--info); }
.badge-brand { background: var(--brand-50); color: var(--brand); }

.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px 16px; border-radius: 12px; font-size: .9rem;
  background: var(--info-50); color: #164d91; border: 1px solid #cfe1f9;
}
.alert p:last-child { margin: 0; }
.alert-warning { background: var(--warning-50); color: #7a4a00; border-color: #ffe0a8; }
.alert-danger { background: var(--danger-50); color: #8e1526; border-color: #f7c6cd; }
.alert-success { background: var(--success-50); color: #0c6139; border-color: #bfe7d1; }

/* ---------- Empty / loading states ---------- */
.empty-state {
  text-align: center; padding: 56px 20px; color: var(--muted);
  background: var(--surface); border: 1px dashed #d6d9e3; border-radius: var(--radius);
}
.empty-state .empty-icon {
  width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
  display: grid; place-items: center; background: var(--brand-50); color: var(--brand);
}
.empty-state .empty-icon .icon { width: 30px; height: 30px; }
.empty-state h3 { color: var(--ink); }

.skeleton {
  background: linear-gradient(90deg, #eceef4 25%, #f6f7fb 50%, #eceef4 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--brand-50); border-top-color: var(--brand);
  animation: spin .8s linear infinite; margin: 24px auto;
}

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed; z-index: 3000; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 14px; border-radius: 12px; background: var(--ink); color: #fff;
  box-shadow: var(--shadow-lg); font-size: .9rem;
  animation: toast-in .25s var(--ease);
  border-left: 4px solid var(--info);
}
.toast.success { border-left-color: #3ccf8e; }
.toast.error { border-left-color: #ff6b7d; }
.toast.warning { border-left-color: var(--accent); }
.toast .toast-msg { flex: 1; }
.toast button { background: none; border: 0; color: #aab; cursor: pointer; padding: 0; }
.toast.leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 2500; background: rgba(15, 17, 30, .5);
  display: grid; place-items: center; padding: 20px;
  animation: fade-in .18s ease;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto;
  animation: pop-in .22s var(--ease);
}
.modal.modal-lg { width: min(860px, 100%); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: #fafbfd; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fbfbfe; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Utilities ---------- */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; } .gap-2 { gap: 14px; } .wrap { flex-wrap: wrap; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 26px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 16px; }
.text-muted { color: var(--muted); } .text-sm { font-size: .86rem; } .text-right { text-align: right; }
.strike { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.hidden { display: none !important; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .toast-region { left: 20px; right: 20px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
