:root {
    color-scheme: light;
    --bg: #4c1d95;
    --bg-deep: #3b0764;
    --surface: #ffffff;
    --surface-2: #faf5ff;
    --border: #e9d5ff;
    --text: #1e1b4b;
    --muted: #6b7280;
    --accent: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-soft: #ede9fe;
    --accent-light: #c4b5fd;
    --danger: #991b1b;
    --danger-bg: #fef2f2;
    --ok: #065f46;
    --ok-bg: #ecfdf5;
    --sidebar-w: 360px;
    --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Plus Jakarta Sans", system-ui, sans-serif;
    color: var(--text);
    background: var(--surface-2);
}

.is-hidden { display: none !important; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: 0;
    border-radius: 0.625rem;
    padding: 0.55rem 0.9rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #e2e8f0; color: #0f172a; }
.btn-ghost { background: transparent; color: #334155; }
.btn-sm { padding: 0.4rem 0.65rem; font-size: 0.8125rem; }
.btn-block { width: 100%; }

.alert {
    margin: 0.75rem 1rem 0;
    padding: 0.75rem 1rem;
    border-radius: 0.625rem;
    font-size: 0.875rem;
}

.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #a7f3d0; }

/* Login */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    background:
        radial-gradient(circle at top left, rgba(168, 85, 247, 0.35), transparent 42%),
        radial-gradient(circle at bottom right, rgba(109, 40, 217, 0.25), transparent 38%),
        var(--bg-deep);
}

.login-panel {
    width: min(100%, 420px);
    background: var(--surface);
    border-radius: 1rem;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    overflow: hidden;
}

.login-panel-head {
    padding: 1.5rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.eyebrow {
    margin: 0 0 0.25rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
}

.login-panel h1 {
    margin: 0;
    font-size: 1.4rem;
}

.lead {
    margin: 0.65rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

.login-form {
    display: grid;
    gap: 0.85rem;
    padding: 1.25rem 1.5rem 1.5rem;
}

.login-form label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.login-form input {
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    padding: 0.7rem 0.85rem;
    font: inherit;
}

.login-panel .alert { margin: 0 1.5rem; }

.login-secure-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin: 1.25rem 1.5rem 0;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: #ecfdf5;
    color: #065f46;
    font-size: 0.75rem;
    font-weight: 700;
}

.login-secure-badge svg {
    width: 1rem;
    height: 1rem;
}

.login-security-notes {
    list-style: none;
    margin: 0;
    padding: 0 1.5rem 1.35rem;
    display: grid;
    gap: 0.35rem;
    color: var(--muted);
    font-size: 0.78rem;
}

.login-security-notes li::before {
    content: "✓ ";
    color: var(--ok);
    font-weight: 700;
}

.login-phone-input {
    letter-spacing: 0.45em;
    text-align: center;
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 0.85rem 1rem;
}

.login-phone-hint {
    margin: -0.35rem 0 0;
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.45;
}

.login-cancel-btn {
    margin-top: 0.15rem;
    color: var(--muted) !important;
}

.login-form-phone {
    padding-bottom: 1.25rem;
}

.settings-lead {
    margin: 0 0 0.75rem;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

.settings-push-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
}

.push-status {
    margin: 0 0 0.85rem;
    padding: 0.65rem 0.85rem;
    border-radius: 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.45;
}

.push-status--info { background: var(--accent-soft); color: #6d28d9; }
.push-status--ok { background: var(--ok-bg); color: var(--ok); }
.push-status--warn { background: #fffbeb; color: #92400e; }

.push-prompt {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.push-prompt.is-hidden { display: none !important; }

.push-prompt-open { overflow: hidden; }

.push-prompt-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.push-prompt-panel {
    position: relative;
    z-index: 1;
    width: min(100%, 420px);
    padding: 1.35rem 1.35rem 1.15rem;
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

.push-prompt-eyebrow {
    margin: 0 0 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
}

.push-prompt-panel h2 {
    margin: 0;
    font-size: 1.25rem;
}

.push-prompt-text {
    margin: 0.75rem 0 0;
    color: var(--muted);
    font-size: 0.9rem;
    line-height: 1.55;
}

.push-prompt-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 1.1rem;
}

.push-prompt-note {
    margin: 0.85rem 0 0;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
}

/* App shell */
.support-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: var(--topbar-h);
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-topbar-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.app-topbar-title { min-width: 0; }

.app-topbar-eyebrow {
    margin: 0;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}

.app-topbar-title h1 {
    margin: 0;
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-open-badge {
    flex-shrink: 0;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.app-open-badge.is-zero { display: none; }

.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.app-topbar-actions .btn-ghost { color: #e2e8f0; }

.btn-icon {
    width: 2rem;
    height: 2rem;
    padding: 0;
}

.btn-icon .icon-gear {
    width: 1.15rem;
    height: 1.15rem;
}

.app-back-link {
    width: 2rem;
    height: 2rem;
    padding: 0;
    font-size: 1.35rem;
    line-height: 1;
    color: #e2e8f0 !important;
    text-decoration: none;
}

/* Settings page */
.settings-page .settings-main {
    max-width: 560px;
    margin: 0 auto;
    padding: 1rem 0.75rem 2rem;
}

.settings-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    padding: 1rem 1.1rem;
    margin-bottom: 0.85rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.settings-card h2 {
    margin: 0 0 0.85rem;
    font-size: 0.95rem;
}

.settings-dl {
    margin: 0;
    display: grid;
    gap: 0.65rem;
}

.settings-dl div {
    display: grid;
    gap: 0.15rem;
}

.settings-dl dt {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.settings-dl dd {
    margin: 0;
    font-size: 0.9375rem;
}

.settings-form {
    display: grid;
    gap: 0.85rem;
}

.settings-field {
    display: grid;
    gap: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.settings-field select {
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    padding: 0.6rem 0.75rem;
    font: inherit;
    background: #fff;
}

.settings-check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--muted);
    font-weight: 500;
}

.settings-check input { margin-top: 0.15rem; }

.settings-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.5rem;
}

.settings-links a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

.settings-links a:hover { text-decoration: underline; }

.settings-main > .alert { margin-bottom: 0.85rem; }

.app-user {
    display: none;
    font-size: 0.75rem;
    color: #cbd5e1;
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-back-btn {
    display: none;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border: 0;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.45rem;
    line-height: 1;
    cursor: pointer;
}

.support-app.show-ticket-detail .app-back-btn.is-hidden {
    display: none !important;
}

.support-app.show-ticket-detail .app-back-btn:not(.is-hidden) {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.app-layout {
    flex: 1;
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 0;
}

.app-sidebar {
    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, #ffffff 0%, #faf5ff 100%);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.ticket-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.45rem;
    padding: 0.75rem 0.75rem 0.55rem;
}

.ticket-stat {
    display: grid;
    gap: 0.1rem;
    padding: 0.55rem 0.45rem;
    border-radius: 0.65rem;
    background: #fff;
    border: 1px solid var(--border);
    text-align: center;
}

.ticket-stat--pending {
    border-color: #fecaca;
    background: linear-gradient(180deg, #fff 0%, #fef2f2 100%);
}

.ticket-stat--pending .ticket-stat-value { color: #dc2626; }

.ticket-stat-value {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.ticket-stat-label {
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.app-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.7);
}

.app-filter {
    display: grid;
    gap: 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--muted);
}

.app-filter select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    padding: 0.5rem 0.55rem;
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    background: #fff;
    color: var(--text);
}

.ticket-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.ticket-list-head-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.ticket-list-count {
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #e2e8f0;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-variant-numeric: tabular-nums;
}

.ticket-list {
    list-style: none;
    margin: 0;
    padding: 0.45rem;
    overflow: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.ticket-list-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.5;
    border: 1px dashed var(--border);
    border-radius: 0.75rem;
    background: #fff;
}

.ticket-card {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    background: #fff;
    text-align: left;
    padding: 0.75rem 0.8rem;
    cursor: pointer;
    display: grid;
    gap: 0.45rem;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.ticket-card:hover {
    border-color: var(--accent-light);
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.12);
}

.ticket-card.is-active {
    border-color: var(--accent);
    background: linear-gradient(180deg, #f5f3ff 0%, #ffffff 100%);
    box-shadow: 0 0 0 1px var(--accent), 0 8px 20px rgba(124, 58, 237, 0.16);
}

.ticket-card.is-pending {
    border-left: 3px solid #dc2626;
}

.ticket-card.is-closed {
    opacity: 0.82;
    background: #f8fafc;
}

.ticket-card.is-urgent:not(.is-active) {
    border-color: #fecaca;
    background: linear-gradient(180deg, #fff 0%, #fef2f2 100%);
}

.ticket-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.ticket-card-number {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.ticket-card-time {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.ticket-card-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
}

.ticket-card-badges .badge {
    font-size: 0.64rem;
    padding: 0.12rem 0.45rem;
}

.ticket-card-subject {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ticket-card-preview {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: #64748b;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ticket-card-preview-author {
    font-weight: 700;
    color: #475569;
}

.ticket-card-preview-author--admin { color: #7c3aed; }

.ticket-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-top: 0.15rem;
    border-top: 1px solid #f1f5f9;
}

.ticket-card-client {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ticket-card-meta {
    flex-shrink: 0;
    font-size: 0.68rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

/* Legacy aliases removed — ticket-list-btn replaced by ticket-card */

.app-main {
    min-width: 0;
    min-height: 0;
    overflow: auto;
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
}

.app-detail {
    padding: 1rem;
    max-width: 900px;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.app-empty {
    display: grid;
    place-content: center;
    gap: 0.5rem;
    min-height: 100%;
    padding: 2rem;
    text-align: center;
    color: var(--muted);
    flex: 1;
}

.app-empty-icon { font-size: 2rem; }
.app-empty h2 { margin: 0; color: var(--text); font-size: 1.1rem; }

.detail-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.detail-kicker {
    margin: 0;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
}

.detail-head h2 {
    margin: 0.15rem 0 0;
    font-size: 1.25rem;
    line-height: 1.3;
}

.detail-meta {
    margin: 0.35rem 0 0;
    font-size: 0.8125rem;
    color: var(--muted);
}

.detail-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: flex-start; }

.badge {
    display: inline-flex;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
}

.badge-cat--urgent { background: #fee2e2; color: #991b1b; }
.badge-cat--normal { background: var(--accent-soft); color: #6d28d9; }
.badge-cat--billing { background: #fef3c7; color: #92400e; }
.badge-cat--intervention { background: #ede9fe; color: #5b21b6; }

.badge-status--open { background: #dcfce7; color: #166534; }
.badge-status--answered { background: var(--accent-soft); color: #6d28d9; }
.badge-status--closed { background: #e2e8f0; color: #475569; }

.detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.thread {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    align-items: stretch;
    max-height: min(50vh, 420px);
    overflow: auto;
    padding: 0.25rem 0 1rem;
}

.message {
    flex: 0 0 auto;
    align-self: stretch;
    border-radius: 0.75rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    background: var(--surface);
}

.message--admin {
    background: var(--accent-soft);
    border-color: var(--accent-light);
    margin-left: 1.25rem;
    max-width: calc(100% - 0.5rem);
}

.message--client {
    margin-right: 1.25rem;
    max-width: calc(100% - 0.5rem);
}

.message-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.45rem;
    font-size: 0.8125rem;
}

.message-head span { color: var(--muted); }
.message-body {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.9rem;
    line-height: 1.5;
}

.attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.65rem;
}

.attachments a {
    display: block;
    width: 88px;
    height: 88px;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

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

.reply-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    padding: 0.9rem;
    margin-top: auto;
}

.reply-form h3 {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
}

.reply-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    padding: 0.75rem;
    font: inherit;
    resize: vertical;
    min-height: 96px;
}

.reply-upload { margin-top: 0.65rem; }
.reply-upload-label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

.reply-upload-hint {
    margin: 0.35rem 0 0;
    font-size: 0.75rem;
    color: var(--muted);
}

.reply-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.preview-item {
    position: relative;
    width: 72px;
    height: 72px;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
}

.preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 1.35rem;
    height: 1.35rem;
    border: 0;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
}

.reply-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.reply-footer .btn-primary { margin-left: auto; }

@media (min-width: 900px) {
    .app-user { display: inline; }
    .app-topbar { padding: 0.5rem 1rem; }
}

@media (max-width: 899px) {
    .support-app {
        height: 100dvh;
        overflow: hidden;
    }

    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr);
        overflow: hidden;
    }

    .app-sidebar {
        min-height: 0;
        overflow: hidden;
    }

    .app-layout:not(.show-detail) .app-main {
        display: none;
    }

    .app-layout.show-detail .app-sidebar {
        display: none !important;
    }

    .app-layout.show-detail .app-main {
        display: flex;
        overflow: hidden;
    }

    .app-layout.show-detail .app-detail {
        max-width: none;
        height: 100%;
    }

    .app-layout.show-detail .thread {
        flex: 1;
        max-height: none;
        min-height: 0;
        overflow-y: auto;
    }

    .reply-footer .btn-primary {
        width: 100%;
        margin-left: 0;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .app-open-badge.pulse {
        animation: badgePulse 0.6s ease 2;
    }
}

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}
