* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0e1116; color: #e6edf3; height: 100vh; overflow: hidden;
}
.hidden { display: none !important; }

/* ============ AUTH ============ */
.auth-screen {
    display: flex; align-items: center; justify-content: center; height: 100vh;
}
.auth-card {
    background: #161b22; padding: 40px; border-radius: 16px; width: 360px;
    display: flex; flex-direction: column; gap: 12px;
    border: 1px solid #30363d;
}
.auth-card h1 { text-align: center; margin-bottom: 8px; }
.auth-card input {
    padding: 10px 14px; border-radius: 8px; border: 1px solid #30363d;
    background: #0d1117; color: #e6edf3; font-size: 14px; outline: none;
}
.auth-card input:focus { border-color: #58a6ff; }
.switch-link {
    text-align: center; color: #58a6ff; cursor: pointer;
    font-size: 13px; margin-top: 4px;
}
.switch-link:hover { text-decoration: underline; }
.error { color: #f85149; font-size: 13px; }

/* ============ BUTTONS ============ */
button {
    padding: 10px 16px; border: none; border-radius: 8px; cursor: pointer;
    background: #238636; color: #fff; font-weight: 600; font-size: 14px;
    transition: 0.15s;
}
button:hover { opacity: 0.9; }
button.secondary { background: #21262d; color: #e6edf3; }
button.danger { background: #da3633; }

/* ============ MAIN ============ */
.main-screen { display: flex; height: 100vh; }
.sidebar {
    width: 320px; background: #161b22; border-right: 1px solid #30363d;
    display: flex; flex-direction: column; padding: 12px; gap: 8px;
    overflow-y: auto;
}
.me {
    display: flex; align-items: center; gap: 10px; padding: 8px;
    border-radius: 8px; cursor: pointer; background: #0d1117;
}
.me:hover { background: #21262d; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
    background: #30363d;
}
.avatar.big { width: 96px; height: 96px; }

#search-input {
padding: 10px; border-radius: 8px; border: 1px solid #30363d;
background: #0d1117; color: #e6edf3; font-size: 14px; outline: none;
}
#search-input:focus { border-color: #58a6ff; }
#search-results { max-height: 260px; overflow-y: auto; }
.search-header {
    font-size: 11px; color: #8b949e; padding: 8px 4px 4px;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.search-user {
    padding: 8px; border-radius: 6px; cursor: pointer; display: flex;
    align-items: center; gap: 8px; font-size: 14px;
}
.search-user:hover { background: #21262d; }

.tabs { display: flex; gap: 4px; margin-top: 8px; }
.tabs button { flex: 1; background: #21262d; color: #8b949e; font-size: 13px; }
.tabs button.active { background: #238636; color: #fff; }
.create-group { background: #21262d; color: #e6edf3; font-size: 13px; }

.chat-item {
    padding: 10px; border-radius: 8px; cursor: pointer;
    display: flex; flex-direction: column; gap: 4px;
    border-bottom: 1px solid #21262d;
}
.chat-item:hover { background: #21262d; }
.chat-item.active { background: #1f6feb33; }
.chat-item .name { font-weight: 600; font-size: 14px; }
.chat-item .last {
    font-size: 12px; color: #8b949e;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============ CONTENT ============ */
.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-view { display: flex; flex-direction: column; height: 100%; }
.chat-header {
    padding: 16px; border-bottom: 1px solid #30363d;
    display: flex; justify-content: space-between; align-items: center;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; }
#chat-title { font-size: 16px; font-weight: 600; }
#chat-actions button { padding: 8px 12px; font-size: 13px; }

.messages {
    flex: 1; overflow-y: auto; padding: 16px;
    display: flex; flex-direction: column; gap: 8px;
}
.msg {
    max-width: 60%; padding: 8px 12px; border-radius: 12px;
    background: #21262d; word-wrap: break-word; font-size: 14px;
    align-self: flex-start;
}
.msg.mine { background: #1f6feb; align-self: flex-end; }
.msg .sender {
    font-size: 11px; color: #8b949e; margin-bottom: 4px;
}
.msg .sender.clickable { cursor: pointer; }
.msg .sender.clickable:hover { color: #58a6ff; text-decoration: underline; }
.msg img, .msg video { max-width: 100%; border-radius: 8px; margin-top: 4px; }
.msg audio { width: 100%; margin-top: 4px; }
.msg a { color: #58a6ff; }

.chat-input {
    display: flex; gap: 8px; padding: 12px; border-top: 1px solid #30363d;
    align-items: center;
}
#msg-input {
flex: 1; padding: 10px 14px; border-radius: 8px;
border: 1px solid #30363d; background: #0d1117; color: #e6edf3;
font-size: 14px; outline: none;
}
#msg-input:focus { border-color: #58a6ff; }
.chat-input button, .attach {
    background: #21262d; color: #e6edf3; padding: 10px 12px;
    border-radius: 8px; cursor: pointer; border: none; font-size: 16px;
}
.attach { display: inline-block; }
#record-btn.recording { background: #da3633; }

/* ============ ACCOUNTING ============ */
.accounting-view { padding: 16px; overflow-y: auto; height: 100%; }
.acc-header {
    display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.tables-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.table-card {
    padding: 16px; background: #161b22; border-radius: 10px;
    border: 1px solid #30363d; cursor: pointer;
}
.table-card:hover { border-color: #58a6ff; }
.table-editor { margin-top: 16px; overflow-x: auto; }
#table-grid { margin-top: 12px; }
.grid-table { border-collapse: collapse; background: #0d1117; }
.grid-table td, .grid-table th {
    border: 1px solid #30363d; padding: 4px; min-width: 80px; font-size: 13px;
}
.grid-table input {
    width: 100%; border: none; background: transparent; color: #e6edf3;
    padding: 4px; font-size: 13px; outline: none;
}
.grid-table input:focus { background: #161b22; }
.grid-table th { background: #161b22; font-weight: 600; }

/* ============ MODALS ============ */
.modal {
    position: fixed; inset: 0; background: #000000aa;
    display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-card {
    background: #161b22; padding: 24px; border-radius: 16px;
    width: 480px; max-width: 92vw; max-height: 92vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
    border: 1px solid #30363d;
}
.modal-card h2 { margin-bottom: 4px; }
.modal-card input, .modal-card textarea {
    padding: 10px 14px; border-radius: 8px; border: 1px solid #30363d;
    background: #0d1117; color: #e6edf3; font-size: 14px; outline: none;
    font-family: inherit;
}
.modal-card input:focus, .modal-card textarea:focus { border-color: #58a6ff; }
.modal-card textarea { min-height: 120px; resize: vertical; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.modal-actions button { flex: 1; min-width: 100px; }

.field-label { font-size: 12px; color: #8b949e; margin-top: 6px; }
.checkbox-label {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; cursor: pointer; padding: 8px 0;
}

/* ============ PROFILE ============ */
.profile-avatar-block {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 8px 0;
}
.avatar-upload { color: #58a6ff; cursor: pointer; font-size: 13px; }
.avatar-upload:hover { text-decoration: underline; }
.role-badge {
    display: inline-block; padding: 3px 10px; border-radius: 12px;
    background: #21262d; font-size: 12px; color: #58a6ff;
}
.bio-view {
    background: #0d1117; padding: 12px; border-radius: 8px;
    font-size: 13px; white-space: pre-wrap; max-height: 300px;
    overflow-y: auto; border: 1px solid #30363d; color: #c9d1d9;
}

/* ============ INVITE / PRIVATE ============ */
.invite-block { margin-top: 12px; }
.invite-row { display: flex; gap: 6px; margin-top: 4px; }
.invite-row input { flex: 1; font-size: 12px; }
.invite-row button { padding: 8px 12px; }
.private-toggle {
    margin-top: 12px; padding: 10px; border-radius: 8px;
    background: #0d1117; border: 1px solid #30363d;
}
.private-toggle label {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; cursor: pointer;
}

/* ============ MEMBERS ============ */
.members-block {
    margin-top: 16px; border-top: 1px solid #30363d; padding-top: 12px;
}
.members-block h3 { font-size: 14px; margin-bottom: 8px; }
.member-row {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px;
    border-radius: 6px; font-size: 13px;
}
.member-row:hover { background: #0d1117; }
.member-row .avatar { width: 28px; height: 28px; cursor: pointer; }
.member-row .name { cursor: pointer; }
.member-row .name:hover { text-decoration: underline; }
.member-badge {
    padding: 2px 6px; border-radius: 4px; font-size: 10px;
    background: #21262d; color: #8b949e;
}
.member-badge.owner { background: #d29922; color: #000; }
.member-badge.admin { background: #1f6feb; color: #fff; }
.member-row button { padding: 4px 8px; font-size: 11px; background: #21262d; }
.member-row button.danger { background: #da3633; color: white; }

/* ============ CALL ============ */
.call-card { width: 560px; }
.call-videos {
    position: relative; background: #000; border-radius: 10px;
    min-height: 260px; display: flex; align-items: center; justify-content: center;
}
#call-remote { width: 100%; max-height: 60vh; border-radius: 10px; background: #000; }
#call-local {
position: absolute; bottom: 12px; right: 12px;
width: 120px; height: 90px; border-radius: 8px;
border: 2px solid #58a6ff; object-fit: cover; background: #000;
}
.call-status {
    text-align: center; font-size: 13px; color: #8b949e; padding: 4px;
}

/* ============ ADMIN ============ */
#admin-users { margin-top: 16px; overflow-x: auto; }
.admin-table {
    width: 100%; border-collapse: collapse; background: #0d1117;
    border-radius: 10px; overflow: hidden;
}
.admin-table th, .admin-table td {
    padding: 10px 12px; text-align: left; font-size: 13px;
    border-bottom: 1px solid #21262d;
}
.admin-table th {
    background: #161b22; color: #8b949e; font-weight: 600;
    text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px;
}
.admin-table tr:hover td { background: #161b22; }
.admin-table .admin-row td { opacity: 0.7; }
.admin-table select {
    padding: 6px 8px; border-radius: 6px; border: 1px solid #30363d;
    background: #0d1117; color: #e6edf3; font-size: 13px;
}
.admin-table .user-cell {
    display: flex; align-items: center; gap: 8px;
}
.admin-table .user-cell .avatar { width: 28px; height: 28px; }
.you-badge {
    background: #1f6feb; color: white; padding: 2px 6px;
    border-radius: 4px; font-size: 10px; margin-left: 6px;
}

/* ============ LOADER ============ */
.loader {
    position: fixed; top: 16px; right: 16px; background: #1f6feb;
    padding: 8px 16px; border-radius: 8px; font-size: 13px; z-index: 999;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }
