/* ============================================
   DataLink Tech Portal v01 — Components
   Buttons, cards, inputs, tables, modals, etc.
   ============================================ */

/* ==== BUTTONS ==== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--touch-min);
    padding: 10px 20px;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: var(--weight-semi);
    line-height: 1;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-default);
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.btn-primary {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: var(--accent-dim);
}

.btn-primary:hover {
    background: var(--accent-bright);
}

.btn-primary:active {
    background: var(--accent-dim);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-default);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-success {
    background: var(--color-success);
    color: var(--text-inverse);
}

.btn-danger {
    background: var(--color-danger);
    color: var(--text-primary);
}

.btn-sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: var(--text-xs);
}

.btn-lg {
    min-height: 52px;
    padding: 14px 28px;
    font-size: var(--text-base);
}

.btn-icon {
    width: var(--touch-min);
    height: var(--touch-min);
    padding: 0;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: transparent;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-group {
    display: flex;
    gap: var(--space-2);
}


/* ==== CARDS ==== */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-accent {
    border-left: 4px solid var(--accent);
}

.card-accent-success {
    border-left: 4px solid var(--color-success);
}

.card-accent-danger {
    border-left: 4px solid var(--color-danger);
}

.card-accent-info {
    border-left: 4px solid var(--color-info);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
}

.card-title {
    font-family: var(--font-display);
    font-size: var(--text-base);
    font-weight: var(--weight-bold);
    color: var(--accent-primary);
}

.card-body {
    padding: var(--space-4);
}

.card-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
}


/* ==== FORM INPUTS ==== */

.field-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.field-label {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
}

.field-input {
    min-height: var(--touch-min);
    padding: 10px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 16px;
    transition: border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default);
}

.field-input:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
    outline: none;
}

.field-input::placeholder {
    color: var(--text-muted);
}

.field-input.mono {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

select.field-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b65' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.field-input {
    min-height: 80px;
    resize: vertical;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-4);
}

.field-row {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
}

.field-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.field-error {
    font-size: var(--text-xs);
    color: var(--color-danger);
}

/* Toggle / Checkbox */
.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    min-height: var(--touch-min);
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    width: 44px;
    height: 24px;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-default);
    transition: background var(--duration-fast) var(--ease-default);
    position: relative;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: var(--radius-full);
    transition: transform var(--duration-fast) var(--ease-default),
                background var(--duration-fast) var(--ease-default);
}

.toggle input:checked + .toggle-track {
    background: var(--accent-subtle);
    border-color: var(--accent);
}

.toggle input:checked + .toggle-track::after {
    transform: translateX(20px);
    background: var(--accent);
}


/* ==== SEGMENTED CONTROL ==== */

.segmented {
    display: inline-flex;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 2px;
}

.segmented-btn {
    padding: 8px 16px;
    min-height: 36px;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-default);
    white-space: nowrap;
}

.segmented-btn:hover {
    color: var(--text-primary);
}

.segmented-btn.active {
    background: var(--bg-surface);
    color: var(--accent);
    box-shadow: var(--shadow-sm);
}


/* ==== TABLES ==== */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table th {
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    font-weight: var(--weight-semi);
    color: var(--text-secondary);
    text-align: left;
    padding: var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
    z-index: var(--z-base);
}

.table td {
    padding: var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
}

.table tr:last-child td {
    border-bottom: none;
}

.table tr:hover td {
    background: var(--bg-hover);
}

.table-sticky-col td:first-child,
.table-sticky-col th:first-child {
    position: sticky;
    left: 0;
    background: var(--bg-surface);
    z-index: calc(var(--z-base) + 1);
    border-right: 1px solid var(--border-default);
}


/* ==== BADGES ==== */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semi);
    border-radius: var(--radius-full);
    line-height: 1;
    white-space: nowrap;
}

.badge-default {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.badge-accent {
    background: var(--accent-subtle);
    color: var(--accent);
}

.badge-success {
    background: var(--color-success-dim);
    color: var(--color-success);
}

.badge-warning {
    background: var(--color-warning-dim);
    color: var(--color-warning);
}

.badge-danger {
    background: var(--color-danger-dim);
    color: var(--color-danger);
}

.badge-info {
    background: var(--color-info-dim);
    color: var(--color-info);
}


/* ==== STATUS DOT ==== */

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.status-dot-pass { background: var(--status-pass); }
.status-dot-fail { background: var(--status-fail); }
.status-dot-ni   { background: var(--status-ni); }
.status-dot-na   { background: var(--status-na); }


/* ==== MODAL ==== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--z-modal);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: var(--space-4);
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-default);
}

.modal-backdrop.visible {
    opacity: 1;
}

.modal-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    width: 100%;
    max-width: 600px;
    max-height: 85dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform var(--duration-normal) var(--ease-out);
}

.modal-backdrop.visible .modal-panel {
    transform: translateY(0);
}

.modal-handle {
    display: flex;
    justify-content: center;
    padding: var(--space-3) 0 var(--space-1);
}

.modal-handle::after {
    content: '';
    width: 36px;
    height: 4px;
    background: var(--border-default);
    border-radius: var(--radius-full);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4) var(--space-4);
}

.modal-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: var(--weight-bold);
}

.modal-body {
    padding: 0 var(--space-4) var(--space-4);
}

.modal-footer {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
}

/* Desktop: center modal */
@media (min-width: 768px) {
    .modal-backdrop {
        align-items: center;
    }
    .modal-panel {
        border-radius: var(--radius-xl);
        transform: translateY(20px);
    }
    .modal-handle {
        display: none;
    }
}


/* ==== TOAST ==== */

.toast-container {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--space-4) + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-2);
    pointer-events: none;
    width: calc(100% - var(--space-8));
    max-width: 420px;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toast-in var(--duration-normal) var(--ease-out);
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.toast.removing {
    animation: toast-out var(--duration-fast) var(--ease-default) forwards;
}

.toast-accent {
    width: 4px;
    height: 24px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.toast-success .toast-accent { background: var(--color-success); }
.toast-warning .toast-accent { background: var(--color-warning); }
.toast-danger  .toast-accent { background: var(--color-danger); }
.toast-info    .toast-accent { background: var(--color-info); }

.toast-message {
    flex: 1;
}

.toast-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

@keyframes toast-in {
    from {
        transform: translateY(16px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    to {
        transform: translateY(16px);
        opacity: 0;
    }
}


/* ==== SECTION COLLAPSE ==== */

.section {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: var(--space-4);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    min-height: var(--touch-min);
}

.section-title {
    font-family: var(--font-display);
    font-size: var(--text-sm);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.section-chevron {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    transition: transform var(--duration-normal) var(--ease-default);
}

.section.collapsed .section-chevron {
    transform: rotate(-90deg);
}

.section-body {
    padding: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

.section.collapsed .section-body {
    display: none;
}


/* ==== STATS GRID ==== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}

.stat-value {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: var(--space-1);
}

.stat-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-detail {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}


/* ==== UTILITY CLASSES ==== */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.p-4 { padding: var(--space-4); }
.hidden { display: none !important; }
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
