/* Takaful ERP components. Reads the tokens in tokens.css; RTL first (logical properties throughout). */

[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; font-family: var(--font-sans); background: var(--canvas); color: var(--ink); -webkit-font-smoothing: antialiased; }
.tk-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* layout helpers for screens and previews */
.tk-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-5); }
.tk-stack { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-5); }
.tk-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); padding: var(--space-5); }

/* Icon */
.tk-icon { display: inline-block; flex: none; vertical-align: middle; }

/* Button */
.tk-btn {
  font: inherit; font-size: 0.87rem; font-weight: 500; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--control-md); padding: 0 var(--space-5);
  border: 1px solid transparent; border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs); cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .3s ease, color .3s ease, border-color .3s ease, box-shadow .3s ease;
}
.tk-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.tk-btn--sm { height: var(--control-sm); padding: 0 var(--space-4); }
.tk-btn--lg { height: var(--control-lg); padding: 0 var(--space-6); font-size: 1rem; }
.tk-btn--block { width: 100%; }
.tk-btn--pill { border-radius: var(--radius-pill); }
.tk-btn--icon { padding: 0; width: var(--control-md); }
.tk-btn--icon.tk-btn--sm { width: var(--control-sm); }
.tk-btn--icon.tk-btn--lg { width: var(--control-lg); }
.tk-btn--primary { background: var(--primary); color: var(--on-primary); }
.tk-btn--primary:hover { background: var(--primary-hover); }
.tk-btn--accent { background: var(--accent-strong); color: var(--on-accent-strong); }
.tk-btn--secondary { background: var(--secondary); color: var(--on-secondary); }
.tk-btn--danger { background: var(--danger); color: var(--on-danger); }
.tk-btn--accent:hover, .tk-btn--secondary:hover, .tk-btn--danger:hover { background-image: linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.1)); }
.tk-btn--soft { background: var(--surface-soft); color: var(--ink-brand); box-shadow: none; }
.tk-btn--soft:hover { background: var(--accent); color: var(--on-accent); }
.tk-btn--outline { background: transparent; border-color: var(--line); color: var(--ink); box-shadow: none; }
.tk-btn--outline:hover { border-color: var(--line-input); }
.tk-btn--ghost { background: transparent; color: var(--ink-muted); box-shadow: none; }
.tk-btn--ghost:hover { background: var(--surface-soft); color: var(--ink); }
.tk-btn:disabled, .tk-btn:disabled:hover {
  cursor: not-allowed; background: transparent; background-image: none;
  border-color: var(--line); color: var(--ink-subtle); box-shadow: none;
}
.tk-btn--ghost:disabled { border-color: transparent; }

/* Chip */
.tk-chip {
  font: inherit; font-size: 0.87rem; line-height: 1.2;
  display: inline-flex; align-items: center; gap: var(--space-1);
  min-height: var(--control-sm); padding: var(--space-2) var(--space-3);
  border: 0; border-radius: var(--radius-md);
  background: var(--surface-soft); color: var(--ink-brand); cursor: pointer;
  transition: background-color .3s ease, color .3s ease;
}
.tk-chip:hover { background: var(--accent-soft); color: var(--accent-strong); }
.tk-chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 500; }
.tk-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* Field + Select */
.tk-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tk-field__label { font-size: 0.87rem; font-weight: 500; line-height: 1.4; color: var(--ink); }
.tk-field__req { color: var(--danger); }
.tk-field__control {
  position: relative; display: flex; align-items: center; gap: var(--space-2);
  height: var(--control-md); padding: 0 var(--space-3); box-sizing: border-box;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-input); border-radius: var(--radius-sm);
  transition: box-shadow .2s ease, border-color .2s ease;
}
.tk-field__control:focus-within { box-shadow: var(--focus-ring); }
.tk-field__control--area { height: auto; align-items: flex-start; padding: var(--space-2) var(--space-3); }
.tk-field__input {
  flex: 1; min-width: 0; height: 100%; padding: 0; margin: 0;
  border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 1rem; color: inherit;
}
textarea.tk-field__input { min-height: 88px; line-height: 1.7; resize: vertical; }
.tk-field__input::placeholder { color: var(--ink-subtle); opacity: 1; }
.tk-field__affix { display: inline-flex; align-items: center; flex: none; color: var(--ink-muted); font-size: 0.87rem; }
.tk-field__hint { display: flex; align-items: center; gap: var(--space-1); font-size: 0.75rem; line-height: 1.5; color: var(--ink-muted); }
.tk-field--error .tk-field__control { border-color: var(--danger-line); }
.tk-field--error .tk-field__hint { color: var(--danger); }
.tk-field--disabled .tk-field__control { background: var(--surface-subtle); border-color: var(--line); color: var(--ink-subtle); }
.tk-field--disabled .tk-field__label { color: var(--ink-muted); }
.tk-select .tk-field__input { appearance: none; -webkit-appearance: none; padding-inline-end: 28px; cursor: pointer; }
.tk-select__chevron { position: absolute; inset-inline-end: var(--space-3); pointer-events: none; color: var(--ink-muted); }

/* Checkbox */
.tk-check { position: relative; display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: 0.87rem; line-height: 1.5; color: var(--ink-body); }
.tk-check__input { position: absolute; opacity: 0; width: 18px; height: 18px; margin: 0; cursor: inherit; }
.tk-check__box {
  width: 18px; height: 18px; box-sizing: border-box; flex: none;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line-input); border-radius: var(--radius-xs);
  background: var(--surface); color: transparent;
  transition: background-color .2s ease, border-color .2s ease;
}
.tk-check__input:checked + .tk-check__box { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.tk-check__input:focus-visible + .tk-check__box { box-shadow: var(--focus-ring); }
.tk-check--disabled { cursor: not-allowed; color: var(--ink-subtle); }
.tk-check--disabled .tk-check__box { background: var(--surface-subtle); border-color: var(--line); }

/* Tabs */
.tk-tabs { display: flex; gap: var(--space-5); border-bottom: 1px solid var(--line-soft); }
.tk-tab {
  font: inherit; font-size: 1rem; line-height: 1.4;
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3) 0; margin-bottom: -1px;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--ink-muted); cursor: pointer;
}
.tk-tab:hover { color: var(--ink); }
.tk-tab[aria-selected="true"] { color: var(--secondary); border-bottom-color: var(--secondary); font-weight: 500; }
.tk-tab:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xs); }
.tk-tab__count {
  font-size: 0.75rem; line-height: 20px; padding: 0 var(--space-2);
  border-radius: var(--radius-pill); background: var(--surface-soft); color: var(--ink-muted);
}
.tk-tabs--segment {
  display: inline-flex; gap: var(--space-1); padding: var(--space-1);
  background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-pill);
}
.tk-tabs--segment .tk-tab {
  height: var(--control-sm); padding: 0 var(--space-4); margin: 0;
  border: 0; border-radius: var(--radius-pill); font-size: 0.87rem;
}
.tk-tabs--segment .tk-tab[aria-selected="true"] { background: var(--accent-strong); color: var(--on-accent-strong); }
.tk-tabs--segment .tk-tab[aria-selected="true"] .tk-tab__count { background: transparent; color: inherit; }

/* Sidebar */
.tk-sidebar {
  width: var(--sidebar-w); box-sizing: border-box; min-height: 100%;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-4) var(--space-3);
  background: var(--sidebar); color: var(--on-sidebar);
  border-inline-end: 1px solid var(--line-soft);
}
.tk-sidebar__brand { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) var(--space-3) var(--space-5); }
.tk-sidebar__name { font-size: 1.38rem; font-weight: 800; line-height: 1.2; color: var(--on-sidebar); }
.tk-sidebar__tagline { font-size: 0.75rem; line-height: 1.5; color: var(--on-sidebar-muted); }
.tk-sidebar__section { font-size: 0.75rem; line-height: 1.5; color: var(--on-sidebar-muted); padding: var(--space-4) var(--space-3) var(--space-1); }
.tk-sidebar__item {
  font: inherit; font-size: 0.87rem; text-align: start; text-decoration: none;
  display: flex; align-items: center; gap: var(--space-3);
  height: var(--control-md); padding: 0 var(--space-3); width: 100%; box-sizing: border-box;
  background: none; border: 0; border-radius: var(--radius-md);
  color: var(--on-sidebar-muted); cursor: pointer;
  transition: background-color .2s ease, color .2s ease;
}
.tk-sidebar__item:hover { background: rgba(255, 255, 255, 0.06); color: var(--on-sidebar); }
.tk-sidebar__item[aria-current="page"] { background: var(--sidebar-active); color: var(--on-sidebar); font-weight: 500; }
.tk-sidebar__item[aria-current="page"] .tk-icon { color: var(--accent); }
.tk-sidebar__item:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--focus); }
.tk-sidebar__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tk-sidebar__badge {
  font-size: 0.75rem; font-weight: 700; line-height: 20px; padding: 0 var(--space-2);
  border-radius: var(--radius-pill); background: var(--accent); color: var(--on-accent);
}
.tk-sidebar__footer { margin-top: auto; padding-top: var(--space-4); }

/* Topbar */
.tk-topbar {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: var(--space-4);
  height: var(--topbar-h); padding: 0 var(--space-5); box-sizing: border-box;
  background: var(--surface); box-shadow: var(--shadow-bar);
}
.tk-topbar__titles { display: flex; flex-direction: column; min-width: 0; }
.tk-topbar__crumbs { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; line-height: 1.5; color: var(--ink-muted); }
.tk-topbar__title { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.45; color: var(--heading); white-space: nowrap; }
.tk-topbar__search { margin-inline-start: auto; width: 320px; max-width: 40%; }
.tk-topbar__actions { display: flex; align-items: center; gap: var(--space-2); }
.tk-topbar__search + .tk-topbar__actions { margin-inline-start: 0; }
.tk-topbar__titles + .tk-topbar__actions { margin-inline-start: auto; }
.tk-topbar__bell { position: relative; display: inline-flex; }
.tk-dot { position: absolute; top: 8px; inset-inline-end: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface); }
.tk-topbar__user { display: flex; align-items: center; gap: var(--space-2); padding-inline-start: var(--space-2); }
.tk-topbar__who { display: flex; flex-direction: column; }
.tk-topbar__name { font-size: 0.87rem; font-weight: 500; line-height: 1.4; color: var(--ink); white-space: nowrap; }
.tk-topbar__role { font-size: 0.75rem; line-height: 1.4; color: var(--ink-muted); white-space: nowrap; }
.tk-avatar {
  width: 36px; height: 36px; flex: none; display: inline-grid; place-items: center;
  border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-strong);
  font-size: 1rem; font-weight: 700;
}

/* Pagination */
.tk-pager { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) var(--space-4); font-size: 0.87rem; color: var(--ink-muted); }
.tk-pager__pages { display: flex; align-items: center; gap: var(--space-1); }
.tk-pager__page {
  font: inherit; min-width: 32px; height: 32px; padding: 0 var(--space-1);
  background: transparent; border: 0; border-bottom: 3px solid transparent;
  color: var(--ink-body); cursor: pointer;
}
.tk-pager__page:hover { color: var(--heading); }
.tk-pager__page[aria-current="page"] { border-bottom-color: var(--accent-strong); color: var(--heading); font-weight: 700; }
.tk-pager__page:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-xs); }
.tk-pager__gap { min-width: 24px; text-align: center; }

/* Badge */
.tk-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--radius-pill);
  font-size: 0.75rem; font-weight: 500; line-height: 1.2; white-space: nowrap;
}
.tk-badge--category { background: var(--category); color: var(--on-category); padding: 6px 12px; font-size: 0.87rem; font-weight: 400; }
.tk-badge--neutral { background: var(--surface-soft); color: var(--ink-muted); }
.tk-badge--success { background: var(--success-soft); color: var(--success); }
.tk-badge--warning { background: var(--warning-soft); color: var(--warning); }
.tk-badge--danger { background: var(--danger-soft); color: var(--danger); }
.tk-badge--info { background: var(--info-soft); color: var(--info); }
.tk-badge--success::before, .tk-badge--warning::before, .tk-badge--danger::before, .tk-badge--info::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none;
}
.tk-badge--with-icon::before { display: none; }

/* Card */
.tk-card { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-2xl); overflow: hidden; min-width: 0; }
.tk-card--raised { border-color: transparent; box-shadow: var(--shadow-card); }
.tk-card__head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line-soft); }
.tk-card__titles { min-width: 0; }
.tk-card__title { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.45; color: var(--heading); }
.tk-card__sub { margin: 2px 0 0; font-size: 0.87rem; line-height: 1.6; color: var(--ink-muted); }
.tk-card__actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--space-2); }
.tk-card__body { padding: var(--space-5); color: var(--ink-body); font-size: 1rem; line-height: 1.7; }
.tk-card__body--flush { padding: 0; }
.tk-card__foot { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line-soft); }

/* StatCard */
.tk-stat {
  display: flex; flex-direction: column; gap: var(--space-2); min-width: 0;
  padding: var(--space-5); background: var(--surface);
  border: 1px solid var(--line-soft); border-radius: var(--radius-2xl);
}
.tk-stat__top { display: flex; align-items: center; gap: var(--space-3); }
.tk-stat__icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: var(--radius-lg); background: var(--accent-soft); color: var(--accent-strong); }
.tk-stat__label { font-size: 0.87rem; line-height: 1.6; color: var(--ink-muted); }
.tk-stat__value { font-size: 2rem; font-weight: 700; line-height: 1.2; color: var(--heading); white-space: nowrap; }
.tk-stat__foot { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); font-size: 0.75rem; line-height: 1.5; color: var(--ink-muted); }
.tk-trend { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; }
.tk-trend--success { color: var(--success); }
.tk-trend--danger { color: var(--danger); }
.tk-trend--warning { color: var(--warning); }
.tk-trend--info { color: var(--info); }

/* Progress */
.tk-progress { display: flex; flex-direction: column; gap: 6px; }
.tk-progress__head { display: flex; justify-content: space-between; gap: var(--space-3); font-size: 0.87rem; line-height: 1.5; color: var(--ink-muted); }
.tk-progress__value { color: var(--heading); font-weight: 700; }
.tk-progress__track { height: 8px; border-radius: var(--radius-pill); background: var(--surface-subtle); overflow: hidden; }
.tk-progress--sm .tk-progress__track { height: 6px; }
.tk-progress__bar { height: 100%; border-radius: inherit; background: var(--accent); transition: width .3s ease; }
.tk-progress__bar--success { background: var(--success); }
.tk-progress__bar--warning { background: var(--warning); }
.tk-progress__bar--danger { background: var(--danger); }

/* DataTable */
.tk-table-wrap { overflow: auto; }
.tk-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.87rem; line-height: 1.6; color: var(--ink-body); }
.tk-table th {
  position: sticky; top: 0; z-index: 1;
  text-align: start; font-weight: 500; white-space: nowrap;
  padding: var(--space-3) var(--space-4); background: var(--surface-subtle); color: var(--heading);
  border-bottom: 1px solid var(--line-soft);
}
.tk-table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line-soft); white-space: nowrap; background: var(--surface); }
.tk-table--dense th, .tk-table--dense td { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.tk-table tbody tr:hover td { background: var(--surface-soft); }
.tk-table tr[aria-selected="true"] td { background: var(--accent-soft); }
.tk-table tbody tr:last-child td { border-bottom: 0; }
.tk-table .tk-num { text-align: end; }
.tk-table .tk-center { text-align: center; }
.tk-table__check { width: 18px; }
.tk-table__empty { padding: var(--space-7) !important; text-align: center; color: var(--ink-muted); }

/* Amount */
.tk-amount { display: inline-flex; flex-direction: row-reverse; align-items: baseline; gap: 0.25em; white-space: nowrap; }
.tk-amount__sign { font-family: var(--font-currency); font-weight: inherit; line-height: 1; }

/* Alert */
.tk-alert { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius-lg); background: var(--info-soft); color: var(--ink-body); font-size: 0.87rem; line-height: 1.6; }
.tk-alert__icon { display: inline-flex; flex: none; color: var(--info); }
.tk-alert__body { flex: 1; min-width: 0; }
.tk-alert__title { margin: 0 0 2px; font-weight: 700; color: var(--ink); }
.tk-alert__action { flex: none; align-self: center; }
.tk-alert__close { flex: none; margin: -6px; }
.tk-alert--success { background: var(--success-soft); }
.tk-alert--success .tk-alert__icon { color: var(--success); }
.tk-alert--warning { background: var(--warning-soft); }
.tk-alert--warning .tk-alert__icon { color: var(--warning); }
.tk-alert--danger { background: var(--danger-soft); }
.tk-alert--danger .tk-alert__icon { color: var(--danger); }

/* Dialog */
.tk-dialog-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--space-4); background: var(--overlay); }
.tk-dialog {
  width: min(480px, 100%); max-height: calc(100vh - 32px); box-sizing: border-box;
  display: flex; flex-direction: column; overflow: hidden; outline: none;
  background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-card);
}
.tk-dialog--lg { width: min(720px, 100%); }
.tk-dialog__head { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-5) var(--space-3); }
.tk-dialog__icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: var(--radius-lg); background: var(--danger-soft); color: var(--danger); }
.tk-dialog__titles { flex: 1; min-width: 0; }
.tk-dialog__title { margin: 0; font-size: 1.38rem; font-weight: 700; line-height: 1.4; color: var(--heading); }
.tk-dialog__desc { margin: 4px 0 0; font-size: 0.87rem; line-height: 1.6; color: var(--ink-muted); }
.tk-dialog__close { flex: none; margin: -4px; }
.tk-dialog__body { padding: 0 var(--space-5) var(--space-5); overflow: auto; font-size: 1rem; line-height: 1.7; color: var(--ink-body); }
.tk-dialog__foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line-soft); }
