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

:root {
    --bg:         #0f172a;
    --bg-2:       #1e293b;
    --bg-3:       #334155;
    --border:     #334155;
    --border-2:   #475569;
    --text:       #f1f5f9;
    --text-2:     #94a3b8;
    --text-3:     #64748b;
    --primary:    #3b82f6;
    --primary-h:  #2563eb;
    --success:    #10b981;
    --danger:     #ef4444;
    --warning:    #f59e0b;
    --info:       #06b6d4;
    --tag-ip-bg:  #1e3a5f;
    --tag-ip-c:   #60a5fa;
    --tag-so-bg:  #14532d;
    --tag-so-c:   #4ade80;
    --tag-app-bg: #3b0764;
    --tag-app-c:  #c084fc;
    --sidebar-w:  240px;
    --radius:     10px;
    --radius-sm:  6px;
    --shadow:     0 4px 24px rgba(0,0,0,.4);
    --shadow-sm:  0 2px 8px rgba(0,0,0,.25);
    --font:       'Inter', system-ui, -apple-system, sans-serif;
    --transition: .15s ease;
}

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Auth Layout ──────────────────────────────────────────────────────────── */
body.auth-layout {
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 60% 0%, #1e3a5f 0%, #0f172a 60%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 36px;
    box-shadow: var(--shadow);
    animation: fadeIn .3s ease;
}

.auth-logo {
    color: var(--primary);
    margin-bottom: 16px;
}

.auth-title {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--text-2);
    font-size: .9rem;
    margin-bottom: 28px;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* ── App Layout ───────────────────────────────────────────────────────────── */
body.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    font-weight: 700;
    font-size: .95rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

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

.nav-item:hover {
    background: var(--bg-3);
    color: var(--text);
    text-decoration: none;
}

.nav-item.active {
    background: rgba(59,130,246,.15);
    color: var(--primary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-email {
    font-size: .78rem;
    color: var(--text-3);
    word-break: break-all;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: .85rem;
    font-weight: 500;
    transition: background var(--transition);
    text-decoration: none;
}

.btn-logout:hover {
    background: rgba(239,68,68,.1);
    text-decoration: none;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
}

.main-content {
    padding: 32px;
    max-width: 1100px;
}

/* ── Page Header ──────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
    gap: 16px;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
}

.page-subtitle {
    color: var(--text-2);
    font-size: .9rem;
    margin-top: 4px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-h); text-decoration: none; color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--text-2);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-3); color: var(--text); text-decoration: none; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-outline:hover { background: rgba(59,130,246,.1); text-decoration: none; }

.btn-full { width: 100%; justify-content: center; padding: 12px; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-3);
    color: var(--text-2);
    border: none;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-icon:hover { background: var(--border-2); color: var(--text); text-decoration: none; }
.btn-icon-danger:hover { background: rgba(239,68,68,.15); color: var(--danger); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.form-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.form-col-full { grid-column: 1 / -1; }
.form-col-2    { grid-column: span 2; }
.form-col-1    { grid-column: span 1; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.required { color: var(--danger); }

.form-group input[type=text],
.form-group input[type=email],
.form-group input[type=password],
.form-group input[type=number] {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 14px;
    font-size: .9rem;
    font-family: var(--font);
    transition: border-color var(--transition);
    width: 100%;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-hint {
    font-size: .75rem;
    color: var(--text-3);
}

.form-group select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 14px;
    font-size: .9rem;
    font-family: var(--font);
    transition: border-color var(--transition);
    width: 100%;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-group select option {
    background: var(--bg-2);
    color: var(--text);
}

/* ── IA-style picker ─────────────────────────────────────────────────────── */
.ia-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 2px;
}

.ia-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    border-radius: 999px;
    font-size: .875rem;
    font-weight: 500;
    font-family: var(--font);
    background: transparent;
    border: 1.5px solid var(--border-2);
    color: var(--text-2);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    user-select: none;
    line-height: 1;
    white-space: nowrap;
}

.ia-pill:hover {
    border-color: var(--text-3);
    color: var(--text);
    background: rgba(255,255,255,.04);
}

.ia-pill.selected {
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.3);
    color: var(--text);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.ia-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

/* ── Server tag picker ────────────────────────────────────────────────────── */
.server-tag-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 2px 0;
}

.server-tag-option {
    all: unset;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    font-family: var(--font);
    background: var(--bg-3);
    border: 1.5px solid var(--border-2);
    color: var(--text-2);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
    user-select: none;
    line-height: 1;
    box-sizing: border-box;
}

.server-tag-option:hover {
    border-color: var(--primary);
    color: var(--text);
    background: rgba(59,130,246,.08);
}

.server-tag-option.selected {
    background: rgba(59,130,246,.18);
    border-color: var(--primary);
    color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.server-tag-option .srv-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border-2);
    flex-shrink: 0;
    transition: background .15s;
}

.server-tag-option.selected .srv-dot {
    background: var(--primary);
}

.server-tag-option .check-icon {
    display: none;
    flex-shrink: 0;
    color: var(--primary);
}

.server-tag-option.selected .check-icon {
    display: block;
}

.nav-section-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .8px;
    color: var(--text-3);
    padding: 4px 10px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Input with toggle button */
.input-wrapper {
    position: relative;
    display: flex;
}

.input-wrapper input {
    padding-right: 44px !important;
}

.toggle-pwd {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-3);
    padding: 0;
    display: flex;
    align-items: center;
}
.toggle-pwd:hover { color: var(--text); }

/* ── Tag Input ────────────────────────────────────────────────────────────── */
.tag-input-container {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    min-height: 46px;
    cursor: text;
    transition: border-color var(--transition);
    position: relative;
}

.tag-input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.tags-display {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}

.tag-removable {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: .8rem;
    font-weight: 500;
    background: rgba(59,130,246,.2);
    color: #93c5fd;
    border: 1px solid rgba(59,130,246,.3);
}

.tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    padding: 0;
    display: flex;
    opacity: .7;
    font-size: 1rem;
    line-height: 1;
}
.tag-remove:hover { opacity: 1; }

.tag-input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: .9rem;
    font-family: var(--font);
    width: 100%;
    padding: 2px 6px;
}

/* ── Autocomplete ─────────────────────────────────────────────────────────── */
.autocomplete-wrapper { position: relative; }

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    z-index: 50;
    display: none;
    max-height: 200px;
    overflow-y: auto;
}

.autocomplete-item {
    padding: 9px 14px;
    cursor: pointer;
    font-size: .9rem;
    color: var(--text);
    transition: background var(--transition);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: rgba(59,130,246,.15);
    color: var(--primary);
}

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: 20px;
    border: 1px solid transparent;
}

.alert-error   { background: rgba(239,68,68,.12);  color: #fca5a5; border-color: rgba(239,68,68,.3); }
.alert-success { background: rgba(16,185,129,.12); color: #6ee7b7; border-color: rgba(16,185,129,.3); }
.alert-info    { background: rgba(6,182,212,.12);  color: #67e8f9; border-color: rgba(6,182,212,.3); }

/* ── Dashboard Cards ──────────────────────────────────────────────────────── */
.servers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.server-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: box-shadow var(--transition), border-color var(--transition);
    box-shadow: var(--shadow-sm);
}

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

.server-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, rgba(59,130,246,.05) 0%, transparent 100%);
}

.server-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    background: rgba(59,130,246,.15);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.server-icon-purple {
    background: rgba(139,92,246,.15);
    color: #a78bfa;
}

.server-title {
    flex: 1;
    min-width: 0;
}

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

.server-port {
    font-size: .8rem;
    color: var(--text-3);
    font-family: monospace;
}

.server-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.inline-form { display: inline; }

.server-card-body {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.info-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
    padding-top: 3px;
    min-width: 130px;
}

.tags-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Tags ─────────────────────────────────────────────────────────────────── */
.tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .2px;
    border: 1px solid transparent;
}

.tag-ip   { background: var(--tag-ip-bg);  color: var(--tag-ip-c);  border-color: rgba(96,165,250,.25); }
.tag-so   { background: var(--tag-so-bg);  color: var(--tag-so-c);  border-color: rgba(74,222,128,.25); }
.tag-app  { background: var(--tag-app-bg); color: var(--tag-app-c); border-color: rgba(192,132,252,.25); }
.tag-port { background: #1c1917; color: #fb923c; border-color: rgba(251,146,60,.25); }

.server-card-footer {
    padding: 10px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.server-date {
    font-size: .75rem;
    color: var(--text-3);
}

/* ── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 80px 24px;
    color: var(--text-2);
}

.empty-state svg {
    color: var(--text-3);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text);
}

.empty-state p {
    margin-bottom: 24px;
    color: var(--text-2);
}

/* ── Profile ──────────────────────────────────────────────────────────────── */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.card-section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.text-muted {
    color: var(--text-2);
    font-size: .875rem;
    line-height: 1.6;
    margin-bottom: 16px;
}

.info-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(6,182,212,.08);
    border: 1px solid rgba(6,182,212,.2);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: .875rem;
    color: var(--text-2);
    margin-bottom: 16px;
}

.info-box svg { color: var(--info); flex-shrink: 0; }

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.server-card, .form-card { animation: fadeIn .2s ease; }

/* ── Dashboard Blocks ─────────────────────────────────────────────────────── */
.dash-block {
    margin-bottom: 40px;
}

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

.dash-block-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.dash-block-count {
    font-size: .8rem;
    color: var(--text-3);
}

.btn-sm {
    padding: 6px 14px;
    font-size: .8rem;
}

.dash-empty-inline {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-2);
    font-size: .9rem;
}

/* ── Form narrow (single column) ─────────────────────────────────────────── */
.form-card-narrow {
    max-width: 560px;
}

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

/* SO suggestion pills */
.suggestions-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.pill {
    background: var(--bg-3);
    border: 1px solid var(--border-2);
    color: var(--text-2);
    border-radius: 20px;
    padding: 3px 12px;
    font-size: .78rem;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font);
}

.pill:hover {
    background: rgba(59,130,246,.15);
    border-color: var(--primary);
    color: var(--primary);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .profile-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .form-col-2, .form-col-1 { grid-column: span 1; }
}

@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }

    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition);
    }
    .sidebar.open { transform: translateX(0); width: 240px; }

    .main-content { padding: 16px; }
    .servers-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-col-2, .form-col-1, .form-col-full { grid-column: span 1; }

    .page-header { flex-direction: column; }

    .hamburger {
        display: flex !important;
        position: fixed;
        top: 12px; left: 12px;
        z-index: 200;
        background: var(--bg-2);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 8px;
        cursor: pointer;
        align-items: center;
        color: var(--text);
    }
}

.hamburger {
    display: none;
    background: none;
    border: none;
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
}
.overlay.active { display: block; }
