/* ==========================================================================
   KRIN — Component layer
   Reusable, documented UI building blocks. Namespaced `ds-` plus legacy aliases.
   ========================================================================== */

/* ---------- Surface / card ---------- */
.ds-card,
.card {
    background: var(--ds-surface-base);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-xs);
    padding: var(--ds-space-5);
}
.card { margin-bottom: var(--ds-space-5); }
.card:last-child { margin-bottom: 0; }

.ds-card--flush { padding: 0; overflow: hidden; }
.ds-card--raised { box-shadow: var(--ds-shadow-md); }

.ds-card__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-3);
    padding: var(--ds-space-4) var(--ds-space-5);
    border-bottom: 1px solid var(--ds-border-subtle);
}
.ds-card__body { padding: var(--ds-space-5); }
.ds-card__footer {
    padding: var(--ds-space-3) var(--ds-space-5);
    border-top: 1px solid var(--ds-border-subtle);
    background: var(--ds-surface-sunken);
}

.section-heading { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--ds-space-3); margin-bottom: var(--ds-space-4); }
.section-heading h2, .card h2 { margin-bottom: 0.3rem; }
.section-heading p { color: var(--ds-text-muted); font-size: var(--ds-font-size-sm); }

/* ---------- Stat ---------- */
.ds-stat { display: flex; flex-direction: column; gap: var(--ds-space-1); }
.ds-stat__label { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); font-weight: var(--ds-font-weight-semibold); }
.ds-stat__value { color: var(--ds-text-strong); font-size: var(--ds-font-size-2xl); font-weight: var(--ds-font-weight-bold); line-height: 1.15; }
.ds-stat__hint { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); }
.ds-stat__trend { display: inline-flex; align-items: center; gap: 0.25rem; font-size: var(--ds-font-size-xs); font-weight: var(--ds-font-weight-semibold); }
.ds-stat__trend--up { color: var(--ds-color-success); }
.ds-stat__trend--down { color: var(--ds-color-danger); }

.stat-card { display: flex; flex-direction: column; gap: var(--ds-space-1); }
.stat-card strong { font-size: var(--ds-font-size-xl); color: var(--ds-text-strong); }
.stat-label { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); font-weight: var(--ds-font-weight-semibold); }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--ds-space-4); margin-bottom: var(--ds-space-4); }

/* ---------- Buttons ---------- */
.btn,
.ds-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-space-2);
    border: 1px solid transparent;
    border-radius: var(--ds-radius-sm);
    padding: 0.58rem 1rem;
    font: inherit;
    font-size: var(--ds-font-size-sm);
    font-weight: var(--ds-font-weight-bold);
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: background var(--ds-duration-fast) var(--ds-ease-standard),
                border-color var(--ds-duration-fast) var(--ds-ease-standard),
                color var(--ds-duration-fast) var(--ds-ease-standard),
                transform var(--ds-duration-instant) var(--ds-ease-standard),
                box-shadow var(--ds-duration-fast) var(--ds-ease-standard);
}
.btn:active, .ds-btn:active { transform: translateY(1px); }
.btn svg, .ds-btn svg { width: 18px; height: 18px; }
.btn[disabled], .ds-btn[disabled], .ds-btn.is-disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary, .ds-btn--primary { background: var(--ds-brand-600); color: var(--ds-text-on-brand); }
.btn-primary:hover, .ds-btn--primary:hover { background: var(--ds-brand-700); color: var(--ds-text-on-brand); text-decoration: none; }

.ds-btn--accent { background: var(--ds-color-accent); color: #fff; }
.ds-btn--accent:hover { filter: brightness(0.94); }

.btn-ghost, .ds-btn--ghost { background: transparent; border-color: var(--ds-border-base); color: var(--ds-text-base); }
.btn-ghost:hover, .ds-btn--ghost:hover { border-color: var(--ds-brand-500); color: var(--ds-brand-700); text-decoration: none; }

.ds-btn--subtle { background: var(--ds-surface-sunken); color: var(--ds-text-base); }
.ds-btn--subtle:hover { background: var(--ds-surface-hover); }

.btn-danger, .ds-btn--danger { background: var(--ds-color-danger); color: #fff; }
.btn-danger:hover, .ds-btn--danger:hover { background: #b91c1c; color: #fff; text-decoration: none; }

.ds-btn--success { background: var(--ds-color-success); color: #fff; }

.ds-btn--block, .btn-block { width: 100%; }
.btn-sm, .ds-btn--sm { padding: 0.34rem 0.62rem; font-size: var(--ds-font-size-xs); border-radius: var(--ds-radius-xs); }
.ds-btn--lg { padding: 0.72rem 1.25rem; font-size: var(--ds-font-size-md); }
.ds-btn--icon { padding: 0; width: 40px; height: 40px; }

/* ---------- Badges / pills / chips ---------- */
.badge, .ds-badge, .pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: var(--ds-radius-pill);
    padding: 0.14rem 0.6rem;
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    white-space: nowrap;
}
.badge-on, .pill-on, .ds-badge--success { color: var(--ds-color-success); background: var(--ds-color-success-soft); }
.badge-off, .pill-off, .ds-badge--neutral { color: var(--ds-text-muted); background: var(--ds-surface-sunken); }
.pill-warn, .ds-badge--warning { color: var(--ds-color-warning); background: var(--ds-color-warning-soft); }
.pill-danger, .ds-badge--danger { color: var(--ds-color-danger); background: var(--ds-color-danger-soft); }
.ds-badge--info { color: var(--ds-color-info); background: var(--ds-color-info-soft); }
.ds-badge--accent { color: var(--ds-color-accent); background: var(--ds-color-accent-soft); }

.ds-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-2);
    border: 1px solid var(--ds-border-base);
    border-radius: var(--ds-radius-pill);
    padding: 0.3rem 0.7rem;
    background: var(--ds-surface-base);
    font-size: var(--ds-font-size-xs);
    color: var(--ds-text-base);
}
.ds-chip__remove { cursor: pointer; color: var(--ds-text-muted); }
.ds-chip__remove:hover { color: var(--ds-color-danger); }

/* ---------- Forms ---------- */
.field, .ds-field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.field > label, .ds-field > label { font-size: var(--ds-font-size-sm); font-weight: var(--ds-font-weight-semibold); color: var(--ds-text-base); }
.ds-field__hint { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); }
.field-error, .ds-field__error { color: var(--ds-color-danger); font-size: var(--ds-font-size-xs); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], input[type="tel"], input[type="url"], input[type="date"],
input[type="datetime-local"], input[type="time"], select, textarea,
.ds-input, .ds-select, .ds-textarea {
    width: 100%;
    border: 1px solid var(--ds-border-base);
    border-radius: var(--ds-radius-sm);
    padding: 0.62rem 0.75rem;
    background: var(--ds-surface-base);
    color: var(--ds-text-base);
    outline: none;
    transition: border-color var(--ds-duration-fast) var(--ds-ease-standard),
                box-shadow var(--ds-duration-fast) var(--ds-ease-standard);
}
input:hover, select:hover, textarea:hover, .ds-input:hover { border-color: var(--ds-border-strong); }
input:focus, select:focus, textarea:focus, .ds-input:focus, .ds-select:focus, .ds-textarea:focus {
    border-color: var(--ds-border-focus);
    box-shadow: var(--ds-shadow-focus);
}
textarea, .ds-textarea { resize: vertical; min-height: 96px; }
input::placeholder, textarea::placeholder { color: var(--ds-text-subtle); }
input[aria-invalid="true"], .ds-input.is-invalid { border-color: var(--ds-color-danger); }

.ds-input-group { display: flex; align-items: stretch; }
.ds-input-group .ds-input { border-start-end-radius: 0; border-end-end-radius: 0; }
.ds-input-group__addon {
    display: inline-flex;
    align-items: center;
    padding-inline: 0.75rem;
    border: 1px solid var(--ds-border-base);
    border-inline-start: 0;
    border-start-end-radius: var(--ds-radius-sm);
    border-end-end-radius: var(--ds-radius-sm);
    background: var(--ds-surface-sunken);
    color: var(--ds-text-muted);
}

.check-row, .ds-check {
    display: flex;
    align-items: center;
    gap: var(--ds-space-2);
    font-size: var(--ds-font-size-sm);
    color: var(--ds-text-base);
    cursor: pointer;
}
input[type="checkbox"], input[type="radio"] { width: 1rem; height: 1rem; accent-color: var(--ds-brand-600); }

.ds-switch { position: relative; display: inline-flex; align-items: center; gap: var(--ds-space-2); cursor: pointer; }
.ds-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.ds-switch__track {
    width: 42px; height: 24px; border-radius: var(--ds-radius-pill);
    background: var(--ds-border-strong); position: relative; transition: background var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-switch__track::after {
    content: ""; position: absolute; inset-block-start: 3px; inset-inline-start: 3px;
    width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: var(--ds-shadow-xs);
    transition: transform var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-switch input:checked + .ds-switch__track { background: var(--ds-brand-600); }
.ds-switch input:checked + .ds-switch__track::after { transform: translateX(-18px); }
.ds-switch input:focus-visible + .ds-switch__track {
    outline: 2px solid var(--ds-border-focus);
    outline-offset: 2px;
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ds-space-4); }
.form-inline { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); align-items: flex-end; }
.form-inline .field { min-width: 150px; }

/* ---------- Alerts / inline states ---------- */
.alert, .ds-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--ds-space-2);
    border-radius: var(--ds-radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: var(--ds-space-4);
    border: 1px solid transparent;
    font-size: var(--ds-font-size-sm);
}
.alert-success, .ds-alert--success { color: var(--ds-color-success); background: var(--ds-color-success-soft); border-color: rgba(15, 157, 88, 0.28); }
.alert-error, .ds-alert--danger { color: var(--ds-color-danger); background: var(--ds-color-danger-soft); border-color: rgba(220, 38, 38, 0.28); }
.ds-alert--warning { color: var(--ds-color-warning); background: var(--ds-color-warning-soft); border-color: rgba(217, 119, 6, 0.28); }
.ds-alert--info { color: var(--ds-color-info); background: var(--ds-color-info-soft); border-color: rgba(37, 99, 235, 0.28); }
.alert ul { margin: 0.25rem 0 0; padding-inline-start: 1.1rem; }

/* ---------- Data grid / tables ---------- */
.table-wrap, .ds-table-wrap { overflow-x: auto; border-radius: var(--ds-radius-sm); }
table.data, .ds-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--ds-font-size-sm);
}
table.data th, table.data td,
.ds-table th, .ds-table td {
    padding: 0.6rem 0.7rem;
    text-align: start;
    border-bottom: 1px solid var(--ds-border-subtle);
    vertical-align: middle;
}
table.data th, .ds-table th {
    color: var(--ds-text-muted);
    font-size: var(--ds-font-size-xs);
    font-weight: var(--ds-font-weight-bold);
    background: var(--ds-surface-sunken);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}
table.data tbody tr:hover td, .ds-table tbody tr:hover td { background: var(--ds-surface-hover); }
.ds-table--striped tbody tr:nth-child(even) td { background: var(--ds-surface-sunken); }
.ds-table__sort { cursor: pointer; user-select: none; }
.ds-table__sort::after { content: "↕"; margin-inline-start: 0.35rem; color: var(--ds-text-subtle); font-size: 0.7em; }
.ds-table__sort[aria-sort="ascending"]::after { content: "↑"; color: var(--ds-brand-600); }
.ds-table__sort[aria-sort="descending"]::after { content: "↓"; color: var(--ds-brand-600); }

.ds-datagrid__toolbar {
    display: flex; flex-wrap: wrap; gap: var(--ds-space-3);
    align-items: center; justify-content: space-between; margin-bottom: var(--ds-space-3);
}

/* ---------- Pagination ---------- */
.ds-pagination { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); }
.ds-pagination__list { display: flex; gap: var(--ds-space-1); list-style: none; padding: 0; }
.ds-pagination__item {
    min-width: 36px; height: 36px; padding-inline: 0.5rem;
    display: inline-grid; place-items: center;
    border: 1px solid var(--ds-border-base); border-radius: var(--ds-radius-xs);
    background: var(--ds-surface-base); color: var(--ds-text-base); cursor: pointer;
    font-size: var(--ds-font-size-sm); transition: background var(--ds-duration-fast) var(--ds-ease-standard);
}
.ds-pagination__item:hover { background: var(--ds-surface-hover); }
.ds-pagination__item.is-active { background: var(--ds-brand-600); border-color: var(--ds-brand-600); color: #fff; }
.ds-pagination__item[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tabs ---------- */
.ds-tabs { display: flex; gap: var(--ds-space-1); border-bottom: 1px solid var(--ds-border-subtle); margin-bottom: var(--ds-space-4); overflow-x: auto; }
.ds-tab {
    padding: 0.6rem 0.9rem; border: 0; background: transparent; cursor: pointer;
    color: var(--ds-text-muted); font-weight: var(--ds-font-weight-semibold); font-size: var(--ds-font-size-sm);
    border-bottom: 2px solid transparent; white-space: nowrap;
}
.ds-tab:hover { color: var(--ds-text-strong); }
.ds-tab.is-active { color: var(--ds-brand-700); border-bottom-color: var(--ds-brand-600); }
.ds-tabpanel[hidden] { display: none; }

/* ---------- Dropdown ---------- */
.ds-dropdown { position: relative; display: inline-block; }
.ds-dropdown__menu {
    position: absolute;
    inset-block-start: calc(100% + 6px);
    inset-inline-start: 0;
    min-width: 220px;
    background: var(--ds-surface-raised);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-md);
    padding: var(--ds-space-2);
    z-index: var(--ds-z-dropdown);
    display: none;
    animation: ds-pop-in var(--ds-duration-fast) var(--ds-ease-out) both;
}
.ds-dropdown__menu--end { inset-inline-start: auto; inset-inline-end: 0; }
.ds-dropdown.is-open .ds-dropdown__menu { display: block; }
.ds-dropdown__item {
    display: flex; align-items: center; gap: var(--ds-space-2);
    width: 100%; padding: 0.5rem 0.65rem; border: 0; background: transparent;
    border-radius: var(--ds-radius-xs); color: var(--ds-text-base); font-size: var(--ds-font-size-sm);
    cursor: pointer; text-align: start;
}
.ds-dropdown__item:hover { background: var(--ds-surface-hover); text-decoration: none; color: var(--ds-text-strong); }
.ds-dropdown__item--danger { color: var(--ds-color-danger); }
.ds-dropdown__divider { height: 1px; background: var(--ds-border-subtle); margin: var(--ds-space-1) 0; }
.ds-dropdown__label { padding: 0.4rem 0.65rem; color: var(--ds-text-subtle); font-size: var(--ds-font-size-xs); font-weight: var(--ds-font-weight-bold); }

/* ---------- Context menu ---------- */
.ds-context-menu {
    position: fixed;
    z-index: var(--ds-z-context);
    min-width: 200px;
    background: var(--ds-surface-raised);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-lg);
    padding: var(--ds-space-2);
    display: none;
}
.ds-context-menu.is-open { display: block; animation: ds-pop-in var(--ds-duration-fast) var(--ds-ease-out) both; }

/* ---------- Modal ---------- */
.ds-modal {
    border: 0;
    padding: 0;
    background: transparent;
    max-width: min(560px, calc(100vw - 2rem));
    width: 100%;
}
.ds-modal::backdrop { background: var(--ds-surface-overlay); backdrop-filter: blur(2px); }
.ds-modal[open] .ds-modal__panel { animation: ds-pop-in var(--ds-duration-base) var(--ds-ease-out) both; }
.ds-modal--lg { max-width: min(880px, calc(100vw - 2rem)); }
.ds-modal__panel {
    background: var(--ds-surface-raised);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-shadow-lg);
    overflow: hidden;
}
.ds-modal__header { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3); padding: var(--ds-space-4) var(--ds-space-5); border-bottom: 1px solid var(--ds-border-subtle); }
.ds-modal__body { padding: var(--ds-space-5); }
.ds-modal__footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--ds-space-2); padding: var(--ds-space-4) var(--ds-space-5); border-top: 1px solid var(--ds-border-subtle); background: var(--ds-surface-sunken); }

/* ---------- Drawer ---------- */
.ds-drawer {
    position: fixed;
    inset-block: 0;
    inset-inline-end: 0;
    width: min(420px, 92vw);
    background: var(--ds-surface-raised);
    border-inline-start: 1px solid var(--ds-border-subtle);
    box-shadow: var(--ds-shadow-lg);
    z-index: var(--ds-z-drawer);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform var(--ds-duration-base) var(--ds-ease-standard);
}
.ds-drawer.is-open { transform: translateX(0); }
.ds-drawer__header { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3); padding: var(--ds-space-4) var(--ds-space-5); border-bottom: 1px solid var(--ds-border-subtle); }
.ds-drawer__body { padding: var(--ds-space-5); overflow-y: auto; flex: 1 1 auto; }
.ds-drawer__footer { padding: var(--ds-space-4) var(--ds-space-5); border-top: 1px solid var(--ds-border-subtle); display: flex; gap: var(--ds-space-2); justify-content: flex-end; }

/* ---------- Toast ---------- */
.ds-toasts {
    position: fixed;
    inset-block-start: var(--ds-space-5);
    inset-inline-start: var(--ds-space-5);
    z-index: var(--ds-z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-2);
    width: min(360px, calc(100vw - 2rem));
    pointer-events: none;
}
.ds-toast {
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--ds-space-3);
    background: var(--ds-surface-raised);
    border: 1px solid var(--ds-border-subtle);
    border-inline-start: 4px solid var(--ds-color-info);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-md);
    padding: var(--ds-space-3) var(--ds-space-4);
    animation: ds-rise-in var(--ds-duration-base) var(--ds-ease-out) both;
}
.ds-toast--success { border-inline-start-color: var(--ds-color-success); }
.ds-toast--danger { border-inline-start-color: var(--ds-color-danger); }
.ds-toast--warning { border-inline-start-color: var(--ds-color-warning); }
.ds-toast__title { font-weight: var(--ds-font-weight-bold); font-size: var(--ds-font-size-sm); color: var(--ds-text-strong); }
.ds-toast__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ds-toast__message { font-size: var(--ds-font-size-sm); color: var(--ds-text-muted); }
.ds-toast__close { margin-inline-start: auto; background: transparent; border: 0; cursor: pointer; color: var(--ds-text-subtle); }
.ds-toast.is-leaving { animation: ds-fade-in var(--ds-duration-fast) var(--ds-ease-standard) reverse both; }

/* ---------- Search & filter ---------- */
.ds-search { position: relative; display: flex; align-items: center; min-width: 220px; }
.ds-search__icon { position: absolute; inset-inline-start: 0.7rem; color: var(--ds-text-subtle); width: 18px; height: 18px; pointer-events: none; }
.ds-search input { padding-inline-start: 2.3rem; }
.ds-filter-bar { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); align-items: flex-end; }
.ds-filter-bar .field { min-width: 150px; }

/* ---------- Avatar ---------- */
.ds-avatar {
    display: inline-grid; place-items: center;
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--ds-brand-100); color: var(--ds-brand-700);
    font-weight: var(--ds-font-weight-bold); font-size: var(--ds-font-size-sm);
    flex: 0 0 auto;
}
.ds-avatar--sm { width: 30px; height: 30px; font-size: var(--ds-font-size-xs); }
.ds-avatar--lg { width: 56px; height: 56px; font-size: var(--ds-font-size-lg); }

/* ---------- Progress / skeleton / loading ---------- */
.ds-progress { height: 8px; border-radius: var(--ds-radius-pill); background: var(--ds-surface-sunken); overflow: hidden; }
.ds-progress__bar { height: 100%; background: var(--ds-brand-600); border-radius: inherit; transition: width var(--ds-duration-slow) var(--ds-ease-standard); }

.ds-spinner {
    width: 22px; height: 22px; border-radius: 50%;
    border: 3px solid var(--ds-border-base);
    border-top-color: var(--ds-brand-600);
    animation: ds-spin 800ms linear infinite;
}
.ds-spinner--lg { width: 40px; height: 40px; border-width: 4px; }
.ds-loading { display: inline-flex; align-items: center; gap: var(--ds-space-2); color: var(--ds-text-muted); font-size: var(--ds-font-size-sm); }

.ds-skeleton {
    position: relative; overflow: hidden;
    background: var(--ds-surface-sunken); border-radius: var(--ds-radius-sm);
    min-height: 1rem;
}
.ds-skeleton::after {
    content: ""; position: absolute; inset: 0;
    transform: translateX(100%);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
    animation: ds-shimmer 1.4s infinite;
}
.ds-skeleton--text { height: 0.85rem; margin-block: 0.3rem; }
.ds-skeleton--title { height: 1.4rem; width: 40%; margin-bottom: 0.6rem; }
.ds-skeleton--circle { border-radius: 50%; width: 42px; height: 42px; }

/* ---------- Empty / error states ---------- */
.ds-state {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    gap: var(--ds-space-3); padding: var(--ds-space-10) var(--ds-space-5);
}
.ds-state__icon {
    display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
    background: var(--ds-surface-sunken); color: var(--ds-text-muted);
}
.ds-state__icon svg { width: 30px; height: 30px; }
.ds-state h3 { font-size: var(--ds-font-size-lg); }
.ds-state p { color: var(--ds-text-muted); font-size: var(--ds-font-size-sm); max-width: 42ch; }
.ds-state--error .ds-state__icon { background: var(--ds-color-danger-soft); color: var(--ds-color-danger); }

/* ---------- Charts ---------- */
.ds-chart { position: relative; width: 100%; }
.ds-chart svg { width: 100%; height: auto; overflow: visible; }
.ds-chart__grid { stroke: var(--ds-border-subtle); stroke-width: 1; }
.ds-chart__bar { fill: var(--ds-brand-500); transition: fill var(--ds-duration-fast) var(--ds-ease-standard); }
.ds-chart__bar:hover { fill: var(--ds-brand-700); }
.ds-chart__line { fill: none; stroke: var(--ds-brand-600); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.ds-chart__area { fill: var(--ds-brand-500); opacity: 0.14; }
.ds-chart__point { fill: var(--ds-surface-base); stroke: var(--ds-brand-600); stroke-width: 2; }
.ds-chart__donut-seg { transition: opacity var(--ds-duration-fast) var(--ds-ease-standard); }
.ds-chart__donut-seg:hover { opacity: 0.82; }
.ds-chart__legend { display: flex; flex-wrap: wrap; gap: var(--ds-space-3); margin-top: var(--ds-space-3); font-size: var(--ds-font-size-xs); color: var(--ds-text-muted); }
.ds-chart__legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.ds-chart__swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.ds-sparkline { display: inline-block; vertical-align: middle; }

/* ---------- Timeline ---------- */
.ds-timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--ds-space-3); }
.ds-timeline__item { display: flex; gap: var(--ds-space-3); }
.ds-timeline__dot { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%; background: var(--ds-brand-500); margin-top: 0.35rem; }
.ds-timeline__body { font-size: var(--ds-font-size-sm); }
.ds-timeline__time { color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); }

/* ---------- Tooltip ---------- */
.ds-tooltip { position: relative; }
.ds-tooltip::after {
    content: attr(data-ds-tooltip);
    position: absolute; inset-block-end: calc(100% + 6px); inset-inline-start: 50%;
    transform: translateX(50%) scale(0.96);
    background: var(--ds-surface-inverse); color: var(--ds-text-inverse);
    padding: 0.3rem 0.55rem; border-radius: var(--ds-radius-xs);
    font-size: var(--ds-font-size-xs); white-space: nowrap;
    opacity: 0; pointer-events: none; transition: opacity var(--ds-duration-fast) var(--ds-ease-standard);
    z-index: var(--ds-z-dropdown);
}
.ds-tooltip:hover::after { opacity: 1; }

/* ---------- Separator ---------- */
.ds-divider { height: 1px; background: var(--ds-border-subtle); margin-block: var(--ds-space-4); border: 0; }

/* ---------- Date picker ---------- */
.ds-datepicker { position: relative; }
.ds-datepicker__panel {
    position: absolute; inset-block-start: calc(100% + 6px); inset-inline-start: 0;
    width: 296px; padding: var(--ds-space-3);
    background: var(--ds-surface-raised);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-shadow-md);
    z-index: var(--ds-z-dropdown);
    display: none;
}
.ds-datepicker.is-open .ds-datepicker__panel { display: block; animation: ds-pop-in var(--ds-duration-fast) var(--ds-ease-out) both; }
.ds-datepicker__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--ds-space-2); }
.ds-datepicker__month { font-weight: var(--ds-font-weight-bold); font-size: var(--ds-font-size-sm); }
.ds-datepicker__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.ds-datepicker__dow { text-align: center; color: var(--ds-text-subtle); font-size: var(--ds-font-size-xs); padding-block: 0.25rem; }
.ds-datepicker__day {
    border: 0; background: transparent; border-radius: var(--ds-radius-xs);
    padding: 0.4rem 0; cursor: pointer; font-size: var(--ds-font-size-sm); color: var(--ds-text-base);
}
.ds-datepicker__day:hover { background: var(--ds-surface-hover); }
.ds-datepicker__day.is-today { box-shadow: inset 0 0 0 1px var(--ds-brand-400); }
.ds-datepicker__day.is-selected { background: var(--ds-brand-600); color: #fff; }
.ds-datepicker__day.is-empty { visibility: hidden; }
.ds-datepicker__footer { display: flex; justify-content: space-between; margin-top: var(--ds-space-2); }

/* ---------- Auth pages ---------- */
.auth-shell, .ds-auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: var(--ds-space-6);
    background:
        radial-gradient(circle at 15% 15%, var(--ds-brand-100), transparent 34rem),
        radial-gradient(circle at 85% 85%, var(--ds-color-accent-soft), transparent 30rem),
        var(--ds-surface-canvas);
}
.auth-card { width: min(440px, 100%); padding: var(--ds-space-6); }
.auth-heading { margin-bottom: var(--ds-space-5); text-align: center; }
.auth-heading p { font-size: var(--ds-font-size-sm); }
.auth-aside { width: min(980px, 100%); display: grid; grid-template-columns: 1.05fr 0.95fr; gap: var(--ds-space-8); align-items: center; }

/* ---------- Misc legacy ---------- */
.check-list { margin: var(--ds-space-3) 0 0; padding-inline-start: 1.2rem; color: var(--ds-text-muted); }
.check-list li { margin-block: 0.35rem; }
.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ds-space-3); }
.feature-item { border: 1px solid var(--ds-border-subtle); border-radius: var(--ds-radius-sm); padding: var(--ds-space-3); background: var(--ds-surface-sunken); }
.feature-title { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-3); }
.feature-meta { display: flex; flex-wrap: wrap; gap: var(--ds-space-3); margin-top: 0.35rem; color: var(--ds-text-muted); font-size: var(--ds-font-size-xs); }
.date-chip { background: var(--ds-surface-base); border: 1px solid var(--ds-border-base); border-radius: var(--ds-radius-pill); padding: 0.4rem 0.9rem; color: var(--ds-text-muted); font-size: var(--ds-font-size-sm); white-space: nowrap; }
.error-card { max-width: 620px; margin-inline: auto; text-align: center; }
.trace { display: inline-block; margin-block: var(--ds-space-3); padding: 0.45rem 0.7rem; border-radius: var(--ds-radius-xs); background: var(--ds-surface-sunken); border: 1px solid var(--ds-border-subtle); font-size: var(--ds-font-size-xs); word-break: break-all; }
.page-heading { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--ds-space-4); margin-bottom: var(--ds-space-5); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid { grid-template-columns: 1fr; }
    .feature-grid { grid-template-columns: 1fr; }
    .auth-aside { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .stat-row { grid-template-columns: 1fr; }
}

/* ---------- POS (Phase 6) ---------- */
.pos-shell { display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 100vh; background: var(--ds-surface-canvas); }
.pos-main { display: flex; flex-direction: column; min-width: 0; }
.pos-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; background: var(--ds-surface-base); border-bottom: 1px solid var(--ds-border-subtle); }
.pos-body { padding: 1rem; flex: 1 1 auto; }
.pos-side { background: var(--ds-surface-base); border-inline-start: 1px solid var(--ds-border-subtle); padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.pos-total { display: flex; justify-content: space-between; padding: 0.35rem 0; }
.pos-total--grand { font-size: var(--ds-font-size-xl); font-weight: var(--ds-font-weight-bold); color: var(--ds-text-strong); border-top: 1px dashed var(--ds-border-base); padding-top: 0.6rem; }
.pos-cart input { width: 84px; }
.pos-keys { display: flex; flex-wrap: wrap; gap: 0.4rem; font-size: var(--ds-font-size-xs); color: var(--ds-text-muted); }
.kbd { border: 1px solid var(--ds-border-base); border-bottom-width: 2px; border-radius: 5px; padding: 0 0.35rem; font-family: ui-monospace, monospace; direction: ltr; }
.pos-parked { max-height: 200px; overflow: auto; }
@media print {
    .ds-header, .admin-nav, .ds-toasts, .no-print { display: none !important; }
    .ds-content { padding: 0; }
}
@media (max-width: 980px) { .pos-shell { grid-template-columns: 1fr; } }
