:root {
    --bg-color: #ffffff;
    --text-primary: #0d0d0d;
    --text-secondary: #737373;
    --border-color: #e5e5e5;
    --bubble-left: #f1f5f9;
    --bubble-right: #4d6bfe;
    --bubble-right-text: #ffffff;
    --accent: #4d6bfe;
    --sidebar-width: 300px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0d0d0d;
        --text-primary: #f5f5f5;
        --text-secondary: #a3a3a3;
        --border-color: #262626;
        --bubble-left: #1f1f1f;
        --bubble-right: #4d6bfe;
    }
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

#app {
    display: flex;
    width: 100vw;
    height: 100%;
}

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    z-index: 10;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.title-row h1 {
    font-size: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.controls-row {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-outline:hover {
    background: var(--bubble-left);
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.search-wrapper input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    padding-right: 90px; /* space for nav */
}

.search-wrapper input:focus, .date-input:focus {
    border-color: var(--accent);
}

.search-nav {
    position: absolute;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-color);
    padding-left: 4px;
}

.search-nav.hidden {
    display: none;
}

.nav-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 2px 4px;
    border-radius: 4px;
}

.nav-btn:hover {
    background: var(--bubble-left);
}

mark {
    background-color: #fde047;
    color: #000;
    border-radius: 2px;
    padding: 0 2px;
}

mark.active-match {
    background-color: #f97316; /* Orange for active match */
    color: #fff;
}

.filter-group {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group.row {
    flex-direction: row;
    gap: 8px;
}

.filter-group.row > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.filter-group input[type="date"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    font-family: inherit;
}

.timeline {
    overflow-y: auto;
    padding: 12px;
    flex: 1;
}

.timeline a {
    display: block;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    border-radius: 6px;
    margin-bottom: 2px;
    transition: all 0.2s;
}

.timeline a:hover {
    background-color: var(--bubble-left);
    color: var(--text-primary);
}

/* Chat Area */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.mobile-header {
    display: none;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-color);
    z-index: 10;
}

.chat-window {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message Bubbles */
.message {
    max-width: 75%;
    display: flex;
    flex-direction: column;
    font-size: 0.95rem;
    line-height: 1.4;
    animation: fadeIn 0.2s ease;
}

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

.sent {
    align-self: flex-end;
    align-items: flex-end;
}
.received {
    align-self: flex-start;
    align-items: flex-start;
}

.bubble {
    padding: 10px 14px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.sent .bubble {
    background-color: var(--bubble-right);
    color: var(--bubble-right-text);
    border-radius: 16px;
    border-bottom-right-radius: 4px;
}

.received .bubble {
    background-color: var(--bubble-left);
    color: var(--text-primary);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

/* Reversed Direction */
body.reversed .sent {
    align-self: flex-start;
    align-items: flex-start;
}
body.reversed .received {
    align-self: flex-end;
    align-items: flex-end;
}
body.reversed .sent .bubble {
    background-color: var(--bubble-left);
    color: var(--text-primary);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 16px;
}
body.reversed .received .bubble {
    background-color: var(--bubble-right);
    color: var(--bubble-right-text);
    border-radius: 16px;
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 16px;
}
body.reversed .sender-name {
    align-self: flex-end;
    margin-right: 4px;
    margin-left: 0;
}

.sender-name {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    margin-left: 4px;
}

.time-stamp {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
    margin-right: 4px;
}

body.reversed .time-stamp {
    align-self: flex-start;
    margin-left: 4px;
    margin-right: 0;
}

/* Date Divider */
.date-divider {
    text-align: center;
    margin: 24px 0 12px 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Links & Attachments */
.message a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    opacity: 0.9;
}

.sent .message a {
    color: #e0e7ff;
}

body.reversed .sent .message a {
    color: var(--accent);
}

.attachment-chip {
    display: inline-block;
    padding: 4px 8px;
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
    font-size: 0.8rem;
    margin-top: 4px;
    margin-right: 4px;
}

.sent .attachment-chip {
    background: rgba(255,255,255,0.2);
}

body.reversed .sent .attachment-chip {
    background: rgba(0,0,0,0.1);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .sidebar {
        display: none;
    }
    .mobile-header {
        display: block;
    }
    .chat-window {
        padding: 12px;
    }
    .message {
        max-width: 85%;
    }
}
