* {
    box-sizing: border-box;
}

:root {
    --bg: #f3f4f6;
    --dark: #111827;
    --muted: #6b7280;
    --card: #ffffff;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --border: #e5e7eb;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --shadow: 0 12px 35px rgba(15, 23, 42, .08);
}

body {
    margin: 0;
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    color: var(--dark);
}

a {
    color: inherit;
    text-decoration: none;
}

.app {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 280px;
    background: #0f172a;
    color: white;
    padding: 22px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 50;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 28px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #22c55e);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.brand span {
    display: block;
    font-size: 12px;
    color: #94a3b8;
    margin-top: 3px;
}

.menu {
    display: grid;
    gap: 6px;
}

.menu a {
    padding: 13px 14px;
    border-radius: 12px;
    color: #cbd5e1;
    font-size: 15px;
}

.menu a:hover,
.menu a.active {
    background: rgba(255,255,255,.1);
    color: white;
}

.main {
    margin-left: 280px;
    width: calc(100% - 280px);
}

.topbar {
    height: 76px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
}

.topbar small {
    color: var(--muted);
}

.menu-btn {
    display: none;
    border: 0;
    background: #eef2ff;
    color: var(--primary);
    border-radius: 10px;
    font-size: 22px;
    padding: 9px 12px;
}

.logout {
    margin-left: auto;
    background: #fee2e2;
    color: #991b1b;
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 14px;
}

.content {
    padding: 28px;
}

.grid {
    display: grid;
    gap: 18px;
}

.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
    background: var(--card);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 22px;
    border: 1px solid var(--border);
}

.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.metric strong {
    display: block;
    font-size: 30px;
    margin-top: 8px;
}

.metric span {
    color: var(--muted);
    font-size: 14px;
}

.metric .icon {
    width: 48px;
    height: 48px;
    border-radius: 15px;
    background: #eef2ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 18px;
    align-items: center;
    flex-wrap: wrap;
}

.search {
    flex: 1;
    min-width: 220px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 13px;
    font-size: 15px;
    background: white;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

label {
    display: block;
    margin-bottom: 7px;
    font-weight: 700;
    font-size: 14px;
}

.form-row {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: var(--primary);
    color: white;
    border-radius: 12px;
    padding: 12px 16px;
    font-weight: 700;
    cursor: pointer;
}

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

.btn-light {
    background: #eef2ff;
    color: var(--primary);
}

.btn-danger {
    background: #fee2e2;
    color: #991b1b;
}

.table-wrap {
    overflow-x: auto;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: white;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

th {
    background: #f9fafb;
    color: #374151;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

td {
    font-size: 14px;
}

.badge {
    display: inline-flex;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    background: #e5e7eb;
}

.badge.open,
.badge.CONNECTED {
    background: #dcfce7;
    color: #166534;
}

.badge.pending {
    background: #fef3c7;
    color: #92400e;
}

.badge.closed,
.badge.DISCONNECTED {
    background: #fee2e2;
    color: #991b1b;
}

.alert {
    border-radius: 12px;
    padding: 13px 15px;
    margin-bottom: 18px;
    font-weight: 700;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
}

.chat {
    display: grid;
    gap: 12px;
}

.message {
    max-width: 78%;
    padding: 12px 14px;
    border-radius: 16px;
    background: #f3f4f6;
}

.message.me {
    margin-left: auto;
    background: #dbeafe;
}

.message small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
}

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: linear-gradient(135deg, #0f172a, #1d4ed8);
}

.login-box {
    width: 100%;
    max-width: 430px;
    background: white;
    border-radius: 22px;
    padding: 34px;
    box-shadow: 0 25px 70px rgba(0,0,0,.32);
}

.login-logo {
    width: 60px;
    height: 60px;
    margin: 0 auto 18px;
    border-radius: 20px;
    background: linear-gradient(135deg, #2563eb, #22c55e);
    color: white;
    font-size: 30px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-box h1,
.login-box p {
    text-align: center;
}

.login-box h1 {
    margin: 0;
}

.login-box p {
    color: var(--muted);
    margin-bottom: 24px;
}

@media (max-width: 1100px) {
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-105%);
        transition: .25s ease;
        box-shadow: 30px 0 60px rgba(0,0,0,.25);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main {
        margin-left: 0;
        width: 100%;
    }

    .menu-btn {
        display: inline-flex;
    }

    .topbar {
        padding: 0 16px;
    }

    .content {
        padding: 18px;
    }

    .topbar h1 {
        font-size: 18px;
    }
}

@media (max-width: 640px) {
    .grid-4,
    .grid-2,
    .form-row {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 17px;
        border-radius: 15px;
    }

    .toolbar {
        display: grid;
    }

    .toolbar .btn,
    .toolbar form {
        width: 100%;
    }

    .logout {
        padding: 9px 11px;
        font-size: 13px;
    }

    .message {
        max-width: 92%;
    }

    .login-box {
        padding: 26px;
    }
}
