/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-tertiary: #1c1f2e;
    --bg-card: #1e2132;
    --bg-card-hover: #25283d;
    --bg-input: #25283d;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0b0;
    --text-muted: #6b7280;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --accent-glow: rgba(79, 195, 247, 0.15);
    --success: #34d399;
    --success-bg: rgba(52, 211, 153, 0.1);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.1);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, 0.1);
    --border: #2a2e42;
    --border-light: #353a52;
    --sidebar-width: 260px;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.nav-list {
    list-style: none;
    padding: 8px;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
}

.nav-item:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.04);
}

.nav-item.active {
    color: var(--accent);
    background: var(--accent-glow);
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ── Sidebar Footer (User) ──────────────────────────────────── */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.logout-btn:hover {
    color: var(--danger);
    background: var(--danger-bg);
}

/* ── Main Content ────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    padding: 28px 32px;
    flex: 1;
    min-height: 100vh;
    max-width: calc(100vw - var(--sidebar-width));
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    gap: 16px;
}

.page-header h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.domain-badge {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

/* ── Stats Grid ──────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -1px;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-card.stat-running .stat-value { color: var(--success); }
.stat-card.stat-stopped .stat-value { color: var(--text-muted); }
.stat-card.stat-mods .stat-value { color: var(--warning); }
.stat-card.stat-versions .stat-value { color: var(--accent); }

/* ── Sections ────────────────────────────────────────────── */
.section { margin-bottom: 28px; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.section-header h2 { font-size: 18px; font-weight: 600; }

/* ── Server Grid ─────────────────────────────────────────── */
.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.server-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: var(--transition);
}

.server-card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow);
}

.server-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.server-card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.server-card-body p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.server-card-body p strong {
    color: var(--text-primary);
    font-weight: 500;
}

.server-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

/* ── Status Badges ───────────────────────────────────────── */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    gap: 5px;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.status-running {
    background: var(--success-bg);
    color: var(--success);
}
.status-running::before { background: var(--success); }

.status-stopped {
    background: rgba(107, 114, 128, 0.1);
    color: var(--text-muted);
}
.status-stopped::before { background: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1;
}

.btn:hover {
    border-color: var(--border-light);
    background: var(--bg-card-hover);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-primary {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-success {
    background: var(--success);
    color: #000;
    border-color: var(--success);
    font-weight: 600;
}
.btn-success:hover { background: #2ecf8e; border-color: #2ecf8e; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
    font-weight: 600;
}
.btn-danger:hover { background: #ef4444; border-color: #ef4444; }

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Tables ──────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
}

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

.table th, .table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

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

.table td { font-size: 13px; }

.table a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}
.table a:hover { text-decoration: underline; }

.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-size: 15px;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.card.readonly-config {
    background: transparent;
    border: none;
    padding: 0;
}

.card.readonly-config h3 {
    display: none;
}

/* ── Forms ───────────────────────────────────────────────── */
.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.form-group small a { color: var(--accent); }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 18px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.checkbox-label:hover {
    border-color: var(--border-light);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--accent);
}

/* ── Info Table ──────────────────────────────────────────── */
.info-table {
    width: 100%;
}

.info-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.info-table td:first-child {
    color: var(--text-secondary);
    width: 140px;
    font-weight: 500;
}

code {
    background: rgba(0,0,0,0.3);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: var(--accent);
}

/* ── Tabs ────────────────────────────────────────────────── */
.tab-bar {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
    margin-bottom: -1px;
}

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

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Modal ───────────────────────────────────────────────── */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
}

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

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition);
    line-height: 1;
}

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

.modal h2 {
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 600;
}

.modal-content.wide {
    max-width: 800px;
}

/* ── Console ─────────────────────────────────────────────── */
.console {
    background: #0a0b12;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    height: 420px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
    margin-bottom: 12px;
    color: #4ade80;
}

.console pre {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.console-header h3 {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    font-size: 14px;
}

.command-input {
    display: flex;
    gap: 8px;
}

.command-input input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 13px;
    transition: var(--transition);
}

.command-input input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Version List ────────────────────────────────────────── */
.version-list {
    max-height: 500px;
    overflow-y: auto;
}

.version-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.version-item:hover {
    background: rgba(255,255,255,0.02);
}

.version-item:last-child { border-bottom: none; }

.version-item .version-id {
    font-size: 14px;
    font-weight: 500;
}

/* ── Mods ────────────────────────────────────────────────── */
.mod-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: var(--transition);
}

.mod-item:hover {
    background: rgba(255,255,255,0.02);
}

.mod-item:last-child { border-bottom: none; }

.mod-name {
    font-size: 14px;
    font-weight: 500;
}

.mod-size {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 12px;
}

.mod-actions {
    display: flex;
    gap: 6px;
}

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

/* ── Utilities ───────────────────────────────────────────── */
.text-muted { color: var(--text-secondary); font-size: 13px; margin-bottom: 12px; }

hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Modrinth Grid ───────────────────────────────────────── */
.modrinth-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
}

.modrinth-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.modrinth-card:hover {
    border-color: var(--border-light);
    background: var(--bg-tertiary);
}

.modrinth-card-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
}

.modrinth-card-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modrinth-card-body { flex: 1; min-width: 0; }

.modrinth-card-body h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modrinth-author {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.modrinth-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.modrinth-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.modrinth-meta span {
    white-space: nowrap;
}

.modrinth-card-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

#modrinthSearch {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

#modrinthSearch:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Login Page ──────────────────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(79, 195, 247, 0.04) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 50%, rgba(52, 211, 153, 0.03) 0%, transparent 60%);
}

.login-wrapper {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 32px 32px;
    box-shadow: var(--shadow-lg);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-icon {
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form .form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.login-form .form-group input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
}

.login-form .form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-btn {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    margin-top: 8px;
}

.login-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 12px;
    color: var(--text-muted);
}
