:root {
    --color-bg:             #f4f5f7;
    --color-surface:        #ffffff;
    --color-surface-raised: #eaecf0;
    --color-header:         #ffffff;
    --color-border:         #d0d3db;
    --color-text:           #1a1d26;
    --color-text-muted:     #5a6275;
    --color-accent:         #e67e22;
    --color-primary:        #3498db;
    --color-primary-hover:  #2980b9;
    --color-success:        #27ae60;
    --color-success-hover:  #219a52;
    --color-danger:         #e74c3c;
    --color-danger-hover:   #c0392b;
    --color-warning:        #f39c12;
    --color-info:           #2980b9;

    --status-running:   #27ae60;
    --status-stopped:   #7f8c8d;
    --status-starting:  #f39c12;
    --status-failed:    #e74c3c;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-sm: 0 2px 4px rgba(0,0,0,0.15);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.2);

    --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg:             #0f1117;
        --color-surface:        #1a1d26;
        --color-surface-raised: #20243a;
        --color-header:         #13161f;
        --color-border:         #2a2d3a;
        --color-text:           #e8eaf0;
        --color-text-muted:     #8892a4;

        --shadow-sm: 0 2px 4px rgba(0,0,0,0.4);
        --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
    }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
dialog { margin: auto; } /* restore centering removed by margin: 0 above */

::-webkit-scrollbar        { width: 8px; height: 8px; }
::-webkit-scrollbar-track  { background: var(--color-bg); }
::-webkit-scrollbar-thumb  { background: var(--color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

::-webkit-resizer {
    background-color: var(--color-surface-raised);
    background-image: linear-gradient(
        135deg,
        transparent 40%,
        var(--color-text-muted) 40%,
        var(--color-text-muted) 55%,
        transparent 55%,
        transparent 65%,
        var(--color-text-muted) 65%,
        var(--color-text-muted) 80%,
        transparent 80%
    );
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font);
    overflow: hidden;
}

/* ─── Header ─────────────────────────────────── */

.page-header {
    height: 52px;
    padding: 0 1.5rem;
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    position: relative;
    z-index: 50;
}

.page-header-title {
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-icon { font-size: 1.4rem; line-height: 1; }

/* ─── App root ────────────────────────────────── */

#app {
    height: calc(100vh - 52px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ─── Toolbar (back / action buttons) ─────────── */

.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.toolbar-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.password-row {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.password-row input {
    flex: 1;
}

.toolbar-admin-pw {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    white-space: nowrap;
}

.toolbar-admin-pw:hover {
    background: var(--color-surface-raised);
    color: var(--color-text);
}

/* ─── Buttons ─────────────────────────────────── */

.btn {
    padding: 0.45rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
    color: var(--color-text);
}

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

.btn-ghost {
    background: transparent;
    border: 1px solid var(--color-border);
}
.btn-ghost:hover:not(:disabled) { background: var(--color-surface); }

.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--color-success-hover); }

.btn-compare {
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
}
.btn-compare:hover:not(:disabled) { background: var(--color-surface-raised); }
.btn-compare.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}

/* ─── Spinner ─────────────────────────────────── */

.spinner {
    width: 0.85em;
    height: 0.85em;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
}

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

/* ─── Split layout (compare mode) ─────────────── */

.panels {
    display: flex;
    flex: 1;
    overflow-y: auto;
    align-items: flex-start;
}


.primary-panel {
    flex: 1;
    min-width: 0;
}

.compare-panel {
    display: none;
    width: 50%;
    flex-shrink: 0;
    border-left: 2px solid var(--color-accent);
}

.compare-active .primary-panel { flex: 0 0 50%; }
.compare-active .compare-panel { display: flex; flex-direction: column; }

/* ─── Server card grid ─────────────────────────── */

.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
}

.server-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    outline: none;
}

.server-card:hover, .server-card:focus {
    border-color: var(--color-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.server-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.running   { background: var(--status-running); box-shadow: 0 0 6px var(--status-running); }
.status-dot.stopped   { background: var(--status-stopped); }
.status-dot.starting  { background: var(--status-starting); box-shadow: 0 0 6px var(--status-starting); }
.status-dot.failed    { background: var(--status-failed); box-shadow: 0 0 6px var(--status-failed); }

.status-label { color: var(--color-text-muted); flex: 1; }

.port-badge {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-bg);
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
}

.server-name {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
}

.server-friendly {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.config-badge {
    font-size: 0.72rem;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    background: rgba(39,174,96,0.15);
    color: var(--status-running);
    border: 1px solid rgba(39,174,96,0.3);
    align-self: flex-start;
}
.config-badge.missing {
    background: rgba(127,140,141,0.15);
    color: var(--color-text-muted);
    border-color: var(--color-border);
}

/* ─── Detail view ──────────────────────────────── */

.detail-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.no-config-notice {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--color-text-muted);
}
.no-config-notice h2 { color: var(--color-text); margin-bottom: 0.5rem; }

/* ─── Searchable select ───────────────────────── */

.searchable-select {
    position: relative;
}

.searchable-select-input {
    width: 100%;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    padding: 0.4rem 0.6rem;
    font-size: 0.875rem;
    font-family: var(--font);
    cursor: pointer;
    transition: border-color 0.15s;
}

.searchable-select-input:focus {
    outline: none;
    border-color: var(--color-primary);
    cursor: text;
}

.searchable-select-input:disabled { opacity: 0.5; cursor: not-allowed; }

.searchable-select-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 220px;
    overflow-y: auto;
    z-index: 200;
    list-style: none;
    box-shadow: var(--shadow-md);
}

.searchable-select-group {
    padding: 0.4rem 0.75rem 0.2rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    user-select: none;
}

.searchable-select-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.searchable-select-option:hover,
.searchable-select-option:focus {
    background: var(--color-surface-raised);
    outline: none;
}

.searchable-select-option.selected { color: var(--color-primary); }

.select-option-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.35rem;
    border-radius: 99px;
    background: rgba(230, 126, 34, 0.15);
    color: var(--color-accent);
    border: 1px solid rgba(230, 126, 34, 0.3);
    flex-shrink: 0;
}

/* ─── Search bar ──────────────────────────────── */

.search-bar {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font);
    transition: border-color 0.15s;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.search-clear {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0.25rem;
    line-height: 1;
}

.search-clear:hover { color: var(--color-text); }

/* ─── Settings sections ────────────────────────── */

.settings-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--color-surface-raised);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.section-header:hover { color: var(--color-text); }

.section-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s;
}
.section-collapsed .section-chevron { transform: rotate(-90deg); }
.section-collapsed .section-body { display: none; }

.section-body {
    padding: 1rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.75rem 1.25rem;
}

.settings-grid.wide { grid-template-columns: 1fr; }

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

.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.field-group label {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.field-group input[type="text"],
.field-group input[type="number"],
.field-group select,
.field-group textarea {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    padding: 0.4rem 0.6rem;
    font-size: 0.875rem;
    font-family: var(--font);
    width: 100%;
    transition: border-color 0.15s;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.field-group input:disabled,
.field-group select:disabled,
.field-group textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.field-group textarea {
    resize: vertical;
    min-height: 80px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
}

.input-with-suffix {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.input-with-suffix input {
    flex: 1;
    min-width: 0;
}

.input-suffix {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.field-group.checkbox-field {
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    padding: 0.3rem 0;
}

.field-group.checkbox-field label {
    font-size: 0.875rem;
    color: var(--color-text);
    cursor: pointer;
}

.field-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--color-primary);
    flex-shrink: 0;
}

/* ─── Diff highlighting ────────────────────────── */

.field-group.diff-changed input,
.field-group.diff-changed select,
.field-group.diff-changed textarea {
    border-color: var(--color-accent);
    background: rgba(230, 126, 34, 0.08);
}

.field-group.diff-changed label {
    color: var(--color-accent);
}

/* ─── INI editor ───────────────────────────────── */

.ini-editor {
    width: 100%;
    min-height: 300px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    padding: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.5;
    resize: vertical;
}
.ini-editor:focus { outline: none; border-color: var(--color-primary); }
.ini-editor:disabled { opacity: 0.5; }

.ini-diff {
    overflow: auto;
    white-space: pre;
    cursor: default;
}

.ini-line { display: block; }

.ini-line.diff-changed .ini-value    { color: var(--color-accent); background: rgba(230, 126, 34, 0.12); border-radius: 2px; }
.ini-line.diff-only-right .ini-value { color: var(--color-warning); background: rgba(243, 156, 18, 0.1);  border-radius: 2px; }
.ini-line-clickable                  { cursor: pointer; }
.ini-line-clickable:hover            { background: rgba(255, 255, 255, 0.04); }

/* ─── Toast ────────────────────────────────────── */

.toast {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 1rem;
    color: #fff;
    font-weight: 500;
    text-align: center;
    z-index: 10001;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.toast.visible              { transform: translateY(0); }
.toast.success              { background: var(--color-success); }
.toast.error                { background: var(--color-danger); }
.toast.info                 { background: var(--color-info); }
.toast.warning              { background: var(--color-warning); color: #000; }

.toast-close {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: inherit;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
}
.toast-close:hover { opacity: 1; }

/* ─── Modal ────────────────────────────────────── */

dialog {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    color: var(--color-text);
    max-width: 480px;
    width: 90vw;
    padding: 0;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.modal-content {
    padding: 1.5rem 1.5rem 1rem;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 0 1.5rem 1.5rem;
}

/* ─── Backup progress ──────────────────────────── */

.backup-status {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin: 0.75rem 0 0.5rem;
    min-height: 1.2em;
}

.backup-progress-bar {
    height: 6px;
    background: var(--color-border);
    border-radius: 99px;
    overflow: hidden;
}

.backup-progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 99px;
    width: 0%;
    transition: width 0.5s ease;
}

/* ─── Compare panel picker ─────────────────────── */

.compare-panel-header {
    padding: 0.75rem 1rem;
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.compare-inner {
    flex: 1;
}

.compare-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
}

.compare-card-list .server-card { border-radius: var(--radius-md); }

/* ─── Restore overlay ─────────────────────────── */

.restore-overlay {
    position: absolute;
    inset: 0;
    background: var(--color-bg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.restore-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.restore-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    flex-shrink: 0;
}

.restore-columns {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.restore-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--color-border);
    overflow: hidden;
}

.restore-column:last-child { border-right: none; }

.restore-column-header {
    padding: 0.6rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background: var(--color-surface-raised);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.restore-list {
    flex: 1;
    overflow-y: auto;
}

.restore-item {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.1s;
}

.restore-item:hover { background: var(--color-surface); }

.restore-item-title {
    font-weight: 500;
    font-size: 0.9rem;
}

.restore-item-meta {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin-top: 0.2rem;
}

.restore-empty {
    padding: 2rem 1rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    white-space: pre-line;
}

/* ─── Loading state ────────────────────────────── */

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    color: var(--color-text-muted);
    gap: 0.75rem;
    font-size: 0.9rem;
}

.loading-state .spinner {
    border-top-color: var(--color-primary);
    border-color: var(--color-border);
    border-top-color: var(--color-primary);
    width: 1.2em;
    height: 1.2em;
}

/* ─── Cheat Sheet ─────────────────────────────── */

.cheatsheet-overlay {
    position: absolute;
    inset: 0;
    background: var(--color-bg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cheatsheet-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.cheatsheet-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    flex-shrink: 0;
}

.cheatsheet-search-wrap {
    flex: 1;
    max-width: 400px;
}

.cheatsheet-search {
    width: 100%;
}

.cheatsheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.cheatsheet-category {
    padding: 0.5rem 1.5rem 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-top: 0.5rem;
}

.cheatsheet-category:first-child {
    margin-top: 0;
}

.cheatsheet-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.cheatsheet-row:hover {
    background: var(--color-surface-raised);
}

.cheatsheet-name {
    width: 220px;
    flex-shrink: 0;
    font-weight: 500;
    font-size: 0.9rem;
}

.cheatsheet-command {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cheatsheet-empty {
    padding: 2rem 1.5rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* ─── Schedules ───────────────────────────────── */

.schedule-body {
    padding: 0.5rem 0;
}

.schedule-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    margin: 0.25rem 0.75rem 0.5rem;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-warning);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.schedule-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--color-border);
    gap: 1rem;
}

.schedule-row:hover { background: var(--color-surface-raised); }

.schedule-info { flex: 1; }

.schedule-desc {
    font-size: 0.9rem;
    font-weight: 500;
}

.schedule-tasks {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.15rem;
}

.schedule-empty {
    padding: 1rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}
