/* Settings — Orchestrator, System, MCP panels */

/* Override body overflow:hidden from main.css — settings page needs to scroll */
body.settings-page {
    overflow: auto;
    overflow-x: hidden;
    height: auto;
}

.settings-container {
    max-width: 700px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 60px;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    z-index: 1;
}

/* ── Header ── */

.settings-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 0;
}

.settings-back {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-body);
    transition: color 0.2s;
}

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

.settings-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    color: var(--text-primary);
    margin: 0;
}

/* ── Tabs ── */

.settings-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 0;
    border-bottom: 2px solid var(--border-soft);
    margin-bottom: 16px;
}

.settings-tab {
    background: rgba(255, 255, 255, 0.24);
    border: 1px solid transparent;
    padding: 9px 16px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 999px;
    transition: all 0.2s;
    touch-action: manipulation;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.settings-tab.active {
    color: var(--text-primary);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(var(--identity-accent-rgb), 0.10)),
        var(--bg-card);
    border: 1px solid rgba(var(--identity-accent-rgb), 0.28);
    margin-bottom: 0;
    box-shadow: 0 10px 18px rgba(var(--identity-accent-rgb), 0.10);
}

/* ── Panels ── */

.settings-panel {
    display: none;
}

.settings-panel.active {
    display: block;
}

/* ── Sections ── */

.settings-section {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(var(--identity-accent-rgb), 0.05)),
        var(--bg-card);
    border-radius: 24px;
    border: 1px solid var(--border-strong);
    padding: 20px;
    margin-bottom: 16px;
    transition: background var(--transition-theme),
                border-color var(--transition-theme);
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
}

.settings-section::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, transparent 0, transparent 13px, rgba(255, 255, 255, 0.09) 13px, rgba(255, 255, 255, 0.09) 14px, transparent 14px),
        linear-gradient(0deg, transparent 0, transparent 13px, rgba(255, 255, 255, 0.07) 13px, rgba(255, 255, 255, 0.07) 14px, transparent 14px);
    background-size: 28px 28px;
    opacity: 0.26;
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.12rem;
    color: var(--text-primary);
    margin: 0 0 4px;
}

.section-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0 0 12px;
    font-style: italic;
}

/* ── Schedule cards ── */

.schedule-group-title {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--text-muted);
    margin: 16px 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.schedule-group-title:first-child {
    margin-top: 0;
}

.schedule-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.44), rgba(var(--identity-accent-rgb), 0.04)),
        rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    margin-bottom: 8px;
    transition: opacity 0.2s, background var(--transition-theme);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.46);
}

body.night-mode .schedule-card {
    background: rgba(255, 255, 255, 0.03);
}

.schedule-card.disabled {
    opacity: 0.45;
}

.schedule-card-main {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.schedule-time {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    min-width: 48px;
    font-family: var(--font-body);
}

.schedule-info {
    min-width: 0;
}

.schedule-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.schedule-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.schedule-edit-btn,
.schedule-delete-btn {
    background: none;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.7rem;
    font-family: var(--font-body);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    touch-action: manipulation;
}

.schedule-edit-btn:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.schedule-delete-btn:hover {
    border-color: #c44;
    color: #c44;
}

/* ── Toggle switch ── */

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.toggle-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--text-muted);
    border-radius: 12px;
    transition: background 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #C47A8A;
}

.toggle-switch input:checked + .toggle-slider::after {
    transform: translateX(18px);
}

/* ── Failsafe thresholds ── */

.failsafe-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.threshold-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.threshold-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 90px;
}

.threshold-input {
    width: 80px;
    padding: 6px 10px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.threshold-input:focus {
    border-color: #C47A8A;
    outline: none;
}

.threshold-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Buttons ── */

.action-btn {
    background: linear-gradient(180deg, color-mix(in srgb, var(--identity-accent) 86%, white 14%), var(--identity-accent));
    color: white;
    border: none;
    border-radius: 999px;
    padding: 10px 20px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    box-shadow:
        0 12px 22px rgba(var(--identity-accent-rgb), 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 24px rgba(var(--identity-accent-rgb), 0.22);
}

.action-btn.secondary {
    background: rgba(255, 255, 255, 0.28);
    color: var(--text-secondary);
    border: 1px solid rgba(var(--identity-accent-rgb), 0.18);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.action-btn.secondary:hover {
    border-color: var(--text-secondary);
    box-shadow: none;
}

/* ── MCP cards ── */

.mcp-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    margin-bottom: 6px;
    transition: background var(--transition-theme);
}

body.night-mode .mcp-card {
    background: rgba(255, 255, 255, 0.03);
}

.mcp-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.mcp-status-dot.active {
    background: #5BA89A;
    box-shadow: 0 0 6px rgba(91, 168, 154, 0.5);
}

.mcp-status-dot.inactive {
    background: var(--text-muted);
}

.mcp-info {
    display: flex;
    justify-content: space-between;
    flex: 1;
    align-items: center;
}

.mcp-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.mcp-tools {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── System info ── */

.info-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-soft);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.info-value {
    font-size: 0.85rem;
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
}

/* ── Scheduler status ── */

.status-indicator {
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.85rem;
    text-align: center;
    margin-bottom: 12px;
}

.status-indicator.running {
    background: rgba(91, 168, 154, 0.15);
    color: #5BA89A;
}

.status-indicator.stopped {
    background: rgba(196, 122, 138, 0.15);
    color: #C47A8A;
}

.status-job {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.8rem;
}

.job-name {
    color: var(--text-primary);
    font-weight: 500;
}

.job-next {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* ── Modal ── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    background: var(--bg-card, #fffaf5);
    border: 2px solid var(--border-soft);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

body.night-mode .modal-card {
    background: var(--bg-card);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--text-primary);
    margin: 0 0 16px;
}

.modal-field {
    margin-bottom: 12px;
}

.modal-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.modal-field input,
.modal-field select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    background: var(--bg-input, #fff);
    color: var(--text-primary);
    box-sizing: border-box;
}

.modal-field input:focus,
.modal-field select:focus {
    border-color: #C47A8A;
    outline: none;
}

.modal-row {
    display: flex;
    gap: 12px;
}

.modal-row .modal-field {
    flex: 1;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ── Ritual cards ── */

.ritual-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    margin-bottom: 8px;
    transition: background var(--transition-theme);
}

body.night-mode .ritual-card {
    background: rgba(255, 255, 255, 0.03);
}

.ritual-info {
    flex: 1;
    min-width: 0;
}

.ritual-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.ritual-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.ritual-actions {
    flex-shrink: 0;
    margin-left: 12px;
}

.ritual-complete-btn {
    background: #C47A8A;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 6px 14px;
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.ritual-complete-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(196, 122, 138, 0.3);
}

.ritual-complete-btn:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
    box-shadow: none;
}

.ritual-done {
    font-size: 0.75rem;
    font-weight: 600;
    color: #5BA89A;
}

/* ── Wellness form ── */

.wellness-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.wellness-field {
    display: flex;
    flex-direction: column;
}

.wellness-field.full-width {
    grid-column: 1 / -1;
}

.wellness-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.wellness-field select,
.wellness-field input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    background: var(--bg-input, #fff);
    color: var(--text-primary);
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.wellness-field select:focus,
.wellness-field input:focus,
.wellness-field textarea:focus {
    border-color: #C47A8A;
    outline: none;
}

.wellness-field textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font-body);
    background: var(--bg-input, #fff);
    color: var(--text-primary);
    box-sizing: border-box;
    resize: vertical;
    min-height: 60px;
    transition: border-color 0.2s;
}

/* ── Mobile ── */

@media screen and (max-width: 480px) {
    .settings-container {
        padding: 10px;
    }

    .settings-section {
        padding: 14px;
    }

    .settings-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .schedule-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .schedule-card-actions {
        align-self: flex-end;
    }

    .schedule-edit-btn,
    .schedule-delete-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
    }

    .wellness-form {
        grid-template-columns: 1fr;
    }
}
