/* --- Variables & Core Setup --- */
:root { 
    --primary: #2563eb; 
    --primary-hover: #1d4ed8;
    --dark-bg: #0f172a;
    --glass: rgba(15, 23, 42, 0.9);
    --text-main: #f1f5f9;
    --text-dark: #1e293b;
    --text-muted: #94a3b8;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --bg: #6366f1; 
    --appCard: #111726;
    --btn-search: #4d7cff;
    --btn-reset: #e85347;
    --btn-disable: #df8c30;
    --btn-enable: #3cb867;
}

* { 
    box-sizing: border-box; 
}

body { 
    -webkit-user-select: none; 
    -ms-user-select: none; 
    user-select: none; 
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif; 
    background: linear-gradient(rgba(10, 15, 30, 0.75), rgba(10, 15, 30, 0.85)), url('images/bg.jpg');
    background-size: cover; 
    background-position: center; 
    background-attachment: fixed; 
    margin: 0; 
    padding: 0; 
    color: var(--text-main);
}

/* --- Layouts --- */
.container { 
    max-width: 1150px; 
    margin: 10px auto; 
    padding: 0 15px 50px 15px; 
}

.container-wide { 
    max-width: 1800px; 
    width: 95%; 
    margin: 10px auto; 
}

/* Responsive Split Layout Framework */
.split-layout-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    margin-top: 20px;
}

/* --- App Identity & Elements --- */
.header-bar { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    background: transparent; 
    padding: 0; 
    margin-bottom: 25px; 
    border: none; 
}

.title-left { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
}

.title-right { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    flex-grow: 1; 
    justify-content: flex-end; 
}

.badge-count { 
    background: rgba(255, 255, 255, 0.2); 
    color: #ffffff; 
    padding: 2px 10px; 
    border-radius: 20px; 
    font-size: 14px; 
    font-weight: 800; 
    white-space: nowrap; 
}

/* --- Cards --- */
.card { 
    background: #ffffff; 
    color: var(--text-dark); 
    border-radius: 12px; 
    overflow: hidden; 
    box-shadow: 0 10px 15px rgba(0,0,0,0.1); 
    margin-bottom: 25px; 
}

.card-title { 
    background: linear-gradient(45deg, #4b6cb7 0%, #182848 100%); 
    color: #ffffff; 
    padding: 12px 20px; 
    font-size: 16px; 
    font-weight: 700; 
    display: flex; 
    justify-content: space-between; 
    flex-wrap: wrap; 
    gap: 10px; 
}

.card-body { 
    padding: 20px; 
}

/* --- Buttons & Inputs --- */
.btn { 
    display: inline-flex; 
    align-items: center; 
    gap: 8px; 
    padding: 10px 16px; 
    border-radius: 6px; 
    font-weight: 600; 
    cursor: pointer; 
    border: none; 
    transition: background-color 0.2s, opacity 0.2s; 
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-blue { 
    background: var(--primary); 
    color: #ffffff; 
}

.btn-blue:hover {
    background: var(--primary-hover);
}

.btn-cancel { 
    background: #e2e8f0; 
    color: #475569; 
}

.btn-cancel:hover {
    background: #cbd5e1;
}

.btn-logout { 
    background: var(--btn-reset); 
    color: #ffffff !important; 
    text-decoration: none; 
    font-size: 10px; 
    font-weight: 900; 
    padding: 6px 14px; 
    border-radius: 6px; 
    text-transform: uppercase; 
    transition: background 0.2s ease; 
}

.btn-logout:hover {
    background: #c93b30;
}

.btn-action { 
    padding: 6px 12px; 
    border-radius: 4px; 
    font-size: 12px; 
    border: 1px solid #e2e8f0; 
    color: var(--primary); 
    cursor: pointer; 
    background: #ffffff; 
    text-decoration: none; 
    display: inline-flex; 
    align-items: center; 
    justify-content: center;
}

.search-box { 
    background: rgba(255, 255, 255, 0.15); 
    border: 1px solid rgba(255, 255, 255, 0.3); 
    border-radius: 6px; 
    padding: 6px 12px; 
    color: #ffffff; 
    outline: none; 
    width: 180px; 
    transition: border-color 0.2s;
}

.search-box:focus {
    border-color: rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

/* --- Tables Layout Matrix --- */
.table-container { 
    width: 100%; 
    overflow-x: auto; 
    margin-top: 15px; 
    border-radius: 8px; 
    border: 1px solid #f1f5f9; 
    -webkit-overflow-scrolling: touch;
}

table { 
    width: 100%; 
    border-collapse: collapse; 
    table-layout: fixed; 
}

.card th, .card td { 
    background: #ffffff; 
    color: var(--text-dark); 
}

th { 
    text-align: left; 
    font-size: 11px; 
    color: var(--text-muted); 
    padding: 12px; 
    border-bottom: 2px solid #f1f5f9; 
    cursor: pointer; 
    user-select: none;
}

.card th:hover { 
    background: #f8fafc; 
}

th i { 
    margin-left: 5px; 
    opacity: 0.5; 
}

td { 
    padding: 12px; 
    font-size: 13px; 
    border-bottom: 1px solid #f1f5f9; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; 
}

/* Strict Desktop Column Ratios */
.col-sn { width: 65px; text-align: center; color: var(--text-muted); font-weight: bold; }
.col-status { width: 75px; text-align: center; }
.col-identity { width: 25%; }
.col-group { width: 12%; }
.col-ip { width: 32%; }
.col-port { width: 10%; }
.col-actions { width: 110px; text-align: center; }

.group-badge { 
    background: #f1f5f9; 
    color: #64748b; 
    padding: 2px 5px; 
    border-radius: 4px; 
    font-size: 10px; 
    font-weight: 600; 
}

/* --- Forms --- */
.form-row { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 15px; 
    margin-bottom: 15px; 
}

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

.layout-left-pane .form-group { 
    margin-bottom: 12px; 
}

.layout-left-pane .card-body { 
    padding: 15px 20px; 
}

.form-group label { 
    display: block; 
    font-size: 13px; 
    font-weight: 600; 
    color: #444444; 
    margin-bottom: 8px; 
}

.form-group input { 
    width: 100%; 
    padding: 12px 14px; 
    border: 1px solid #cbd5e1; 
    border-radius: 8px; 
    outline: none; 
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.pass-toggle { 
    position: absolute; 
    right: 12px; 
    top: 38px; 
    cursor: pointer; 
    color: var(--text-muted); 
}

/* --- Status & Notifications --- */
.status-dot { 
    display: inline-block; 
    width: 10px; 
    height: 10px; 
    border-radius: 50%; 
    background-color: #cbd5e1; 
}

.dot-online { background-color: var(--success); }
.dot-offline { background-color: var(--danger); }

#custom-alert { 
    position: fixed; 
    background: var(--appCard); 
    border: 1px solid rgba(139, 92, 246, 0.5); 
    padding: 8px 16px; 
    border-radius: 12px; 
    color: #e5e7eb; 
    z-index: 999999; 
    display: none; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
    transition: opacity 300ms ease;
    transform: translate(-50%, -100%);
    margin-top: -8px;
}

/* --- ASSIGN DEVICES (PERMISSION MANAGER) STYLES --- */
.perm-top-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.perm-label-dark {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 8px;
}

.select-dark-ui, .search-dark-ui {
    width: 100%;
    padding: 12px;
    background: #111726;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    color: #ffffff;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

.select-dark-ui option {
    background: #111726;
    color: #ffffff;
}

.select-dark-ui:focus, .search-dark-ui:focus {
    border-color: var(--primary);
}

.perm-check-input {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Multi-Column Device Layout Grid Framework */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 25px;
}

.permission-item-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #111726;
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 16px;
    border-radius: 8px;
    transition: background 0.2s, border-color 0.2s;
}

.permission-item-card:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* --- Checked Permissions Active Layout (Green Color Override) --- */
.permission-item-card.is-checked {
    border-color: #22c55e !important; 
    background: rgba(34, 197, 94, 0.08) !important;
}

.permission-item-card.is-checked .permission-card-title {
    color: #22c55e !important; 
}

.permission-item-card.is-checked .permission-group-tag {
    background: rgba(34, 197, 94, 0.2) !important; 
    color: #4ade80 !important;
}

.permission-card-title {
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 5px;
}

.permission-meta-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.permission-group-tag {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bottom-actions-container {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

/* --- Responsive Overrides --- */
@media (max-width: 991px) {
    .form-row { grid-template-columns: 1fr; } 
    .title-right { flex-direction: column; align-items: stretch !important; gap: 8px !important; }
    .search-box { width: 100% !important; }
    .card-title { flex-direction: column; align-items: flex-start; }
    
    /* Strict Mobile Table Width Fix: Stops compression, enables horizontal scroll */
    table {
        table-layout: fixed !important;
        width: 900px !important; 
        min-width: 900px !important;
    }
    
    th, td {
        white-space: nowrap !important;
        word-break: normal !important;
    }
    
    /* Fixed pixel widths for mobile rendering */
    .col-sn { width: 50px !important; }
    .col-status { width: 65px !important; }
    .col-identity { width: 220px !important; overflow: hidden; text-overflow: ellipsis; }
    .col-group { width: 90px !important; }
    .col-ip { width: 280px !important; overflow: hidden; text-overflow: ellipsis; }
    .col-port { width: 80px !important; }
    .col-actions { width: 100px !important; }

    .perm-top-bar {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .permissions-grid {
        grid-template-columns: 1fr;
    }
}

/* Restores side-by-side layout across laptops and desktop viewports */
@media (min-width: 992px) {
    .split-layout-container { 
        flex-direction: row; 
        align-items: flex-start; 
        gap: 20px; 
    }
    .layout-left-pane { 
        flex: 0 0 300px; 
        width: 300px;
        position: sticky; 
        top: 20px; 
    }
    .layout-right-pane { 
        flex: 1; 
        width: calc(100% - 320px); 
    }
}

@media (min-width: 1400px) {
    .layout-left-pane { 
        flex: 0 0 360px; 
        width: 360px;
    }
    .layout-right-pane { 
        width: calc(100% - 384px); 
    }
    .permissions-grid {
        grid-template-columns: repeat(5, 1fr); 
    }
}