/* ══════════════════════════════════════════════════════════════
   SETTINGS PANEL
   ══════════════════════════════════════════════════════════════ */

/* Overlay */
#settings-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
}
#settings-overlay.open { display: block; }

/* Panel */
#settings-panel {
    position: fixed;
    right: 0;
    top: 0;
    width: 420px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 301;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
}
#settings-panel.open { transform: translateX(0); }

/* Header */
.settings-header {
    padding: 20px 24px;
    padding-top: max(20px, env(safe-area-inset-top, 20px));
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.settings-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}
.settings-close {
    padding: 10px 16px;
    color: var(--text-muted);
    font-size: 20px;
    border-radius: var(--radius-xs);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.settings-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Tabs */
.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
}
.settings-tab {
    padding: 12px 16px;
    font-size: 13px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}
.settings-tab:hover { color: var(--text-secondary); }
.settings-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* Content area */
.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* Section */
.settings-section { animation: fadeIn 0.2s ease; }
.settings-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Form field */
.s-field {
    margin-bottom: 18px;
}
.s-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.s-field input, .s-field select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
}
.s-field input:focus, .s-field select:focus {
    border-color: var(--accent);
    outline: none;
}

.s-field .s-value {
    font-size: 14px;
    color: var(--text-primary);
    padding: 8px 0;
}

.s-field .s-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Row layout */
.s-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.s-row:last-child { border-bottom: none; }
.s-row-label {
    font-size: 13px;
    color: var(--text-secondary);
}
.s-row-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Buttons */
.s-btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}
.s-btn-primary {
    background: var(--accent);
    color: #0d1b2a;
}
.s-btn-primary:hover { background: var(--accent-hover); }

.s-btn-ghost {
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.s-btn-ghost:hover { background: var(--bg-hover); }

.s-btn-danger {
    color: var(--danger);
    border: 1px solid rgba(239,83,80,0.3);
}
.s-btn-danger:hover { background: rgba(239,83,80,0.1); }

.s-btn-row {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

/* Separator */
.s-separator {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

/* ── Prompt cards in settings ───────────────────────────────── */
.settings-prompt-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
    transition: border-color 0.2s;
}
.settings-prompt-card.default { border-color: var(--accent); }

.spc-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.spc-header strong {
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
}
.spc-badge {
    font-size: 10px;
    padding: 2px 8px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 10px;
}
.spc-preview {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 10px;
}
.spc-actions {
    display: flex;
    gap: 8px;
}
.spc-actions button {
    padding: 5px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    transition: all 0.15s;
}
.spc-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }
.spc-actions button.danger:hover { color: var(--danger); border-color: rgba(239,83,80,0.3); }

/* Prompt editor inside settings */
#settings-prompt-editor {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 16px;
}
#settings-prompt-editor h4 {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 12px;
}
#settings-prompt-editor textarea {
    width: 100%;
    min-height: 140px;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.6;
    resize: vertical;
}
#settings-prompt-editor textarea:focus { border-color: var(--accent); outline: none; }

.spe-new-btn {
    width: 100%;
    padding: 10px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 8px;
    transition: all 0.2s;
}
.spe-new-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Usage stats ────────────────────────────────────────────── */
.usage-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.usage-card {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 14px;
}
.usage-card-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
}
.usage-card-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}
.usage-card-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.usage-model-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}
.usage-model-row:last-child { border-bottom: none; }
.umr-name {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
}
.umr-stat { color: var(--text-secondary); white-space: nowrap; }

/* ── Notification ───────────────────────────────────────────── */
.settings-notif {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    z-index: 400;
    animation: slideUp 0.3s ease;
    box-shadow: var(--shadow-md);
}
.settings-notif.success { background: rgba(102,187,106,0.15); color: var(--success); border: 1px solid rgba(102,187,106,0.3); }
.settings-notif.error { background: rgba(239,83,80,0.15); color: var(--danger); border: 1px solid rgba(239,83,80,0.3); }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Settings button in sidebar */
.sidebar-settings-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    color: var(--text-secondary);
    font-size: 13px;
    border-radius: var(--radius-xs);
    transition: all 0.2s;
    width: 100%;
    text-align: left;
}
.sidebar-settings-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #settings-panel {
        width: 100vw;
    }
    .settings-tabs {
        padding: 0 12px;
        overflow-x: auto;
    }
    .settings-tab {
        padding: 10px 12px;
        font-size: 12px;
    }
    .settings-content { padding: 16px; }
    .usage-cards { grid-template-columns: 1fr; }
    .settings-notif { left: 16px; right: 16px; bottom: 16px; }
}
