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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-input: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --accent-hover: #c73e54;
    --success: #4ecdc4;
    --border: #2a2a4a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Utility class for hiding elements */
.hidden {
    display: none !important;
}

/* ==================== LANDING PAGE ==================== */

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

.landing-header {
    background: var(--bg-secondary);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.landing-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.landing-logo {
    width: 48px;
    height: auto;
}

.admin-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.9rem;
}

.admin-link:hover {
    text-decoration: underline;
}

.landing-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.landing-main h2 {
    font-size: 2rem;
    margin-bottom: 16px;
}

.landing-main p {
    color: var(--text-secondary);
    max-width: 500px;
    margin-bottom: 12px;
}

.landing-main .note {
    font-size: 0.9rem;
    margin-top: 24px;
}

.landing-footer {
    background: var(--bg-secondary);
    padding: 16px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
}

/* ==================== CHAT APP ==================== */

.chat-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.chat-header {
    background: var(--bg-secondary);
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}

.chat-header h1 {
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-header .logo {
    width: 40px;
    height: auto;
}

.chat-area {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 150px;
}

/* Password Screen */
.password-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.password-container {
    max-width: 400px;
    text-align: center;
    padding: 40px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.password-container h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.password-container p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.password-container form {
    display: flex;
    gap: 8px;
}

.password-container input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
}

.password-container input:focus {
    outline: none;
    border-color: var(--accent);
}

.password-error {
    color: #ff6b6b;
    font-size: 14px;
    margin-top: 12px;
}

.welcome {
    max-width: 600px;
    margin: 0 auto;
    padding: 60px 24px;
    text-align: center;
}

.welcome h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
}

.welcome p {
    color: var(--text-secondary);
}

/* Messages */
.message {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.message.user {
    background: var(--bg-primary);
}

.message.assistant, .message.admin {
    background: var(--bg-secondary);
}

.message-inner {
    max-width: 700px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    gap: 16px;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .avatar {
    background: #5436da;
    color: white;
}

.message.assistant .avatar {
    background: var(--success);
    color: #1a1a2e;
}

.message.admin .avatar {
    background: var(--accent);
    color: white;
}

.message-content {
    flex: 1;
    font-size: 15px;
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    color: var(--success);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Input area */
.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, var(--bg-primary) 50%);
    padding: 24px;
    padding-top: 48px;
}

.input-container {
    max-width: 700px;
    margin: 0 auto;
}

.input-wrapper {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: flex-end;
    padding: 12px;
    gap: 8px;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 150px;
    line-height: 1.5;
}

.input-wrapper textarea::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

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

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

.send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.input-footer {
    text-align: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.input-footer a {
    color: var(--text-secondary);
    text-decoration: underline;
}

/* Attachment Button */
.attach-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

.attach-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.attach-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--text-secondary);
}

/* Attachment Preview */
.attachment-preview {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-preview.hidden {
    display: none;
}

.attachment-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-primary);
}

.attachment-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.remove-attachment {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    line-height: 1;
}

.remove-attachment:hover,
.attachment-remove:hover {
    color: var(--error);
}

.attachment-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    line-height: 1;
}

/* Message Attachments Display */
.message-attachments {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.attachment-display {
    display: inline-block;
    max-width: 300px;
}

.attachment-display img.attachment-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.attachment-display img.attachment-image:hover {
    opacity: 0.9;
}

.attachment-display .attachment-filename {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-display.attachment-file {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
}

.attachment-display .attachment-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    text-decoration: none;
}

.attachment-display .attachment-link:hover {
    color: var(--accent);
}

.attachment-display .attachment-icon {
    background: var(--accent);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: bold;
}

/* ==================== ADMIN DASHBOARD ==================== */

.admin-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.admin-header {
    background: var(--bg-secondary);
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-header h1 {
    font-size: 1.1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-logo {
    width: 36px;
    height: auto;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

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

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

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

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

.btn-success {
    background: var(--success);
    color: var(--bg-primary);
}

.btn-small {
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    margin-left: 4px;
}

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

.thread-password-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.thread-password-info code {
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    color: var(--accent);
}

.admin-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Thread List */
.thread-list {
    width: 350px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.thread-list-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.thread-list-header h2 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.filter-tabs {
    display: flex;
    gap: 4px;
}

.filter-tab {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
}

.filter-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.threads-container {
    flex: 1;
    overflow-y: auto;
}

.thread-item {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

.thread-item:hover {
    background: rgba(255,255,255,0.05);
}

.thread-item.active {
    background: var(--bg-input);
}

.thread-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.thread-customer {
    font-weight: 500;
    font-size: 14px;
}

.thread-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.thread-preview {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.thread-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    margin-top: 8px;
}

.thread-status.active {
    background: rgba(78, 205, 196, 0.2);
    color: var(--success);
}

.thread-status.admin-active {
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent);
}

.thread-status.closed {
    background: rgba(160, 160, 160, 0.2);
    color: var(--text-secondary);
}

/* Load More Button */
.load-more-container {
    padding: 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.load-more-btn {
    width: 100%;
}

/* Thread Detail */
.thread-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.no-thread-selected {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.thread-detail-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.thread-info h3 {
    font-size: 1rem;
    margin-bottom: 4px;
}

.thread-info p {
    font-size: 13px;
    color: var(--text-secondary);
}

.thread-actions {
    display: flex;
    gap: 8px;
}

.thread-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.admin-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.admin-input-wrapper {
    display: flex;
    gap: 8px;
}

.admin-input-wrapper input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 14px;
}

.admin-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Inquiry Data Panel */
.inquiry-data {
    padding: 16px 24px;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
}

.inquiry-data h4 {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.inquiry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.inquiry-field {
    font-size: 13px;
}

.inquiry-field label {
    color: var(--text-secondary);
    display: block;
    margin-bottom: 2px;
}

.inquiry-field span {
    color: var(--text-primary);
}

/* Email edit field */
.inquiry-field-email {
    grid-column: 1 / -1;
    max-width: 400px;
}

.email-edit-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

.email-input {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
}

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

.email-input::placeholder {
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
}

.modal-content h3 {
    margin-bottom: 12px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.thread-link-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 13px;
    margin-bottom: 16px;
}

.thread-slug-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 8px;
}

.thread-slug-input::placeholder {
    color: var(--text-secondary);
}

.slug-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Responsive */
@media (max-width: 768px) {
    .admin-layout {
        flex-direction: column;
    }

    .thread-list {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .thread-detail {
        height: 60%;
    }
}
