:root {
    --ink: #17202a;
    --muted: #637083;
    --line: #dfe5ec;
    --panel: #ffffff;
    --surface: #f4f7fb;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --sidebar: #17324d;
}

* { box-sizing: border-box; }

body {
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
}

.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #eef5ff 0%, #f9fbfc 54%, #ecfdf5 100%);
}

.login-panel {
    width: min(920px, calc(100vw - 32px));
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 36px;
    align-items: center;
}

.brand-block { display: flex; gap: 18px; align-items: center; }
.brand-mark {
    width: 64px; height: 64px; border-radius: 8px; display: grid; place-items: center;
    background: var(--primary); color: white; font-size: 34px; font-weight: 800;
}
.brand-block h1 { margin: 0; font-size: clamp(32px, 6vw, 56px); letter-spacing: 0; }
.brand-block p { margin: 8px 0 0; color: var(--muted); font-size: 18px; }

.login-card, .admin-panel, .metrics-grid article {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 45px rgba(22, 34, 51, .08);
}

.login-card { padding: 28px; }

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

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 320px 1fr; background: var(--surface); }
.sidebar {
    background: var(--sidebar);
    color: white;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.profile-strip { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,.16); }
.profile-strip span { display: block; color: rgba(255,255,255,.72); font-size: 13px; }
.avatar {
    width: 44px; height: 44px; border-radius: 50%;
    display: grid; place-items: center;
    background: #22c55e; color: white; font-weight: 800;
}
.search-control { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.18); color: white; }
.empty-conversations { color: rgba(255,255,255,.78); border-top: 1px solid rgba(255,255,255,.14); padding-top: 18px; }
.empty-conversations p { font-size: 14px; margin-top: 6px; }
.conversation-list { display: grid; gap: 6px; overflow: auto; min-height: 220px; }
.conversation-item {
    width: 100%;
    min-height: 68px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: white;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 8px;
    text-align: left;
}
.conversation-item:hover, .conversation-item.active { background: rgba(255,255,255,.12); }
.conversation-copy { min-width: 0; }
.conversation-copy strong, .conversation-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy small, .conversation-meta small { color: rgba(255,255,255,.7); }
.conversation-meta { display: grid; gap: 5px; justify-items: end; }
.conversation-meta b {
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #22c55e;
    color: white;
    display: grid;
    place-items: center;
    font-size: 12px;
}

.workspace { padding: 28px; overflow: auto; }
.workspace-chat-only {
    display: grid;
    grid-template-rows: minmax(0, 1fr);
}
.workspace-chat-only .chat-panel {
    height: calc(100vh - 56px);
    min-height: 0;
    margin-bottom: 0;
}
.chat-panel {
    height: min(72vh, 720px);
    min-height: 520px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: #e8eef5;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 22px;
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: white;
    border-bottom: 1px solid var(--line);
}
.chat-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.chat-actions .form-control { width: 190px; }
.chat-peer { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-peer h1 {
    margin: 0;
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-peer p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.muted-avatar { background: #94a3b8; }
.message-history {
    padding: 18px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background:
        linear-gradient(rgba(255,255,255,.72), rgba(255,255,255,.72)),
        repeating-linear-gradient(45deg, #dce7f2 0, #dce7f2 2px, #e8eef5 2px, #e8eef5 12px);
}
.message-search-results {
    max-height: 180px;
    overflow: auto;
    background: white;
    border-bottom: 1px solid var(--line);
    padding: 8px 12px;
    display: grid;
    gap: 6px;
}
.message-search-results[hidden] { display: none; }
.typing-indicator {
    background: white;
    border-bottom: 1px solid var(--line);
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 700;
    padding: 7px 18px;
}
.typing-indicator[hidden] { display: none; }
.message-search-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbff;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 8px;
    text-align: left;
}
.message-search-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-search-item small { color: var(--muted); }
.empty-state { color: var(--muted); text-align: center; padding: 18px; }
.message-bubble {
    position: relative;
    width: fit-content;
    max-width: min(680px, 78%);
    padding: 8px 10px 6px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .1);
}
.message-bubble.is-highlighted, .system-message.is-highlighted {
    outline: 3px solid rgba(37,99,235,.35);
}
.message-tools {
    display: none;
    gap: 6px;
    justify-content: flex-end;
    margin-bottom: 4px;
}
.message-bubble:hover .message-tools { display: flex; }
.message-tools button {
    border: 0;
    border-radius: 6px;
    background: rgba(37,99,235,.1);
    color: var(--primary-dark);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 6px;
}
.reply-quote {
    display: grid;
    gap: 2px;
    border-left: 3px solid var(--primary);
    background: rgba(255,255,255,.55);
    padding: 6px 8px;
    border-radius: 6px;
    margin-bottom: 6px;
    max-width: 320px;
}
.reply-quote strong { font-size: 12px; color: var(--primary-dark); }
.reply-quote span {
    color: var(--muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.message-bubble.mine {
    align-self: flex-end;
    background: #dbeafe;
}
.message-bubble.theirs {
    align-self: flex-start;
    background: white;
}
.message-bubble p {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.message-bubble time {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    text-align: right;
}
.sender-name {
    display: block;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 2px;
}
.message-check { color: var(--primary); font-weight: 800; }
.system-message {
    align-self: center;
    max-width: min(520px, 90%);
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.82);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}
.media-preview {
    display: block;
    max-width: min(420px, 100%);
    margin-bottom: 6px;
    border-radius: 8px;
    overflow: hidden;
}
.media-preview img, video.media-preview {
    width: 100%;
    max-height: 340px;
    object-fit: contain;
    display: block;
    background: #0f172a;
}
.audio-preview {
    width: min(360px, 100%);
    display: block;
}
.audio-message {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}
.audio-duration {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}
.document-preview {
    width: min(360px, 100%);
    display: grid;
    gap: 2px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.72);
    color: var(--ink);
    text-decoration: none;
    margin-bottom: 6px;
}
.document-preview span { color: var(--muted); font-size: 12px; }
.composer {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 52px auto;
    gap: 10px;
    padding: 12px;
    background: white;
    border-top: 1px solid var(--line);
}
.reply-preview {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border-left: 3px solid var(--primary);
    background: #eff6ff;
    border-radius: 8px;
    padding: 8px 10px;
}
.reply-preview[hidden] { display: none; }
.reply-preview span { display: grid; gap: 2px; min-width: 0; }
.reply-preview em {
    color: var(--muted);
    font-style: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reply-preview button {
    border: 0;
    background: transparent;
    color: #b91c1c;
    font-weight: 700;
}
.attach-button {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    font-size: 24px;
    line-height: 1;
    color: var(--primary);
    cursor: pointer;
    margin: 0;
    background: white;
}
.attach-button:hover { background: #eff6ff; border-color: var(--primary); }
.attach-menu {
    position: relative;
}
.attach-options {
    position: absolute;
    left: 0;
    bottom: 50px;
    z-index: 20;
    min-width: 150px;
    padding: 6px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 36px rgba(15, 23, 42, .18);
}
.attach-options[hidden] { display: none; }
.attach-options button,
.attach-options label {
    width: 100%;
    border: 0;
    background: transparent;
    border-radius: 6px;
    padding: 9px 10px;
    text-align: left;
    color: var(--ink);
    display: block;
    cursor: pointer;
    margin: 0;
}
.attach-options button:hover,
.attach-options label:hover {
    background: #eff6ff;
    color: var(--primary);
}
.file-input-hidden {
    position: fixed;
    left: -1000px;
    top: -1000px;
    width: 1px;
    height: 1px;
    opacity: 0;
}
.audio-record-button {
    width: 52px;
    height: 42px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: white;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
}
.audio-record-button:hover { background: #eff6ff; border-color: var(--primary); }
.audio-record-button.is-recording {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}
.composer textarea {
    resize: none;
    min-height: 42px;
    max-height: 110px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    outline: none;
}
.composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.attachment-preview {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}
.attachment-preview:empty { display: none; }
.attachment-preview button {
    border: 0;
    background: transparent;
    color: #b91c1c;
    font-weight: 700;
}
.attachment-thumb {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    grid-template-rows: auto auto;
    column-gap: 10px;
    align-items: center;
    min-width: 0;
}
.attachment-thumb img {
    grid-row: 1 / 3;
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}
.attachment-thumb strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
}
.attachment-thumb small { color: var(--muted); }
.recording-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto auto minmax(140px, 1fr) auto auto auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid #fecaca;
    border-radius: 8px;
    background: #fff7f7;
}
.recording-panel[hidden] { display: none; }
.recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: #ef4444;
    box-shadow: 0 0 0 rgba(239,68,68,.6);
    animation: recordPulse 1.2s infinite;
}
.recording-panel button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    padding: 7px 10px;
    color: var(--ink);
    font-weight: 700;
}
.recording-panel button:disabled {
    opacity: .5;
    cursor: not-allowed;
}
.recording-panel audio {
    grid-column: 1 / -1;
    width: 100%;
}
@keyframes recordPulse {
    0% { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
    70% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
    100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}
.admin-spacer { margin-top: 8px; }
.workspace-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.workspace-header h1 { margin: 0; font-size: 28px; }
.workspace-header p { margin: 4px 0 0; color: var(--muted); }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metrics-grid article { padding: 18px; }
.metrics-grid span { color: var(--muted); display: block; font-size: 14px; }
.metrics-grid strong { font-size: 30px; letter-spacing: 0; }

.admin-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; }
.admin-panel { padding: 18px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-heading h2, .admin-panel h2 { margin: 0; font-size: 20px; }

.status-pill { border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 700; }
.status-pill.active { background: #dcfce7; color: #166534; }
.status-pill.blocked { background: #fee2e2; color: #991b1b; }
.status-pill.inactive { background: #e5e7eb; color: #374151; }

.log-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.log-list li { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.log-list span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.mini-metrics {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 14px;
}
.mini-metrics span {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--muted);
}
.mini-metrics strong { color: var(--ink); }
.contact-list { display: grid; gap: 8px; }
.contact-item {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    text-align: left;
}
.contact-item:hover { border-color: var(--primary); background: #f8fbff; }
.contact-item span:last-child { display: grid; }
.contact-item small { color: var(--muted); }
.selectable-list { max-height: 320px; overflow: auto; }
.selectable-contact { cursor: pointer; }
.selectable-contact input {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}
.group-member-list { display: grid; gap: 8px; max-height: 420px; overflow: auto; }
.group-member {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: white;
}
.group-member-copy { min-width: 0; display: grid; }
.group-member-copy strong,
.group-member-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.group-member-copy small { color: var(--muted); }
.group-member-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.group-member-actions button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbff;
    padding: 6px 8px;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary-dark);
}

@media (max-width: 920px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { min-height: auto; }
    .metrics-grid, .admin-grid, .login-panel { grid-template-columns: 1fr; }
    .workspace { padding: 14px; }
    .chat-panel { height: 70vh; min-height: 480px; }
    .chat-header { align-items: flex-start; flex-direction: column; }
    .chat-actions { justify-content: stretch; width: 100%; }
    .chat-actions .form-control { width: 100%; }
    .message-bubble { max-width: 92%; }
    .composer { grid-template-columns: 42px minmax(0, 1fr) 52px; }
    .composer .btn { grid-column: 1 / -1; }
    .recording-panel { grid-template-columns: auto auto minmax(0, 1fr); }
    .group-member { grid-template-columns: 44px minmax(0, 1fr); }
    .group-member-actions { grid-column: 1 / -1; justify-content: stretch; }
}
