/* === Variables (Premium Dark Theme) === */
:root {
    --navy: #0B0C10;
    --navy-light: #1F2833;
    --blue: #0F3460;
    --accent: #E94560;
    --teal: #45A29E;
    --teal-glow: rgba(69, 162, 158, 0.4);
    --green: #66FCF1;
    --amber: #F59E0B;
    --red: #EF4444;
    --bg: #0B0C10;
    --card: rgba(31, 40, 51, 0.6);
    --card-hover: rgba(40, 50, 65, 0.8);
    --card-border: rgba(69, 162, 158, 0.15);
    --text: #C5C6C7;
    --text-muted: #8B949E;
    --input-bg: rgba(11, 12, 16, 0.8);
    --input-border: #1F2833;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: radial-gradient(circle at top right, #1F2833, #0B0C10 50%);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* === Login page === */
.login-page {
    background: linear-gradient(135deg, var(--bg) 0%, var(--navy-light) 50%, #081525 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-container { width: 100%; max-width: 400px; }

.login-card {
    background: var(--card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.login-header { text-align: center; margin-bottom: 2rem; }
.login-logo { margin-bottom: 1rem; }
.login-header h1 { font-size: 1.75rem; font-weight: 700; color: #fff; margin-bottom: 0.5rem; }
.login-header p { color: var(--text-muted); font-size: 0.95rem; }

/* === Forms === */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block; font-size: 0.85rem; font-weight: 500; color: var(--text-muted); margin-bottom: 0.5rem;
}
.form-group input {
    width: 100%; padding: 0.75rem 1rem; background: var(--input-bg);
    border: 1px solid var(--input-border); border-radius: 10px; color: #fff;
    font-size: 1rem; font-family: inherit; transition: all 0.3s ease;
}
.form-group input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(69, 162, 158, 0.2); }

.error-msg {
    background: rgba(239, 68, 68, 0.1); border-left: 4px solid var(--red);
    color: var(--red); padding: 0.75rem 1rem; border-radius: 6px; font-size: 0.875rem; margin-bottom: 1.25rem;
}
.success-msg {
    background: rgba(102, 252, 241, 0.1); border-left: 4px solid var(--green);
    color: var(--green); padding: 0.75rem 1rem; border-radius: 6px; font-size: 0.875rem; margin-bottom: 1.25rem;
}

/* === Buttons === */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.75rem 1.5rem; border: none; border-radius: 10px; font-family: inherit; font-size: 0.95rem;
    font-weight: 600; cursor: pointer; transition: all 0.2s ease;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--teal); color: #000; box-shadow: 0 4px 15px var(--teal-glow); }
.btn-primary:hover:not(:disabled) { background: var(--green); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(102, 252, 241, 0.4); }

.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,0.1); color: var(--text); }
.btn-outline:hover { background: rgba(255,255,255,0.05); color: #fff; }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; border-radius: 8px; }
.btn-full { width: 100%; margin-top: 0.5rem; }

/* === Top bar === */
.topbar {
    position: sticky; top: 0; z-index: 100;
    background: rgba(11, 12, 16, 0.8);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}
.topbar-inner {
    display: flex; align-items: center; justify-content: space-between;
    max-width: 1200px; margin: 0 auto; padding: 1rem 1.5rem;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; }
.topbar-title { font-weight: 700; font-size: 1.25rem; color: #fff; letter-spacing: 0.5px; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topbar-user { color: var(--teal); font-weight: 600; font-size: 0.9rem; letter-spacing: 0.5px; text-transform: uppercase;}

/* === Dashboard === */
.dashboard { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }

/* === Search bar === */
.search-bar { margin-bottom: 1.5rem; }
.search-bar input {
    width: 100%; padding: 1rem 1.5rem; background: rgba(31, 40, 51, 0.5);
    border: 1px solid rgba(255,255,255,0.1); border-radius: 12px; color: #fff;
    font-size: 1.05rem; font-family: inherit; transition: all 0.3s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.search-bar input:focus { outline: none; border-color: var(--teal); background: rgba(31, 40, 51, 0.8); box-shadow: 0 0 15px var(--teal-glow); }
.search-bar input::placeholder { color: var(--text-muted); }

/* === Category filters === */
.category-filters {
    display: flex; gap: 0.75rem; overflow-x: auto; padding-bottom: 1rem; margin-bottom: 1.5rem;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.category-filters::-webkit-scrollbar { display: none; }
.cat-btn {
    flex-shrink: 0; padding: 0.5rem 1.25rem; border: 1px solid rgba(255,255,255,0.1);
    border-radius: 30px; background: rgba(31, 40, 51, 0.3); color: var(--text);
    font-family: inherit; font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: all 0.3s ease;
}
.cat-btn:hover { background: rgba(255,255,255,0.05); color: #fff; transform: translateY(-1px); }
.cat-btn.active { background: var(--teal); border-color: var(--teal); color: #000; box-shadow: 0 4px 12px var(--teal-glow); font-weight: 600; }

/* === App grid === */
.app-grid { display: grid; grid-template-columns: 1fr; gap: 1.25rem; }
@media (min-width: 520px) { .app-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .app-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .app-grid { grid-template-columns: repeat(4, 1fr); } }

/* === App card === */
.app-card {
    display: flex; flex-direction: column; background: var(--card);
    border: 1px solid var(--card-border); border-radius: 16px; padding: 1.5rem; min-height: 140px;
    text-decoration: none; color: var(--text); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative; overflow: hidden; backdrop-filter: blur(8px);
}
.app-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at top right, rgba(102, 252, 241, 0.05), transparent 60%);
    opacity: 0; transition: opacity 0.3s ease;
}
.app-card:hover { border-color: var(--teal); transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0,0,0,0.3), 0 0 15px rgba(69, 162, 158, 0.1); }
.app-card:hover::before { opacity: 1; }
.app-card.hidden { display: none; }

.app-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; position: relative; z-index: 1;}
.app-icon {
    width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, rgba(69, 162, 158, 0.15), rgba(69, 162, 158, 0.05));
    border: 1px solid rgba(69, 162, 158, 0.2); border-radius: 12px; color: var(--green);
    transition: all 0.3s ease;
}
.app-card:hover .app-icon { background: rgba(69, 162, 158, 0.2); transform: scale(1.05); box-shadow: 0 0 15px var(--teal-glow); }
.app-icon svg { width: 24px; height: 24px; }

/* === Health dot === */
.health-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; transition: all 0.3s ease; }
.health-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green), 0 0 12px rgba(102, 252, 241, 0.4); }
.health-dot.offline { background: var(--red); box-shadow: 0 0 8px var(--red); }

.app-card-body { position: relative; z-index: 1; }
.app-card-body h3 { font-size: 1.1rem; font-weight: 600; color: #fff; margin-bottom: 0.3rem; letter-spacing: 0.3px; }
.app-card-body p { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }

.app-card-footer { margin-top: auto; padding-top: 1rem; position: relative; z-index: 1; }
.app-category-badge {
    display: inline-block; padding: 0.25rem 0.6rem; background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255,255,255,0.1); border-radius: 6px; font-size: 0.7rem; color: var(--text);
    text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; transition: background 0.3s ease;
}
.app-card:hover .app-category-badge { background: rgba(69, 162, 158, 0.1); border-color: rgba(69, 162, 158, 0.3); color: var(--green); }

/* === Users panel === */
.users-panel { margin-top: 2rem; background: var(--card); border: 1px solid rgba(255,255,255,0.05); border-radius: 16px; padding: 1.75rem; backdrop-filter: blur(8px); }
.users-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.users-panel-header h2 { font-size: 1.25rem; font-weight: 700; color: #fff; }

.create-user-form { margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid rgba(255,255,255,0.05); }
.create-user-form h3 { font-size: 1rem; margin-bottom: 1rem; color: #fff; }
.form-row { display: flex; gap: 0.75rem; align-items: stretch; flex-wrap: wrap; }
.form-row input { flex: 1; min-width: 150px; padding: 0.6rem 0.8rem; background: rgba(11, 12, 16, 0.5); border: 1px solid rgba(255,255,255,0.1); border-radius: 8px; color: #fff; }
.form-row input:focus { border-color: var(--teal); outline: none; }
.form-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Users list */
.user-list { display: flex; flex-direction: column; gap: 0.75rem; }
.user-item { background: rgba(11, 12, 16, 0.4); border: 1px solid rgba(255,255,255,0.05); border-radius: 10px; padding: 1rem; transition: background 0.2s; }
.user-item:hover { background: rgba(11, 12, 16, 0.6); }
.user-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.user-info { display: flex; align-items: center; gap: 0.75rem; }
.user-info strong { font-weight: 600; font-size: 0.95rem; color: #fff; }
.user-badge { font-size: 0.7rem; padding: 0.15rem 0.4rem; background: rgba(239, 68, 68, 0.15); color: var(--red); border-radius: 4px; font-weight: 600; text-transform: uppercase; }

.user-apps { font-size: 0.85rem; margin-bottom: 1rem; }
.user-apps span { color: var(--text-muted); }

.user-permissions-editor { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed rgba(255,255,255,0.1); }
.user-permissions-editor h4 { font-size: 0.85rem; margin-bottom: 0.75rem; color: #fff; }
.perms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.5rem; margin-bottom: 1rem; }
.perm-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; background: rgba(255,255,255,0.03); border-radius: 8px; font-size: 0.85rem; color: var(--text); cursor: pointer; transition: all 0.2s ease; border: 1px solid transparent;}
.perm-item:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.1); }
.perm-item input[type="checkbox"] { accent-color: var(--teal); width: 16px; height: 16px; cursor: pointer; }

.perm-actions { display: flex; align-items: center; gap: 0.75rem; }
.perm-feedback { font-size: 0.85rem; font-weight: 500; }
.perm-feedback-ok { color: var(--green); }
.perm-feedback-err { color: var(--red); }
.user-actions { display: flex; gap: 0.5rem; align-items: center; }
