* {
    box-sizing: border-box;
}

:root {
    --bg: #070a12;
    --bg-soft: #0b0f19;
    --panel: rgba(11, 15, 25, 0.96);
    --panel-soft: rgba(17, 24, 39, 0.72);
    --border: #263041;
    --text: #f5f7fb;
    --muted: #9ca3af;
    --blue: #2f81f7;
    --blue-dark: #0f2d5c;
    --green: #7cff9b;
    --danger: #ff6b6b;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, #111827 0%, #080b13 45%, #05070d 100%);
    color: var(--text);
    font-family: Arial, sans-serif;
}

a {
    color: #6cbcff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Dark scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: #2f81f7 #0b0d13;
}

::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #0b0d13;
}

::-webkit-scrollbar-thumb {
    background: #2a2f3a;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--blue);
}

/* General cards/forms */
.app,
.auth-box,
.dashboard,
.admin-panel {
    max-width: 1000px;
    margin: 40px auto;
    padding: 24px;
}

.card {
    background: rgba(22, 25, 34, 0.92);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

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

.header h1 {
    margin: 0;
    font-size: 42px;
    letter-spacing: 0.4px;
}

.header p {
    color: #a6adbb;
}

input,
select {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid #303746;
    background: #10131b;
    color: white;
    font-size: 15px;
    margin-bottom: 12px;
}

button,
.btn {
    padding: 13px 20px;
    border: none;
    border-radius: 10px;
    background: var(--blue);
    color: white;
    font-size: 15px;
    cursor: pointer;
    display: inline-block;
}

button:hover,
.btn:hover {
    background: #1f6feb;
    text-decoration: none;
}

.small-btn {
    padding: 8px 14px;
    font-size: 14px;
    background: #2a2f3a;
    margin-top: 10px;
}

.small-btn:hover {
    background: #3a4150;
}

.error {
    background: rgba(255, 80, 80, 0.12);
    color: #ff8585;
    border: 1px solid rgba(255, 80, 80, 0.25);
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 12px;
}

/* Tables/admin */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: #11141c;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
}

.stat-card b {
    color: #a6adbb;
    font-size: 13px;
}

.stat-card div {
    font-size: 28px;
    margin-top: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #11141c;
    border-radius: 14px;
    overflow: hidden;
}

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

th {
    background: #191d28;
    color: #a6adbb;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

/* Main chat layout */
.layout {
    display: flex;
    min-height: 100vh;
    overflow: hidden;
}

.sidebar {
    position: relative;
    width: 320px;
    min-width: 320px;
    height: 100vh;
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease;
}

.sidebar h2 {
    margin: 4px 54px 24px 0;
    font-size: 28px;
}

.sidebar-toggle {
    position: absolute;
    top: 16px;
    right: 18px;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #111827;
    border: 1px solid #374151;
    color: #fff;
    z-index: 20;
}

.layout.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    padding: 0;
    border: none;
    overflow: visible;
}

.layout.sidebar-collapsed .sidebar > *:not(.sidebar-toggle) {
    display: none;
}

.layout.sidebar-collapsed .sidebar-toggle {
    position: fixed;
    left: 14px;
    top: 14px;
}

.new-chat-btn {
    width: 100%;
    margin-bottom: 22px;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 2px;
}

.chat-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    border-radius: 10px;
    color: #d1d5db;
    cursor: pointer;
    margin-bottom: 6px;
    background: transparent;
}

.chat-item:hover,
.chat-item.active {
    background: rgba(47, 129, 247, 0.18);
    color: #ffffff;
}

.sidebar-bottom {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-menu-btn {
    width: 100%;
    background: #111827;
    text-align: left;
}

.user-menu {
    display: none;
    margin-top: 8px;
    background: #11141c;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
}

.user-menu.show {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-main {
    flex: 1;
    height: 100vh;
    padding: 28px 42px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-box {
    flex: 1;
    width: 100%;
    overflow-y: auto;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 34px 0 22px;
    margin: 0 auto;
}

.message {
    max-width: 560px;
    margin-bottom: 28px;
    padding: 14px 16px;
    border-radius: 14px;
    line-height: 1.5;
    border: 1px solid rgba(75, 85, 99, 0.35);
    color: #e5e7eb;
}

.message.user {
    margin-left: auto;
    margin-right: 80px;
    background: linear-gradient(135deg, #123b78, var(--blue-dark));
    color: #ffffff;
    text-align: left;
}

.message.bot {
    margin-left: 80px;
    margin-right: auto;
    background: rgba(18, 24, 34, 0.92);
    color: #ffffff;
    text-align: left;
}

.message strong {
    display: none;
}

.timestamp {
    font-size: 12px;
    color: var(--muted);
    text-align: right;
    margin-top: 6px;
}

.input-area {
    max-width: 1100px;
    width: 100%;
    margin: 0 auto 18px;
    padding-bottom: 18px;
    display: flex;
    gap: 10px;
}

.input-area input {
    margin-bottom: 0;
}

/* Responsive */
@media (max-width: 850px) {
    .sidebar {
        width: 280px;
        min-width: 280px;
    }

    .chat-main {
        padding: 22px 14px;
    }

    .message.user {
        margin-right: 0;
    }

    .message.bot {
        margin-left: 0;
    }

    .header h1 {
        font-size: 32px;
    }
}

.sidebar h2 {
    font-size: 26px;
    letter-spacing: 0.5px;
    margin-bottom: 28px;
}

.chat-list {
    margin-top: 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: transparent;
    color: #d1d5db;
    padding: 12px 10px;
    border-radius: 10px;
    transition: background 0.15s ease, transform 0.15s ease;
}

.chat-item:hover {
    background: rgba(255,255,255,0.06);
}

.chat-item.active {
    background: rgba(47,129,247,0.22);
}

.chat-title {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-delete {
    display: none;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 8px;
    background: transparent;
    color: #9ca3af;
    font-size: 18px;
}

.chat-item:hover .chat-delete {
    display: block;
}

.chat-delete:hover {
    background: rgba(255,80,80,0.15);
    color: #ff6b6b;
}

.sidebar-bottom {
    position: relative;
}

.user-menu-btn {
    width: 100%;
    background: rgba(17,24,39,0.95);
    border: 1px solid #273244;
    border-radius: 12px;
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
}

.user-menu {
    position: absolute;
    bottom: 62px;
    left: 0;
    right: 0;
    display: none;
    background: rgba(17,24,39,0.98);
    border: 1px solid #2d3748;
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 18px 45px rgba(0,0,0,0.45);
}

.user-menu.show {
    display: flex;
    flex-direction: column;
}

.user-menu a {
    padding: 11px 12px;
    border-radius: 10px;
    color: #e5e7eb;
}

.user-menu a:hover {
    background: rgba(255,255,255,0.06);
    text-decoration: none;
}

.user-menu a:last-child {
    color: #ff6b6b;
    border-top: 1px solid #2a2f3a;
    margin-top: 6px;
    padding-top: 12px;
}