:root {
    --bg-dark: #000000;
    --bg-card: #0a0a0a;
    --bg-hover: #111111;
    --primary: #00ff41;
    /* Matrix Green */
    --primary-variant: #008f11;
    --secondary: #003b00;
    --text-main: #00ff41;
    --text-sec: #008f11;
    --error: #ff0000;
    --success: #00ff41;
    --nav-height: 60px;
    --font-mono: 'Courier New', Courier, monospace;
    --border-color: #003300;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--font-mono);
    -webkit-tap-highlight-color: transparent;
}

body,
html {
    height: 100%;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    text-shadow: 0 0 5px rgba(0, 255, 65, 0.5);
    /* Glow effect */
}

/* CRT Scanline Effect Overlay */
body::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 9999;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
}

/* Utilities */
.hidden {
    display: none !important;
}

.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

.error-msg {
    color: var(--error);
    font-size: 0.9rem;
    margin-top: 10px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: var(--bg-hover);
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Login */
#login-screen {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, #1e1e1e 0%, #000000 100%);
}

.login-container {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 12px;
    text-align: center;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.login-container input {
    width: 100%;
    padding: 15px;
    margin: 20px 0;
    border-radius: 8px;
    border: 1px solid #333;
    background: #000;
    color: #fff;
    font-family: monospace;
    font-size: 1.1rem;
    letter-spacing: 2px;
    text-align: center;
}

.login-container button {
    width: 100%;
    padding: 15px;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: #000;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
}

/* Layouts */
.chat-layout {
    display: flex;
    height: 100%;
    width: 100%;
}

aside {
    width: 300px;
    background: var(--bg-card);
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
}

aside header,
section header,
main header,
.screen header {
    height: var(--nav-height);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid #333;
    background-color: var(--bg-card);
    flex-shrink: 0;
    z-index: 50;
    position: relative;
}

.chat-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

#contact-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    padding: 15px 20px;
    cursor: pointer;
    border-bottom: 1px solid #2a2a2a;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.contact-item:hover,
.contact-item.active {
    background: var(--bg-hover);
}

.status-dot {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    background: #555;
    display: inline-block;
    margin-right: 10px;
}

.status-dot.online {
    background: var(--success);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    position: relative;
}

#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
}

.message.sent {
    align-self: flex-end;
    background: var(--primary);
    color: #000;
    border-bottom-right-radius: 2px;
}

.message.received {
    align-self: flex-start;
    background: var(--bg-card);
    border-bottom-left-radius: 2px;
}

#input-area {
    height: 70px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    border-top: 1px solid #333;
    background: var(--bg-card);
}

#input-area input {
    flex: 1;
    padding: 12px;
    border-radius: 20px;
    border: none;
    background: #000;
    color: #fff;
    margin-right: 10px;
}

/* Call Overlay */
#call-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.call-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.call-avatar {
    width: 100px;
    height: 100px;
    background: #333;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.call-avatar span {
    font-size: 50px;
}

.call-controls {
    display: flex;
    gap: 20px;
    margin-top: 30px;
}

.call-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
}

.call-btn.danger {
    background: var(--error);
}

.call-btn.success {
    background: var(--success);
    color: black;
}

.call-btn.secondary {
    background: #555;
}

/* Video UI */
.video-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    height: 60vh;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#local-video {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 120px;
    height: 160px;
    background: #222;
    border-radius: 8px;
    border: 2px solid #333;
    object-fit: cover;
    z-index: 2;
}

/* Admin */
.admin-content {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    /* Use flex instead of calc height */
}

.admin-tabs {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.tab-btn {
    padding: 10px 20px;
    background: var(--bg-card);
    color: var(--text-sec);
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.tab-btn.active {
    background: var(--primary) !important;
    color: #000 !important;
}

.fab {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #000 !important;
    border: none;
    font-size: 24px;
    box-shadow: 0 0 10px var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.fab:hover {
    box-shadow: 0 0 20px var(--primary);
    transform: scale(1.1);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
}


.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.user-card {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
}

.user-card button {
    margin-top: 10px;
    width: 100%;
    padding: 8px;
    cursor: pointer;
    background: #333;
    color: white;
    border: none;
    border-radius: 4px;
}

.form-container {
    max-width: 400px;
    margin: 0 auto;
    background: var(--bg-card);
    padding: 30px;
    border-radius: 8px;
}

.form-container input,
.form-container select {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    background: #000;
    border: 1px solid #333;
    color: #fff;
    border-radius: 4px;
}

.code-display {
    background: #000;
    padding: 10px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    word-break: break-all;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.close-modal {
    float: right;
    font-size: 24px;
    cursor: pointer;
}

.perm-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #333;
}

/* Responsive Mobile */
@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }

    .mobile-only {
        display: block;
    }

    aside {
        width: 100%;
    }

    .chat-layout.chat-active aside {
        display: none;
    }

    .chat-layout.chat-active main {
        display: flex;
    }

    /* Khatabook Styles */
    .sidebar-tabs {
        display: flex;
        border-bottom: 1px solid var(--border);
    }

    .side-tab {
        flex: 1;
        background: none;
        border: none;
        padding: 12px;
        color: var(--text-secondary);
        cursor: pointer;
        font-weight: 500;
    }

    .side-tab.active {
        color: var(--primary);
        border-bottom: 2px solid var(--primary);
    }

    .sidebar-content {
        display: none;
        flex: 1;
        overflow-y: auto;
    }

    .sidebar-content.active {
        display: block;
    }

    #khata-list {
        padding-bottom: 70px;
        /* Space for FAB */
        height: calc(100vh - 120px);
    }

    .khata-item {
        padding: 15px;
        border-bottom: 1px solid var(--border);
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .khata-item:hover {
        background: var(--surface-hover);
    }

    .khata-item h4 {
        margin: 0;
        font-size: 16px;
    }

    .khata-item p {
        margin: 4px 0 0;
        font-size: 12px;
        color: var(--text-secondary);
    }

    .balance {
        font-weight: 600;
        font-size: 14px;
    }

    .balance.green {
        color: #4caf50;
    }

    .balance.red {
        color: #f44336;
    }

    .balance.grey {
        color: var(--text-secondary);
    }



    /* Khata Detail View */
    #khata-detail-area {
        display: flex;
        flex-direction: column;
        height: 100%;
    }

    #transactions-container {
        flex: 1;
        overflow-y: auto;
        padding: 15px;
        background: var(--background);
    }

    #khata-actions-footer {
        display: flex;
        padding: 10px;
        background: var(--surface);
        border-top: 1px solid var(--border);
        gap: 10px;
    }

    .khata-btn {
        flex: 1;
        padding: 12px;
        border: none;
        border-radius: 8px;
        font-weight: 600;
        color: white;
        cursor: pointer;
    }

    .khata-btn.red {
        background: #f44336;
    }

    .khata-btn.green {
        background: #4caf50;
    }

    .tx-item {
        background: var(--surface);
        padding: 12px;
        border-radius: 8px;
        margin-bottom: 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .tx-info h5 {
        margin: 0;
        font-size: 14px;
    }

    .tx-info small {
        color: var(--text-secondary);
        font-size: 12px;
    }

    .tx-amount {
        font-weight: bold;
        font-size: 16px;
    }

    .tx-amount.red {
        color: #f44336;
    }

    .tx-amount.green {
        color: #4caf50;
    }

    .tx-delete-btn {
        background: none;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        margin-left: 10px;
    }

    .tx-delete-btn:hover {
        color: #f44336;
    }

    /* Chat Images */
    .chat-image {
        max-width: 100%;
        border-radius: 8px;
        margin-top: 5px;
        cursor: pointer;
        transition: transform 0.2s;
    }

    .chat-image:hover {
        transform: scale(1.02);
    }

    .chat-layout:not(.chat-active) main {
        display: none;
    }

    /* On mobile, main is usually hidden until a chat is selected */
    /* Handled by JS toggling .chat-active on the .chat-layout container */
}

/* Boot Screen */
#boot-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 20px;
    font-size: 14px;
    color: var(--primary);
}

.boot-line {
    margin-bottom: 5px;
    opacity: 0;
    animation: fadeIn 0.1s forwards;
}

.boot-cursor {
    display: inline-block;
    width: 10px;
    height: 16px;
    background: var(--primary);
    animation: blink 0.8s infinite;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

/* Hacker UI Adjustments */
input,
select,
textarea {
    background: #000 !important;
    border: 1px solid var(--primary) !important;
    color: var(--primary) !important;
    font-family: var(--font-mono) !important;
    border-radius: 0 !important;
    /* Sharp corners */
}

button {
    background: #000 !important;
    color: var(--primary) !important;
    border-radius: 0 !important;
    text-transform: uppercase;
    letter-spacing: 1px;
    border: 1px solid var(--primary) !important;
    transition: all 0.2s;
    cursor: pointer;
}

button:hover {
    background: var(--primary) !important;
    color: #000 !important;
    box-shadow: 0 0 10px var(--primary);
}

.user-card,
.contact-item,
.message,
aside,
header {
    border-color: var(--border-color) !important;
    border-radius: 0 !important;
}

.message.sent {
    background: var(--primary-variant) !important;
    color: #fff !important;
}

.message.received {
    background: var(--bg-card) !important;
    border: 1px solid var(--border-color) !important;
}

#login-screen {
    background: #000 !important;
}

.login-container {
    border: 1px solid var(--primary);
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #000;
}

::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border: 1px solid var(--primary);
}

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