/* =========================================================
   Reusable Components
   ========================================================= */

/* ---------- Buttons (Material 3) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: 10px 20px;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.01em;
    border-radius: var(--r-full);
    transition:
        background var(--d-short) var(--ease-standard),
        box-shadow var(--d-short) var(--ease-standard),
        transform var(--d-short) var(--ease-standard),
        color var(--d-short) var(--ease-standard);
    white-space: nowrap;
    position: relative;
}

.btn__icon {
    font-size: 18px;
}

.btn--sm {
    padding: 8px 14px;
    font-size: 13px;
}
.btn--lg {
    padding: 14px 28px;
    font-size: 15px;
}

.btn--text {
    color: var(--md-primary-strong);
}
.btn--text:hover {
    background: var(--md-hover-layer);
}

.btn--filled {
    background: var(--md-primary-strong);
    color: #fff;
    box-shadow: var(--e-1);
}
[data-theme="dark"] .btn--filled {
    color: var(--md-on-primary);
}
.btn--filled:hover {
    box-shadow: var(--e-2);
    transform: translateY(-1px);
}
.btn--filled:active {
    transform: translateY(0);
}

.btn--tonal {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}
.btn--tonal:hover {
    filter: brightness(0.96);
}
[data-theme="dark"] .btn--tonal:hover {
    filter: brightness(1.1);
}

.btn--outlined {
    background: transparent;
    color: var(--md-primary-strong);
    box-shadow: inset 0 0 0 1px var(--md-outline-strong);
}
.btn--outlined:hover {
    background: var(--md-hover-layer);
}

.btn--danger {
    background: var(--md-error-container);
    color: var(--md-on-error-container);
}

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

/* ---------- Icon button ---------- */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--r-full);
    display: inline-grid;
    place-items: center;
    color: var(--md-on-surface);
    transition: background var(--d-short) var(--ease-standard);
}
.icon-btn:hover {
    background: var(--md-hover-layer);
}
.icon-btn--lg {
    width: 44px;
    height: 44px;
}
.icon-btn--lg .material-symbols-outlined {
    font-size: 24px;
}

/* ---------- Chips ---------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: 4px 12px;
    border-radius: var(--r-full);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.02em;
}
.chip--tonal {
    background: var(--md-primary-container);
    color: var(--md-on-primary-container);
}
.chip--mint {
    background: var(--md-tertiary-container);
    color: var(--md-on-tertiary-container);
}
.chip--lavender {
    background: var(--md-secondary-container);
    color: var(--md-on-secondary-container);
    padding: 0.3em 1.5em 0.3em 1.5em;
}
.chip--peach {
    background: var(--md-accent-peach-container);
    color: var(--md-on-accent-peach-container);
}
.chip--neutral {
    background: var(--md-surface-variant);
    color: var(--md-on-surface-muted);
}
.chip--success {
    background: var(--md-tertiary-container);
    color: var(--md-on-tertiary-container);
}
.chip--error {
    background: var(--md-error-container);
    color: var(--md-on-error-container);
}

.chip__icon {
    font-size: 14px;
}

/* ---------- Card / Surface ---------- */
.card {
    background: var(--md-surface-elevated);
    border: 1px solid var(--md-outline);
    border-radius: var(--r-lg);
    box-shadow: var(--e-1);
    transition:
        box-shadow var(--d-med) var(--ease-standard),
        transform var(--d-med) var(--ease-standard),
        border-color var(--d-med) var(--ease-standard);
}

.card--interactive {
    cursor: pointer;
}
.card--interactive:hover {
    box-shadow: var(--e-3);
    transform: translateY(-2px);
    border-color: var(--md-outline-strong);
}

/* ---------- Table ---------- */
.data-table-wrap {
    background: var(--md-surface-elevated);
    border: 1px solid var(--md-outline);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--e-1);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead {
    background: var(--md-surface-variant);
}

.data-table th {
    text-align: left;
    padding: var(--s-4) var(--s-5);
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--md-on-surface-muted);
    border-bottom: 1px solid var(--md-outline);
}

.data-table td {
    padding: var(--s-4) var(--s-5);
    border-bottom: 1px solid var(--md-outline);
    color: var(--md-on-surface);
}

.data-table tbody tr {
    transition: background var(--d-short) var(--ease-standard);
}
.data-table tbody tr:hover {
    background: var(--md-hover-layer);
}
.data-table tbody tr.is-clickable {
    cursor: pointer;
}
.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Compact density */
[data-density="compact"] .data-table th {
    padding: var(--s-3) var(--s-4);
}
[data-density="compact"] .data-table td {
    padding: var(--s-3) var(--s-4);
    font-size: 13px;
}

.data-table .cell--strong {
    font-weight: 500;
    color: var(--md-on-surface);
}
.data-table .cell--muted {
    color: var(--md-on-surface-muted);
}
.data-table .cell--mono {
    font-family: var(--font-mono);
    font-size: 13px;
}
.data-table .cell--num {
    font-variant-numeric: tabular-nums;
}
.data-table .cell--right {
    text-align: right;
}

.table-empty {
    padding: var(--s-12) var(--s-6);
    text-align: center;
    color: var(--md-on-surface-muted);
}
.table-empty .material-symbols-outlined {
    font-size: 48px;
    color: var(--md-on-surface-subtle);
    margin-bottom: var(--s-3);
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-3) var(--s-5);
    background: var(--md-surface-elevated);
    border-top: 1px solid var(--md-outline);
}

.pagination__info {
    font-size: 13px;
    color: var(--md-on-surface-muted);
}

.pagination__controls {
    display: flex;
    gap: var(--s-1);
    align-items: center;
}

.pagination__btn {
    width: 32px;
    height: 32px;
    border-radius: var(--r-full);
    display: grid;
    place-items: center;
    color: var(--md-on-surface);
    transition: background var(--d-short) var(--ease-standard);
}
.pagination__btn:hover:not([disabled]) {
    background: var(--md-hover-layer);
}
.pagination__btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ---------- Text Field (Material 3) ---------- */
.text-field {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: 12px 16px;
    background: var(--md-surface-elevated);
    border: 1px solid var(--md-outline-strong);
    border-radius: var(--r-md);
    transition:
        border-color var(--d-short) var(--ease-standard),
        box-shadow var(--d-short) var(--ease-standard);
    width: 100%;
}

.text-field:focus-within {
    border-color: var(--md-primary-strong);
    box-shadow: 0 0 0 3px var(--md-primary-container);
}

.text-field__icon {
    font-size: 20px;
    color: var(--md-on-surface-muted);
    flex-shrink: 0;
}

.text-field input,
.text-field textarea {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    resize: none;
}

.text-field textarea {
    min-height: 60px;
    line-height: 1.5;
}

.text-field__label {
    display: block;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 13px;
    margin-bottom: var(--s-2);
    color: var(--md-on-surface);
}

/* ---------- NL Prompt Box (large input) ---------- */
.nl-prompt {
    background: var(--md-surface-elevated);
    border: 1px solid var(--md-outline-strong);
    border-radius: var(--r-xl);
    padding: var(--s-5);
    box-shadow: var(--e-2);
    transition:
        border-color var(--d-short) var(--ease-standard),
        box-shadow var(--d-short) var(--ease-standard);
}

.nl-prompt:focus-within {
    border-color: var(--md-primary-strong);
    box-shadow:
        var(--e-3),
        0 0 0 3px var(--md-primary-container);
}

.nl-prompt__label {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 14px;
    margin-bottom: var(--s-3);
    color: var(--md-on-surface);
}

.nl-prompt__label .material-symbols-outlined {
    font-size: 18px;
    color: var(--md-primary-strong);
}

.nl-prompt__textarea {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    resize: none;
    min-height: 64px;
    color: var(--md-on-surface);
}

.nl-prompt__textarea::placeholder {
    color: var(--md-on-surface-subtle);
}

.nl-prompt__footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--s-3);
    padding-top: var(--s-3);
    border-top: 1px solid var(--md-outline);
}

.nl-prompt__hint {
    font-size: 12px;
    color: var(--md-on-surface-subtle);
}

/* ---------- Segmented control ---------- */
.seg-control {
    display: inline-flex;
    background: var(--md-surface-variant);
    border-radius: var(--r-full);
    padding: 4px;
    gap: 2px;
}

.seg-control__opt {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--md-on-surface-muted);
    border-radius: var(--r-full);
    transition:
        background var(--d-short) var(--ease-standard),
        color var(--d-short) var(--ease-standard);
}

.seg-control__opt .material-symbols-outlined {
    font-size: 16px;
}

.seg-control__opt[aria-checked="true"],
.seg-control__opt.is-active {
    background: var(--md-surface-elevated);
    color: var(--md-on-surface);
    box-shadow: var(--e-1);
}

/* ---------- Drawer ---------- */
.drawer-scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
    animation: fade-in var(--d-med) var(--ease-standard);
}

/* Critical: the [hidden] attribute must win over the positioning rules above. */
.drawer-scrim[hidden],
.drawer[hidden],
.modal-root[hidden] {
    display: none !important;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 90vw;
    background: var(--md-surface-elevated);
    border-left: 1px solid var(--md-outline);
    box-shadow: var(--e-4);
    z-index: 100;
    display: flex;
    flex-direction: column;
    animation: slide-in-right var(--d-long) var(--ease-emphasized);
}

.drawer__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-5) var(--s-6);
    border-bottom: 1px solid var(--md-outline);
}
.drawer__title {
    font-family: var(--font-display);
    font-size: 20px;
}

.drawer__body {
    padding: var(--s-6);
    overflow-y: auto;
    flex: 1;
}

.settings-block {
    margin-bottom: var(--s-8);
}
.settings-block:last-child {
    margin-bottom: 0;
}

.settings-block__title {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--md-on-surface-muted);
    margin-bottom: var(--s-3);
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    padding: var(--s-4) 0;
    border-bottom: 1px solid var(--md-outline);
}
.settings-row:last-child {
    border-bottom: none;
}
.settings-row--stacked {
    flex-direction: column;
    align-items: stretch;
    gap: var(--s-3);
}

.settings-row__text strong {
    display: block;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 14px;
    color: var(--md-on-surface);
}
.settings-row__text small {
    font-size: 12px;
    color: var(--md-on-surface-muted);
}

.hint {
    font-size: 12px;
    margin: 0;
    color: var(--md-on-surface-muted);
}
.hint--success {
    color: #1e6b4f;
}
[data-theme="dark"] .hint--success {
    color: var(--md-tertiary);
}

/* ---------- Modal ---------- */
.modal-root {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.4);
    animation: fade-in var(--d-med) var(--ease-standard);
    padding: var(--s-4);
}

.modal {
    background: var(--md-surface-elevated);
    border-radius: var(--r-xl);
    box-shadow: var(--e-4);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: modal-pop var(--d-long) var(--ease-emphasized);
}

.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--s-5) var(--s-6) var(--s-3);
}

.modal__title {
    font-family: var(--font-display);
    font-size: 22px;
}

.modal__step {
    font-size: 12px;
    color: var(--md-on-surface-muted);
    margin-top: var(--s-1);
}

.modal__body {
    padding: var(--s-3) var(--s-6) var(--s-5);
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
}

.modal__foot {
    display: flex;
    justify-content: flex-end;
    gap: var(--s-3);
    padding: var(--s-4) var(--s-6) var(--s-5);
    border-top: 1px solid var(--md-outline);
}

/* ---------- Mail-not-connected banner (campaign modal) ---------- */
.mail-banner {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    background: var(--md-accent-peach, #fdecd8);
    color: var(--md-on-surface);
    border: 1px solid var(--md-outline);
}
/* HTML5 `hidden` is display:none by default, but our display:flex above wins
   on specificity. Restore the intended hiding behavior. */
.mail-banner[hidden] {
    display: none;
}
[data-theme="dark"] .mail-banner {
    background: var(--md-surface-variant);
}
.mail-banner__icon {
    font-size: 28px;
    color: var(--md-primary-strong);
    flex-shrink: 0;
}
.mail-banner__body {
    flex: 1;
    min-width: 0;
}
.mail-banner__body strong {
    display: block;
    font-size: 14px;
    margin-bottom: 2px;
}
.mail-banner__body p {
    margin: 0;
    font-size: 13px;
    color: var(--md-on-surface-muted);
}

/* ---------- Toasts ---------- */
.toast-root {
    position: fixed;
    bottom: var(--s-6);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: var(--s-2);
    pointer-events: none;
}

.toast {
    background: #2e3033;
    color: #fff;
    padding: var(--s-3) var(--s-5);
    border-radius: var(--r-md);
    box-shadow: var(--e-3);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: var(--s-2);
    animation: toast-in var(--d-long) var(--ease-emphasized);
}

[data-theme="dark"] .toast {
    background: var(--md-surface-variant);
    color: var(--md-on-surface);
    border: 1px solid var(--md-outline);
}

.toast .material-symbols-outlined {
    font-size: 18px;
}

/* ---------- Animations ---------- */
@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
@keyframes slide-in-right {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}
@keyframes modal-pop {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}
@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------- Loading state ---------- */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--md-surface-variant) 0%,
        var(--md-outline) 50%,
        var(--md-surface-variant) 100%
    );
    background-size: 200% 100%;
    border-radius: var(--r-xs);
    animation: skeleton 1.6s linear infinite;
}
@keyframes skeleton {
    from {
        background-position: 200% 0;
    }
    to {
        background-position: -200% 0;
    }
}

/* =========================================================
   Tabs (Material 3 secondary tabs)
   ========================================================= */
.tabs {
    position: relative;
    display: flex;
    align-items: stretch;
    padding: 0 var(--s-3);
    border-bottom: 1px solid var(--md-outline);
    background: var(--md-surface-elevated);
}

.tabs__tab {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-4);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--md-on-surface-muted);
    border-radius: var(--r-xs) var(--r-xs) 0 0;
    transition:
        color var(--d-short) var(--ease-standard),
        background var(--d-short) var(--ease-standard);
    cursor: pointer;
    position: relative;
}

.tabs__icon {
    font-size: 16px;
}

.tabs__tab:hover:not(.is-active) {
    color: var(--md-on-surface);
    background: var(--md-hover-layer);
}

.tabs__tab.is-active {
    color: var(--md-primary-strong);
}
[data-theme="dark"] .tabs__tab.is-active {
    color: var(--md-primary);
}

.tabs__indicator {
    position: absolute;
    bottom: -1px;
    height: 3px;
    background: var(--md-primary-strong);
    border-radius: 3px 3px 0 0;
    transition:
        left var(--d-med) var(--ease-emphasized),
        width var(--d-med) var(--ease-emphasized);
}
[data-theme="dark"] .tabs__indicator {
    background: var(--md-primary);
}

.tabs__panel {
    display: none;
}
.tabs__panel.is-active {
    display: block;
}

/* =========================================================
   Switch (toggle)
   ========================================================= */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

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

.switch__track {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--md-outline-strong);
    border-radius: var(--r-full);
    cursor: pointer;
    transition: background var(--d-short) var(--ease-standard);
    position: relative;
}

.switch__thumb {
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    background: var(--md-surface-elevated);
    border-radius: var(--r-full);
    box-shadow: var(--e-1);
    transition:
        transform var(--d-med) var(--ease-emphasized),
        background var(--d-short) var(--ease-standard);
}

.switch input:checked + .switch__track {
    background: var(--md-primary-strong);
}

.switch input:checked + .switch__track .switch__thumb {
    transform: translateX(20px);
    background: #fff;
}

.switch input:focus-visible + .switch__track {
    box-shadow: 0 0 0 3px var(--md-primary-container);
}

/* =========================================================
   Advanced banner & current value display
   ========================================================= */
.advanced-banner {
    display: flex;
    gap: var(--s-3);
    align-items: flex-start;
    background: var(--md-accent-peach-container);
    color: var(--md-on-accent-peach-container);
    padding: var(--s-4);
    border-radius: var(--r-md);
    margin-bottom: var(--s-6);
}

.advanced-banner .material-symbols-outlined {
    font-size: 22px;
    flex-shrink: 0;
}

.advanced-banner strong {
    display: block;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 14px;
}

.advanced-banner p {
    margin: var(--s-1) 0 0;
    font-size: 12px;
    opacity: 0.85;
}

.current-value {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-4);
    background: var(--md-surface-variant);
    border-radius: var(--r-md);
    margin-bottom: var(--s-4);
}

.current-value__icon {
    font-size: 22px;
    color: var(--md-on-surface-muted);
    flex-shrink: 0;
}

.current-value__body {
    flex: 1;
    min-width: 0;
}

.current-value__body small {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--md-on-surface-muted);
    margin-bottom: 2px;
}

.current-value__body strong {
    display: block;
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 14px;
    color: var(--md-on-surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.current-value__body strong.is-empty {
    color: var(--md-on-surface-subtle);
    font-style: italic;
    font-weight: 400;
}
