/**
 * Reusable component styles — the plain-CSS equivalent of the old
 * shadcn-vue ui/* components. Class names are deliberately close to the
 * old component names (btn ~ Button, card ~ Card, badge ~ Badge) so pages
 * read the same way they used to.
 */

/* Links */

.text-link {
    color: var(--foreground);
    text-decoration: underline;
    text-underline-offset: 3px;
}

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

/* Password input (show/hide toggle) */

.password-field {
    position: relative;
}

.password-field .input {
    padding-right: 2.5rem;
}

.password-toggle {
    position: absolute;
    inset: 0 0 0 auto;
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    color: var(--muted-foreground);
}

.password-toggle:hover {
    color: var(--foreground);
}

.password-toggle svg {
    width: 1rem;
    height: 1rem;
}

.status-message {
    margin-bottom: var(--space-4);
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--chart-1);
}

.alert-info {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    background: color-mix(in srgb, var(--chart-2) 12%, var(--background));
    border: 1px solid color-mix(in srgb, var(--chart-2) 30%, var(--border));
    color: var(--foreground);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    font-size: 0.875rem;
    margin-bottom: var(--space-4);
}

.alert-info svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
    color: var(--chart-2);
}

.spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 999px;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    white-space: nowrap;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    height: 2.25rem;
    padding: 0 var(--space-4);
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    border: 1px solid transparent;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.btn-sm {
    height: 2rem;
    padding: 0 var(--space-3);
    font-size: 0.8125rem;
}

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

.btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.btn-secondary:hover:not(:disabled) {
    opacity: 0.85;
}

.btn-outline {
    background: var(--background);
    border-color: var(--border);
    color: var(--foreground);
}

.btn-outline:hover:not(:disabled) {
    background: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--foreground);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--accent);
    color: var(--accent-foreground);
}

.btn-destructive {
    background: var(--destructive);
    color: var(--destructive-foreground);
}

.btn-destructive:hover:not(:disabled) {
    opacity: 0.9;
}

/* Card */

.card {
    background: var(--card);
    color: var(--card-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.card-header {
    padding: var(--space-6);
    padding-bottom: 0;
}

.card-content {
    padding: var(--space-6);
}

.card-footer {
    padding: var(--space-6);
    padding-top: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.card-title {
    font-weight: 600;
    font-size: 1rem;
    margin: 0 0 var(--space-1);
}

.card-description {
    font-size: 0.875rem;
    color: var(--muted-foreground);
}

/* Badge */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.125rem 0.625rem;
    border: 1px solid transparent;
    line-height: 1.4;
}

.badge-default {
    background: var(--primary);
    color: var(--primary-foreground);
}

.badge-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.badge-destructive {
    background: var(--destructive);
    color: var(--destructive-foreground);
}

.badge-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--foreground);
}

/* Status badge — colored dot + label */

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.8125rem;
    color: var(--foreground);
}

.status-badge::before {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    background: var(--muted-foreground);
    flex-shrink: 0;
}

.status-badge.is-active::before {
    background: var(--chart-1);
}

.status-badge.is-draft::before {
    background: var(--muted-foreground);
}

.status-badge.is-paused::before {
    background: var(--chart-4);
}

.status-badge.is-error::before,
.status-badge.is-destructive::before {
    background: var(--destructive);
}

/* Form controls */

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.field:last-child {
    margin-bottom: 0;
}

.label {
    font-size: 0.875rem;
    font-weight: 500;
}

.input,
.textarea,
.select {
    width: 100%;
    background: var(--background);
    border: 1px solid var(--input);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--foreground);
}

.input:focus,
.textarea:focus,
.select:focus {
    outline: 2px solid var(--ring);
    outline-offset: -1px;
}

.textarea {
    resize: vertical;
    min-height: 6rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.input-error {
    font-size: 0.8125rem;
    color: var(--destructive);
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--muted-foreground);
}

/* Heading (page title + description) */

.heading {
    margin-bottom: var(--space-6);
}

.heading h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.heading p {
    margin-top: var(--space-1);
    font-size: 0.875rem;
    color: var(--muted-foreground);
}

/* Empty state */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-16) var(--space-6);
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--muted-foreground);
}

.empty-state h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--foreground);
    margin-bottom: var(--space-2);
}

.empty-state p {
    font-size: 0.875rem;
    max-width: 28rem;
    margin-bottom: var(--space-4);
}

/* Table */

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

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

table.table th {
    text-align: left;
    font-weight: 500;
    color: var(--muted-foreground);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

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

table.table tbody tr.is-linked {
    cursor: pointer;
}

table.table tbody tr.is-linked:hover {
    background: var(--accent);
}

/* Resource list row (card-style list item used on most index pages) */

.resource-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card);
}

.resource-row + .resource-row {
    margin-top: var(--space-3);
}

.resource-row .resource-title {
    font-weight: 500;
    font-size: 0.9375rem;
}

.resource-row .resource-meta {
    display: flex;
    gap: var(--space-4);
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    margin-top: var(--space-1);
}

.resource-list {
    display: flex;
    flex-direction: column;
}

/* Dropdown menu (Alpine-driven) */

.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    z-index: 40;
    min-width: 12rem;
    background: var(--popover);
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: var(--space-1);
    top: calc(100% + 0.25rem);
    right: 0;
}

.dropdown-menu.align-left {
    right: auto;
    left: 0;
}

.dropdown-label {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    padding: var(--space-2) var(--space-3);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

.dropdown-item:hover {
    background: var(--accent);
    color: var(--accent-foreground);
}

.dropdown-item svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.dropdown-separator {
    height: 1px;
    background: var(--border);
    margin: var(--space-1) 0;
}

/* Dialog (native <dialog>) */

dialog.modal {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 0;
    background: var(--card);
    color: var(--card-foreground);
    width: min(28rem, calc(100vw - 2rem));
}

dialog.modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
}

.modal-header {
    padding: var(--space-6);
    padding-bottom: var(--space-4);
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-header p {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin-top: var(--space-1);
}

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

.modal-footer {
    padding: var(--space-6);
    padding-top: var(--space-4);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* Tabs */

.tabs-list {
    display: inline-flex;
    gap: var(--space-1);
    background: var(--muted);
    padding: 0.25rem;
    border-radius: var(--radius-md);
}

.tabs-trigger {
    padding: 0.375rem 0.875rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--muted-foreground);
}

.tabs-trigger.is-active {
    background: var(--background);
    color: var(--foreground);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

/* Separator */

.separator {
    height: 1px;
    background: var(--border);
    border: none;
    margin: var(--space-6) 0;
}

/* Utility layout classes used across pages */

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

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

.row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

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

.text-muted {
    color: var(--muted-foreground);
}

.text-sm {
    font-size: 0.875rem;
}

/* Stat tiles */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
}

@media (min-width: 768px) {
    .stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.stat-tile {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.stat-tile-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.stat-tile-icon {
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-tile-icon svg {
    width: 1rem;
    height: 1rem;
}

.stat-tile-label {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-tile-value {
    margin-top: var(--space-3);
    font-size: 1.5rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.stat-tile-hint {
    margin-top: var(--space-1);
    font-size: 0.75rem;
    color: var(--muted-foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Bar chart (daily activity) */

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.375rem;
    height: 10rem;
}

.bar-chart-col {
    position: relative;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: flex-end;
}

.bar-chart-bar {
    width: 100%;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--muted);
    transition: opacity 0.15s;
}

.bar-chart-bar.has-value {
    background: var(--chart-1);
}

.bar-chart-col:hover .bar-chart-bar {
    opacity: 0.8;
}

.bar-chart-labels {
    display: flex;
    gap: 0.375rem;
    margin-top: var(--space-2);
}

.bar-chart-labels span {
    flex: 1;
    text-align: center;
    font-size: 0.625rem;
    color: var(--muted-foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 0.375rem;
    background: var(--popover);
    color: var(--popover-foreground);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--space-2);
    font-size: 0.75rem;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

/* Segment value bars */

.segment-bar-row {
    position: relative;
    margin-bottom: var(--space-3);
}

.segment-bar-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    font-size: 0.875rem;
    margin-bottom: var(--space-1);
}

.segment-bar-track {
    height: 1.5rem;
    width: 100%;
    background: var(--muted);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.segment-bar-fill {
    height: 100%;
    background: var(--chart-1);
    border-radius: var(--radius-md);
}

/* Question answer card */

.qa-card {
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.qa-answer-row {
    margin-bottom: var(--space-2);
}

.qa-answer-head {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    font-size: 0.875rem;
    margin-bottom: var(--space-1);
}

.qa-answer-track {
    height: 0.5rem;
    width: 100%;
    background: var(--muted);
    border-radius: 999px;
    overflow: hidden;
}

.qa-answer-fill {
    height: 100%;
    background: var(--chart-1);
    border-radius: 999px;
}

/* Lead row */

.lead-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-2);
    margin: 0 calc(var(--space-2) * -1);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.lead-row:hover {
    background: color-mix(in srgb, var(--muted) 60%, transparent);
}

/* Settings shell */

.settings-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

@media (min-width: 1024px) {
    .settings-wrap {
        flex-direction: row;
    }
}

.settings-nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    width: 100%;
}

@media (min-width: 1024px) {
    .settings-nav {
        width: 12rem;
        flex-shrink: 0;
    }
}

.settings-nav-item {
    display: block;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--foreground);
}

.settings-nav-item:hover {
    background: var(--accent);
}

.settings-nav-item.is-active {
    background: var(--muted);
    font-weight: 500;
}

.settings-content {
    flex: 1;
    max-width: 36rem;
}

.danger-zone {
    border: 1px solid color-mix(in srgb, var(--destructive) 25%, var(--border));
    background: color-mix(in srgb, var(--destructive) 6%, var(--background));
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

.danger-zone .warning-title {
    color: var(--destructive);
    font-weight: 500;
}

.danger-zone .warning-text {
    color: var(--destructive);
    font-size: 0.875rem;
    margin-top: 0.125rem;
}

/* Status pill (StatusBadge equivalent) — consistent status→color mapping,
   always paired with the status word, never color alone. */

.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    width: fit-content;
    flex-shrink: 0;
    border-radius: 999px;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    text-transform: capitalize;
}

.badge-status::before {
    content: '';
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 999px;
    background: currentColor;
}

.badge-status-active,
.badge-status-running {
    background: color-mix(in srgb, var(--chart-1) 18%, transparent);
    color: var(--chart-1);
}

.badge-status-completed {
    background: color-mix(in srgb, var(--chart-2) 18%, transparent);
    color: var(--chart-2);
}

.badge-status-draft {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.badge-status-paused {
    background: color-mix(in srgb, var(--chart-4) 20%, transparent);
    color: var(--chart-4);
}

.badge-status-archived {
    background: var(--muted);
    color: var(--muted-foreground);
}

/* Resource list row — whole-row-clickable list item used across every
   resource index page (segments, campaigns, automations, ...). */

.resource-list-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    border: 1px solid var(--border);
    background: var(--card);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.resource-list-row:hover {
    border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.resource-list-row + .resource-list-row {
    margin-top: var(--space-3);
}

.resource-list-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-md);
    background: var(--muted);
    color: var(--muted-foreground);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.resource-list-icon svg {
    width: 1rem;
    height: 1rem;
}

.resource-list-main {
    min-width: 0;
    flex: 1;
}

.resource-list-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.resource-list-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resource-list-meta {
    margin-top: 0.125rem;
    font-size: 0.875rem;
    color: var(--muted-foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resource-list-stats {
    display: none;
    flex-shrink: 0;
    align-items: center;
    gap: var(--space-5);
}

@media (min-width: 640px) {
    .resource-list-stats {
        display: flex;
    }
}

.resource-list-stat {
    text-align: right;
}

.resource-list-stat .stat-value {
    font-size: 0.875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.resource-list-stat .stat-label {
    font-size: 0.75rem;
    color: var(--muted-foreground);
}

.resource-list-chevron {
    width: 1rem;
    height: 1rem;
    color: var(--muted-foreground);
    flex-shrink: 0;
}

/* Segment condition tree */

.cond-group {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
}

.cond-group[data-depth="0"] {
    background: var(--card);
}

.cond-group[data-depth]:not([data-depth="0"]) {
    background: color-mix(in srgb, var(--muted) 40%, transparent);
}

.cond-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.cond-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    border: 1px solid var(--border);
    background: var(--background);
    border-radius: var(--radius-md);
    padding: var(--space-2);
}

/* Switch (toggle) */

.switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 2.25rem;
    height: 1.25rem;
    flex-shrink: 0;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.switch-track {
    position: absolute;
    inset: 0;
    background: var(--input);
    border-radius: 999px;
    transition: background-color 0.15s;
}

.switch-thumb {
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1rem;
    height: 1rem;
    background: var(--background);
    border-radius: 999px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s;
}

.switch input:checked ~ .switch-track {
    background: var(--primary);
}

.switch input:checked ~ .switch-thumb {
    transform: translateX(1rem);
}

/* Reorder arrows */

.reorder-arrows {
    display: flex;
    flex-direction: column;
}

.reorder-arrows button {
    color: var(--muted-foreground);
    padding: 0.125rem;
}

.reorder-arrows button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.reorder-arrows svg {
    width: 0.875rem;
    height: 0.875rem;
}
