*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f0f2f5; color: #1c1e21; }
html { height: -webkit-fill-available; }

/* Shell */
.app-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: -webkit-fill-available; }

.app-nav {
    display: flex; align-items: center; gap: 1.5rem;
    background: #1a73e8; color: #fff; padding: .6rem 1.2rem;
    flex-shrink: 0;
}
.app-nav-brand { font-weight: 700; font-size: 1.1rem; margin-right: auto; }
.app-nav-link { color: rgba(255,255,255,.85); text-decoration: none; font-size: .9rem; padding: .3rem .6rem; border-radius: 4px; transition: background .15s; }
.app-nav-link:hover, .app-nav-link.active { background: rgba(255,255,255,.2); color: #fff; }

.app-main { flex: 1; overflow: hidden; display: flex; }

/* Device status in header */
.device-status-header { display: flex; gap: 1rem; align-items: center; margin-right: 1rem; }
.device-status-item { display: flex; align-items: center; gap: .35rem; font-size: .8rem; color: rgba(255,255,255,.9); }
.device-info small { opacity: .7; margin-left: 2px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2); }
.status-dot.online { background: #10b981; box-shadow: 0 0 5px #10b981; }
.status-dot.offline { background: #9ca3af; }

/* Inbox two-panel layout */
.inbox { display: flex; flex: 1; min-width: 0; height: 100%; overflow: hidden; }

.thread-panel {
    width: 320px; min-width: 260px; background: #fff;
    border-right: 1px solid #e4e6ea;
    display: flex; flex-direction: column; flex-shrink: 0;
}

.thread-panel-header { padding: .75rem 1rem; border-bottom: 1px solid #e4e6ea; }
.thread-panel-header h2 { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; }

.thread-search {
    width: 100%; padding: .4rem .7rem; border: 1px solid #ddd;
    border-radius: 20px; font-size: .85rem; outline: none;
    background: #f0f2f5;
}
.thread-search:focus { border-color: #1a73e8; background: #fff; }

.thread-list { flex: 1; overflow-y: auto; }

.thread-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .75rem 1rem; cursor: pointer; border-bottom: 1px solid #f0f2f5;
    transition: background .1s;
}
.thread-item:hover { background: #f5f7fb; }
.thread-item.active { background: #e8f0fe; }

.thread-avatar {
    width: 44px; height: 44px; border-radius: 50%;
    background: #1a73e8; color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 1rem; flex-shrink: 0;
}

.thread-info { flex: 1; min-width: 0; }
.thread-name { font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-preview { font-size: .8rem; color: #65676b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-device { font-size: .7rem; color: #1a73e8; margin-top: 1px; }

.thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: .25rem; flex-shrink: 0; }
.thread-time { font-size: .72rem; color: #65676b; }
.thread-badge {
    background: #1a73e8; color: #fff; border-radius: 10px;
    padding: .1rem .4rem; font-size: .72rem; font-weight: 600; min-width: 20px; text-align: center;
}

/* Conversation panel */
.conversation-panel {
    flex: 1; display: flex; flex-direction: column; background: #f0f2f5; overflow: hidden;
}

.conversation-header {
    padding: .75rem 1.2rem; background: #fff; border-bottom: 1px solid #e4e6ea;
    display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
}
.conversation-header-name { font-weight: 600; font-size: 1rem; }
.conversation-header-sub { font-size: .78rem; color: #65676b; }
.device-badge {
    margin-left: auto; background: #e8f0fe; color: #1a73e8;
    font-size: .75rem; padding: .2rem .6rem; border-radius: 12px; font-weight: 500;
}

.message-list { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .4rem; }

.message-row { display: flex; }
.message-row.inbound { justify-content: flex-start; }
.message-row.outbound { justify-content: flex-end; }

.message-row > div { max-width: 65%; display: flex; flex-direction: column; }

.message-bubble {
    padding: .5rem .85rem; border-radius: 18px;
    font-size: .9rem; line-height: 1.4; word-break: break-word;
    min-width: 48px; text-align: center;
}
.message-row.inbound .message-bubble { background: #fff; border-bottom-left-radius: 4px; align-self: flex-start; }
.message-row.outbound .message-bubble { background: #1a73e8; color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }

.message-time { font-size: .7rem; color: #65676b; margin-top: .2rem; }
.message-row.outbound .message-time { color: #65676b; text-align: right; }

.message-status { font-size: .7rem; }
.message-status.pending { color: #f59e0b; }
.message-status.delivered { color: #10b981; }
.message-status.failed { color: #ef4444; }

.message-attachment img { max-width: 220px; border-radius: 8px; margin-top: .3rem; cursor: pointer; }

/* Compose bar */
.compose-bar {
    padding: .75rem 1rem; background: #fff; border-top: 1px solid #e4e6ea;
    display: flex; align-items: flex-end; gap: .6rem; flex-shrink: 0;
    position: sticky; bottom: 0;
    padding-bottom: max(.75rem, env(safe-area-inset-bottom));
}
.compose-input {
    flex: 1; padding: .55rem .9rem; border: 1px solid #ddd; border-radius: 20px;
    font-size: .9rem; resize: none; outline: none; font-family: inherit;
    max-height: 120px; overflow-y: auto; line-height: 1.4;
}
.compose-input:focus { border-color: #1a73e8; }
.compose-send {
    padding: .55rem 1.1rem; background: #1a73e8; color: #fff;
    border: none; border-radius: 20px; font-size: .9rem; cursor: pointer;
    font-weight: 500; transition: background .15s; white-space: nowrap;
}
.compose-send:hover { background: #1557b0; }
.compose-send:disabled { background: #b0c4de; cursor: not-allowed; }

/* Empty state */
.empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; color: #65676b;
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state p { font-size: .95rem; }

/* Notifications page */
.notifications-page { padding: 1.2rem; overflow-y: auto; flex: 1; }
.notifications-page h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }

.notification-card {
    background: #fff; border-radius: 8px; padding: .8rem 1rem;
    margin-bottom: .6rem; display: flex; gap: .8rem; align-items: flex-start;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.notification-card.dismissed { opacity: .5; }
.notification-app { font-size: .75rem; font-weight: 600; color: #1a73e8; }
.notification-title { font-size: .9rem; font-weight: 500; }
.notification-text { font-size: .85rem; color: #444; margin-top: .15rem; }
.notification-time { font-size: .75rem; color: #9ca3af; margin-top: .2rem; }
.notification-dismiss {
    margin-left: auto; background: none; border: 1px solid #ddd; border-radius: 6px;
    padding: .2rem .6rem; font-size: .78rem; cursor: pointer; color: #65676b; white-space: nowrap;
}
.notification-dismiss:hover { background: #f5f7fb; }

/* New message modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-box { background: #fff; border-radius: 12px; padding: 1.5rem; width: 360px; display: flex; flex-direction: column; gap: .75rem; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.modal-box h3 { font-size: 1rem; font-weight: 600; }
.modal-box input, .modal-box select { width: 100%; padding: .5rem .75rem; border: 1px solid #ddd; border-radius: 8px; font-size: .9rem; outline: none; }
.modal-box input:focus, .modal-box select:focus { border-color: #1a73e8; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .25rem; }
.btn-primary { padding: .45rem 1rem; background: #1a73e8; color: #fff; border: none; border-radius: 8px; font-size: .88rem; cursor: pointer; }
.btn-primary:hover { background: #1557b0; }
.btn-secondary { padding: .45rem 1rem; background: #f0f2f5; color: #444; border: none; border-radius: 8px; font-size: .88rem; cursor: pointer; }

/* Blazor error UI */
#blazor-error-ui {
    background: #fff3cd; bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: .6rem 1.25rem .7rem; position: fixed;
    width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid #e50000; }
.validation-message { color: #e50000; }
