@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --bg: #0f0f12;
    --bg-card: #18181c;
    --bg-elevated: #1f1f24;
    --bg-hover: #25252c;
    --text: #f0f0f5;
    --text-muted: #8b8b96;
    --text-subtle: #5c5c66;
    --border: #2a2a32;
    --border-focus: #3d3d48;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: rgba(99, 102, 241, 0.15);
    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --error: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Outfit', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 20px 16px;
    background: linear-gradient(180deg, var(--bg-card) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.header h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}

.header .sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.tab:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.tab.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: var(--transition);
}

.card:active {
    background: var(--bg-hover);
}

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

.ticket-subject {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    flex: 1;
    min-width: 0;
}

.ticket-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    gap: 12px;
}

.status-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
}

.status-open {
    background: var(--accent-soft);
    color: var(--accent);
}

.status-in_progress {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.status-closed {
    background: var(--success-soft);
    color: var(--success);
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--accent);
}

.btn-ghost:hover {
    background: var(--accent-soft);
}

.btn-block {
    width: 100%;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0;
}

.chat-header {
    padding: 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.chat-header .back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    margin-bottom: 12px;
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
}

.msg.out {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.msg.in {
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg-author {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.msg.in .msg-author {
    color: var(--accent);
}

.msg-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
}

.msg-attachments {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.msg-attachment {
    display: block;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: inherit;
    text-decoration: none;
}

.msg.in .msg-attachment {
    background: var(--bg-hover);
    color: var(--text);
}

.msg-attachment img {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-sm);
    display: block;
}

.chat-input-wrap {
    padding: 12px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.chat-attach-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.chat-attach-item {
    position: relative;
}

.chat-attach-item img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: var(--radius-sm);
}

.chat-attach-item span {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-attach-item .remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--error);
    color: white;
    border: none;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input-row textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 12px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 22px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    transition: var(--transition);
}

.chat-input-row textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.attach-btn, .send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.attach-btn {
    background: var(--bg-elevated);
    color: var(--text-muted);
}

.attach-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.send-btn {
    background: var(--accent);
    color: white;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
}

.error-msg {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 16px;
}

.hidden {
    display: none !important;
}

.screen {
    display: none;
    flex-direction: column;
    min-height: 100vh;
}

.screen.active {
    display: flex;
}

@media (max-width: 400px) {
    .content { padding: 12px; }
    .tabs { padding: 12px; }
}
