:root {
    color-scheme: dark;
    --bg: #020617;
    --panel: rgba(8, 18, 30, 0.94);
    --line: rgba(125, 211, 252, 0.18);
    --text: #ecfeff;
    --muted: #93a4b8;
    --teal: #2dd4bf;
    --cyan: #38bdf8;
    --danger: #fb7185;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: radial-gradient(circle at top, rgba(45, 212, 191, 0.16), transparent 22rem), linear-gradient(150deg, #020617, #061827 58%, #03111f);
    color: var(--text);
    overflow: hidden;
}

button, input, textarea { font: inherit; }

[hidden] { display: none !important; }

.app-shell {
    min-height: 100dvh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
    gap: 12px;
}

.app-header {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(8, 18, 30, 0.82);
    padding: 10px 12px;
    box-shadow: 0 16px 40px rgba(2, 8, 23, 0.28);
}

.brand-trigger {
    display: grid;
    place-items: center;
    border: 0;
    background: transparent;
    padding: 0;
}

.brand-trigger img,
.app-header > img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 12px;
    background: #ffffff;
    padding: 4px;
}

.apps-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    background: rgba(2, 6, 23, 0.74);
    padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
}

.apps-modal-panel {
    width: min(100%, 520px);
    max-height: 88dvh;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(8, 18, 30, 0.98);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
    padding: 20px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.modal-header h2,
.modal-header p {
    margin: 0;
}

.modal-header .eyebrow {
    color: var(--teal);
    font-size: 0.72rem;
    font-weight: 900;
    text-transform: uppercase;
}

.icon-button {
    min-width: 40px;
    min-height: 40px;
    border: 1px solid rgba(125, 211, 252, 0.22);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.92);
    color: var(--text);
    font-size: 1.2rem;
}

.apps-status-card {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    margin-top: 18px;
    border: 1px solid rgba(125, 211, 252, 0.16);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.72);
    padding: 14px;
}

.account-card {
    display: grid;
    gap: 4px;
    margin-top: 18px;
    border: 1px solid rgba(125, 211, 252, 0.16);
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.72);
    padding: 14px;
}

.account-card strong,
.account-card span,
.account-card small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-card span,
.account-card small {
    color: var(--muted);
}

.apps-section-title {
    margin: 20px 0 0;
    font-size: 1rem;
    letter-spacing: 0;
}

.apps-status-card strong,
.apps-status-card span,
.apps-status-card small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.apps-status-card span,
.apps-status-card small,
.apps-details dd {
    color: var(--muted);
}

.apps-status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #64748b;
}

.apps-status-dot.is-ok { background: #2dd4bf; }
.apps-status-dot.is-error { background: #fb7185; }

.apps-details {
    display: grid;
    gap: 10px;
    margin: 16px 0;
}

.apps-details div {
    border: 1px solid rgba(125, 211, 252, 0.12);
    border-radius: 14px;
    padding: 10px;
}

.apps-details dt {
    color: #cbd5e1;
    font-size: 0.75rem;
    font-weight: 900;
    text-transform: uppercase;
}

.apps-details dd {
    margin: 4px 0 0;
    overflow-wrap: anywhere;
}

.apps-actions {
    display: grid;
    gap: 9px;
}

.apps-actions button {
    min-height: 46px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--teal), var(--cyan));
    color: #03101d;
    font-weight: 900;
}

.apps-actions .danger-button {
    background: #fb7185;
    color: #fff;
}

.feedback-message {
    margin-top: 14px;
    border: 1px solid rgba(125, 211, 252, 0.16);
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.72);
    color: #bae6fd;
    padding: 10px 12px;
    font-weight: 800;
}

.feedback-error { color: #fecdd3; border-color: rgba(251, 113, 133, 0.35); }
.feedback-success { color: #ccfbf1; border-color: rgba(45, 212, 191, 0.35); }

.app-header strong,
.app-header span {
    display: block;
}

.logout-button {
    margin-left: auto;
    min-height: 38px;
    border: 1px solid rgba(125, 211, 252, 0.22);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.9);
    color: var(--text);
    font-weight: 800;
    padding: 0 12px;
}

.login-shell {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: calc(env(safe-area-inset-top) + 18px) 18px calc(env(safe-area-inset-bottom) + 18px);
}

.login-panel {
    width: min(100%, 420px);
    border: 1px solid var(--line);
    border-radius: 22px;
    background: rgba(8, 18, 30, 0.92);
    box-shadow: 0 24px 70px rgba(2, 8, 23, 0.36);
    padding: 24px;
}

.login-panel img {
    width: 54px;
    height: 54px;
    object-fit: contain;
    border-radius: 16px;
    background: #ffffff;
    padding: 6px;
}

.login-panel p {
    margin: 18px 0 0;
    color: var(--teal);
    font-size: 0.78rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.login-panel h1 {
    margin: 6px 0 0;
    font-size: 2rem;
    letter-spacing: 0;
}

.login-form {
    display: grid;
    gap: 11px;
    margin-top: 24px;
}

.oauth-actions {
    display: grid;
    gap: 10px;
    margin-top: 22px;
}

.oauth-actions button {
    min-height: 48px;
    border: 1px solid rgba(125, 211, 252, 0.2);
    border-radius: 15px;
    background: rgba(15, 23, 42, 0.92);
    color: var(--text);
    font-weight: 900;
}

.oauth-actions button:first-child {
    background: #2563eb;
    border-color: #60a5fa;
}

.oauth-actions button:nth-child(2) {
    background: #ffffff;
    color: #0f172a;
    border-color: #ffffff;
}

.login-form label {
    color: #cbd5e1;
    font-size: 0.9rem;
    font-weight: 800;
}

.login-form input:not([type="checkbox"]) {
    width: 100%;
    min-height: 48px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 15px;
    background: rgba(15, 23, 42, 0.94);
    color: var(--text);
    outline: none;
    padding: 0 14px;
}

.login-form input:focus {
    border-color: rgba(56, 189, 248, 0.72);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.1);
}

.remember-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 2px;
}

.remember-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--teal);
}

.login-error {
    min-height: 20px;
    margin: 0;
    color: var(--danger);
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: none;
}

.login-form button {
    min-height: 48px;
    border: 0;
    border-radius: 15px;
    background: linear-gradient(135deg, var(--teal), var(--cyan));
    color: #03101d;
    font-weight: 900;
}

.login-form button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.app-header strong {
    font-size: 1.05rem;
}

.app-header span {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.message-list {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding: 4px 2px 10px;
    scroll-behavior: smooth;
}

.message {
    max-width: 88%;
    display: grid;
    gap: 5px;
    animation: messageIn 160ms ease both;
}

.message.user {
    align-self: flex-end;
}

.message.assistant,
.message.system {
    align-self: flex-start;
}

.bubble {
    border: 1px solid rgba(125, 211, 252, 0.12);
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.92);
    padding: 12px 14px;
    line-height: 1.48;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.user .bubble {
    border-color: rgba(45, 212, 191, 0.28);
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(20, 184, 166, 0.95));
    color: #ffffff;
}

.message.system .bubble {
    border-color: rgba(245, 158, 11, 0.32);
    background: rgba(245, 158, 11, 0.1);
    color: #fde68a;
}

.time {
    color: rgba(226, 232, 240, 0.58);
    font-size: 0.68rem;
    padding: 0 4px;
}

.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(8, 18, 30, 0.92);
    padding: 10px;
    box-shadow: 0 -14px 40px rgba(2, 8, 23, 0.22);
}

.attachment-list,
.attachment-error,
.attachment-actions {
    grid-column: 1 / -1;
}

.attachment-list {
    display: grid;
    gap: 8px;
}

.attachment-item {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    border: 1px solid rgba(125, 211, 252, 0.14);
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.72);
    padding: 8px;
}

.attachment-preview {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: rgba(8, 47, 73, 0.62);
    color: #bae6fd;
    font-size: 0.72rem;
    font-weight: 900;
    overflow: hidden;
}

.attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-info {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.attachment-info strong,
.attachment-info span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-info strong {
    color: #ecfeff;
    font-size: 0.86rem;
}

.attachment-info span {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 800;
}

.chat-form .attachment-remove {
    min-height: 34px;
    border: 1px solid rgba(251, 113, 133, 0.28);
    border-radius: 11px;
    background: rgba(251, 113, 133, 0.1);
    color: #fecdd3;
    padding: 0 9px;
    font-size: 0.74rem;
}

.attachment-error {
    border: 1px solid rgba(251, 113, 133, 0.35);
    border-radius: 13px;
    background: rgba(127, 29, 29, 0.24);
    color: #fecdd3;
    padding: 9px 11px;
    font-size: 0.82rem;
    font-weight: 800;
}

.attachment-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.chat-form .attachment-button {
    min-height: 38px;
    border: 1px solid rgba(125, 211, 252, 0.18);
    border-radius: 13px;
    background: rgba(15, 23, 42, 0.72);
    color: #dffcff;
    padding: 0 11px;
}

.input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px;
    gap: 9px;
    align-items: end;
}

.chat-form textarea {
    width: 100%;
    min-height: 46px;
    max-height: 140px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 15px;
    background: rgba(15, 23, 42, 0.94);
    color: var(--text);
    outline: none;
    resize: none;
    padding: 12px 13px;
}

.chat-form textarea:focus {
    border-color: rgba(56, 189, 248, 0.72);
    box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.1);
}

.chat-form button {
    min-height: 46px;
    border: 0;
    border-radius: 15px;
    background: linear-gradient(135deg, var(--teal), var(--cyan));
    color: #03101d;
    font-weight: 900;
    padding: 0 15px;
}

.chat-form .voice-button {
    position: relative;
    width: 48px;
    min-width: 48px;
    min-height: 48px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(45, 212, 191, 0.36);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(45, 212, 191, 0.22), rgba(15, 23, 42, 0.96));
    color: #ccfbf1;
    overflow: hidden;
    padding: 0;
    box-shadow: inset 0 0 22px rgba(56, 189, 248, 0.16), 0 10px 24px rgba(2, 8, 23, 0.24);
}

.voice-button.is-listening {
    border-color: rgba(251, 113, 133, 0.94);
    background: radial-gradient(circle, rgba(251, 113, 133, 0.34), rgba(30, 41, 59, 0.96));
    color: #fff1f2;
    animation: voicePulse 1.15s ease-in-out infinite;
}

.voice-button.is-unsupported {
    filter: grayscale(0.9);
}

.voice-orbit {
    position: absolute;
    inset: 7px;
    border: 1px solid rgba(125, 211, 252, 0.44);
    border-left-color: transparent;
    border-radius: 50%;
    animation: voiceOrbit 1.8s linear infinite;
}

.voice-button.is-listening .voice-orbit {
    border-color: rgba(254, 205, 211, 0.76);
    border-left-color: transparent;
    animation-duration: 0.9s;
}

.voice-icon {
    position: relative;
    z-index: 1;
    line-height: 1;
}

.voice-status {
    border: 1px solid rgba(56, 189, 248, 0.26);
    border-radius: 15px;
    background: rgba(8, 47, 73, 0.42);
    color: #bae6fd;
    padding: 10px 13px;
    font-size: 0.84rem;
    font-weight: 800;
}

.voice-status-listening {
    border-color: rgba(45, 212, 191, 0.52);
    background: rgba(20, 184, 166, 0.12);
    color: #99f6e4;
    box-shadow: 0 0 24px rgba(45, 212, 191, 0.14);
}

.voice-status-success {
    border-color: rgba(45, 212, 191, 0.38);
    background: rgba(20, 184, 166, 0.1);
    color: #ccfbf1;
}

.voice-status-error {
    border-color: rgba(251, 113, 133, 0.35);
    background: rgba(127, 29, 29, 0.24);
    color: #fecdd3;
}

.voice-settings {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.voice-toggle,
.chat-form .voice-stop-button {
    min-height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid rgba(125, 211, 252, 0.16);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.58);
    color: #cbd5e1;
    font-size: 0.78rem;
    font-weight: 800;
    padding: 7px 9px;
}

.voice-toggle input {
    width: 16px;
    height: 16px;
    accent-color: var(--teal);
}

.chat-form .voice-stop-button {
    grid-column: 1 / -1;
    border-color: rgba(251, 113, 133, 0.38);
    background: rgba(251, 113, 133, 0.14);
    color: #fecdd3;
}

.chat-form button:disabled {
    opacity: 0.65;
    cursor: wait;
}

@keyframes messageIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes voiceOrbit { to { transform: rotate(360deg); } }

@keyframes voicePulse {
    0%, 100% { box-shadow: inset 0 0 24px rgba(251, 113, 133, 0.18), 0 0 0 0 rgba(251, 113, 133, 0.32); }
    50% { box-shadow: inset 0 0 24px rgba(251, 113, 133, 0.28), 0 0 0 8px rgba(251, 113, 133, 0); }
}

@media (min-width: 760px) {
    .app-shell {
        width: min(100%, 820px);
        margin: 0 auto;
        padding-left: 22px;
        padding-right: 22px;
    }
}
