/* ==========================================================================
   Design System — standardized component classes for patterns the
   Shared Component Library (shared-components.css) does not yet cover:
   Form controls, Data Tables, Icon sizing, generic motion utilities,
   and Layout tokens. Everything here reads only `--ds-*`/`--shared-*`
   custom properties from design-tokens.css — load that file first.

   Load order on a page:
     1. design-tokens.css   (variables only)
     2. design-system.css   (this file — generic standardized classes)
     3. shared-components.css (Shared Component Library classes)
     4. the page's own stylesheet (palette mapping + page-specific layout)
   ========================================================================== */

/* ==========================================================================
   Layout System
   ========================================================================== */

:root {
    --ds-container-width: 1200px;
    --ds-sidebar-width: 280px;
    --ds-header-height: 64px;
    --ds-content-max-width: 780px;
    --ds-page-margin: var(--ds-space-16);
    --ds-section-gap: var(--ds-space-24);
    --ds-grid-columns: 12;
}

.ds-container {
    width: 100%;
    max-width: var(--ds-container-width);
    margin-inline: auto;
    padding-inline: var(--ds-page-margin);
}
.ds-content-width { max-width: var(--ds-content-max-width); margin-inline: auto; }
.ds-section-stack > * + * { margin-top: var(--ds-section-gap); }

.ds-grid {
    display: grid;
    grid-template-columns: repeat(var(--ds-grid-columns), 1fr);
    gap: var(--ds-space-16);
}
@media (max-width: 767px) {
    .ds-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ==========================================================================
   Form System
   ========================================================================== */

.ds-field { display: flex; flex-direction: column; gap: var(--ds-space-4); margin-bottom: var(--ds-space-16); }
.ds-field__label {
    font-size: var(--ds-text-small-size);
    font-weight: 700;
    color: var(--shared-text);
}
.ds-field__label .ds-field__required { color: var(--ds-color-danger); margin-left: 2px; }
.ds-field__help { font-size: var(--ds-text-caption-size); color: var(--shared-text-muted); margin: 0; }
.ds-field__error {
    font-size: var(--ds-text-caption-size);
    color: var(--ds-color-danger);
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--ds-space-4);
}
.ds-field.has-error .ds-input,
.ds-field.has-error .ds-textarea,
.ds-field.has-error .ds-select {
    border-color: var(--ds-color-danger);
}

/* Textbox / Textarea / Dropdown (select) share one visual language */
.ds-input,
.ds-textarea,
.ds-select {
    width: 100%;
    font-family: var(--shared-font-body);
    font-size: var(--ds-text-body-size);
    color: var(--shared-text);
    background: var(--shared-surface);
    border: 1px solid var(--shared-border);
    border-radius: var(--ds-radius-sm);
    padding: var(--ds-space-8) var(--ds-space-12);
    transition: border-color var(--ds-motion-fast) var(--ds-motion-easing),
        box-shadow var(--ds-motion-fast) var(--ds-motion-easing);
}
.ds-textarea { min-height: 6rem; resize: vertical; }
.ds-input:focus,
.ds-textarea:focus,
.ds-select:focus {
    outline: none;
    border-color: var(--ds-color-focus-ring);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ds-color-focus-ring) 25%, transparent);
}
.ds-input:disabled,
.ds-textarea:disabled,
.ds-select:disabled {
    background: var(--ds-color-disabled-bg);
    color: var(--ds-color-disabled-text);
    cursor: not-allowed;
}
.ds-input::placeholder,
.ds-textarea::placeholder { color: var(--shared-text-muted); }

/* Checkbox / Radio — native inputs, styled minimally so keyboard and
   screen-reader behavior stays exactly the native behavior (per
   docs/accessibility-guide.md, custom-widget checkboxes/radios are the
   single most common accessibility regression in hand-rolled forms). */
.ds-checkbox,
.ds-radio {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-8);
    font-size: var(--ds-text-body-size);
    color: var(--shared-text);
    cursor: pointer;
}
.ds-checkbox input,
.ds-radio input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--shared-accent);
    cursor: pointer;
}

/* Toggle (switch) — a checkbox underneath, styled as a track + thumb */
.ds-toggle { display: inline-flex; align-items: center; gap: var(--ds-space-8); cursor: pointer; }
.ds-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ds-toggle__track {
    width: 2.5rem;
    height: 1.4rem;
    border-radius: var(--ds-radius-pill);
    background: var(--shared-border);
    position: relative;
    transition: background var(--ds-motion-base) var(--ds-motion-easing);
}
.ds-toggle__track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    background: var(--shared-surface);
    transition: transform var(--ds-motion-base) var(--ds-motion-easing);
}
.ds-toggle input:checked + .ds-toggle__track { background: var(--shared-accent); }
.ds-toggle input:checked + .ds-toggle__track::after { transform: translateX(1.1rem); }
.ds-toggle input:focus-visible + .ds-toggle__track { outline: 3px solid var(--ds-color-focus-ring); outline-offset: 2px; }

/* Search reuses SearchBox (shared-components.css .shared-search-box) —
   no second search input style exists here, by design. */

/* Upload */
.ds-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--ds-space-8);
    border: 2px dashed var(--shared-border);
    border-radius: var(--ds-radius-md);
    padding: var(--ds-space-24);
    text-align: center;
    color: var(--shared-text-muted);
    background: var(--shared-surface-alt);
}
.ds-upload:hover { border-color: var(--shared-accent); }

/* Date picker — a styled native <input type="date"> rather than a
   custom calendar widget, so browser/OS date-picker accessibility and
   locale formatting are never reimplemented. */
.ds-date-input {
    width: 100%;
    font-family: var(--shared-font-body);
    font-size: var(--ds-text-body-size);
    color: var(--shared-text);
    background: var(--shared-surface);
    border: 1px solid var(--shared-border);
    border-radius: var(--ds-radius-sm);
    padding: var(--ds-space-8) var(--ds-space-12);
}

/* ==========================================================================
   Table System
   ========================================================================== */

.ds-table-responsive { width: 100%; overflow-x: auto; }
.ds-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--ds-text-body-size);
    color: var(--shared-text);
}
.ds-table th,
.ds-table td {
    padding: var(--ds-space-12) var(--ds-space-16);
    text-align: left;
    border-bottom: 1px solid var(--shared-border);
}
.ds-table thead th {
    font-family: var(--shared-font-heading);
    font-weight: 700;
    font-size: var(--ds-text-small-size);
    color: var(--shared-text-muted);
    background: var(--shared-surface-alt);
}
.ds-table--striped tbody tr:nth-child(odd) { background: var(--shared-surface-alt); }
.ds-table--hover tbody tr:hover { background: var(--ds-color-hover-overlay); }
.ds-table--compact th,
.ds-table--compact td { padding: var(--ds-space-8) var(--ds-space-12); }

.ds-table [data-sortable] {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-4);
}
.ds-table [data-sort-direction="asc"]::after { content: '\25B2'; font-size: 0.7em; }
.ds-table [data-sort-direction="desc"]::after { content: '\25BC'; font-size: 0.7em; }

/* Table pagination reuses Pagination (shared-components.css
   .shared-pagination) — no second pagination style exists here. */

/* ==========================================================================
   Icon System — sizing utilities only; icons themselves stay inline
   emoji/Unicode glyphs (this codebase's established convention, see
   docs/component-standards.md's Icon Guidelines) rather than an icon
   font or SVG sprite dependency.
   ========================================================================== */

.ds-icon-sm { font-size: 1rem; line-height: 1; }
.ds-icon-md { font-size: 1.4rem; line-height: 1; }
.ds-icon-lg { font-size: 2rem; line-height: 1; }
.ds-icon-xl { font-size: 2.5rem; line-height: 1; }

/* ==========================================================================
   Animation System — Fade/Slide/Collapse/Expand utilities. Skeleton
   (LoadingSkeleton), Toast (ToastNotification), and Dialog (Modal) are
   already implemented as Shared Components; Hover/Focus motion is
   defined per-component (buttons, links, form controls above).
   ========================================================================== */

.ds-fade-in { animation: ds-fade-in var(--ds-motion-base) var(--ds-motion-easing); }
@keyframes ds-fade-in { from { opacity: 0; } to { opacity: 1; } }

.ds-slide-up { animation: ds-slide-up var(--ds-motion-base) var(--ds-motion-easing); }
@keyframes ds-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.ds-collapse {
    overflow: hidden;
    max-height: 0;
    transition: max-height var(--ds-motion-base) var(--ds-motion-easing);
}
.ds-collapse.is-expanded { max-height: var(--ds-collapse-content-height, 1000px); }

@media (prefers-reduced-motion: reduce) {
    .ds-fade-in, .ds-slide-up, .ds-collapse { animation: none; transition: none; }
}
