@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,100..900;1,9..144,100..900&family=Hanken+Grotesk:ital,wght@0,100..900;1,100..900&display=swap');

:root {
    /* Color Palette */
    --color-barro: #A8331A;
    --color-barro-hover: #8F2712;
    --color-oro: #E0A33E;
    --color-oro-hover: #C58D31;
    --color-crema: #FBF6EE;
    --color-tierra: #241E1A;
    --color-tinta: #221C18;
    --color-verde: #1E7A4D;
    --color-rojo: #C0392B;
    
    /* Neutral overrides */
    --color-card-bg: rgba(255, 255, 255, 0.7);
    --color-border: #E8DFD3;
    --color-text-muted: #665D55;
    
    /* Typography */
    --font-headings: 'Fraunces', serif;
    --font-body: 'Hanken Grotesk', sans-serif;
    
    /* Shadows & Transitions */
    --shadow-soft: 0 4px 20px rgba(34, 28, 24, 0.05);
    --shadow-medium: 0 10px 30px rgba(34, 28, 24, 0.08);
    --transition-fast: all 0.2s ease;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* CSS Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--color-crema);
    color: var(--color-tinta);
    font-size: 16px;
    line-height: 1.5;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-headings);
    font-weight: 600;
    color: var(--color-tierra);
}

a {
    color: var(--color-barro);
    text-decoration: none;
    transition: var(--transition-fast);
}
a:hover {
    color: var(--color-barro-hover);
}

/* Common Components */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-primary {
    background-color: var(--color-barro);
    color: #FFF;
}
.btn-primary:hover {
    background-color: var(--color-barro-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 51, 26, 0.2);
}

.btn-outline {
    background-color: transparent;
    color: var(--color-tierra);
    border: 1px solid var(--color-border);
}
.btn-outline:hover {
    background-color: rgba(34, 28, 24, 0.04);
}

.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: var(--font-body);
    font-size: 1rem;
    background-color: #FFF;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-tinta);
    transition: var(--transition-fast);
}
.form-control:focus {
    outline: none;
    border-color: var(--color-barro);
    box-shadow: 0 0 0 3px rgba(168, 51, 26, 0.1);
}

/* Authentication Page */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
    background: radial-gradient(circle at 10% 20%, rgba(224, 163, 62, 0.05) 0%, rgba(168, 51, 26, 0.05) 90%), var(--color-crema);
}
.auth-card {
    background: var(--color-card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--color-border);
    padding: 2.5rem;
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-medium);
}
.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}
.auth-logo h1 {
    font-size: 2.5rem;
    color: var(--color-barro);
    letter-spacing: -0.02em;
}
.auth-logo p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}
.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
}
.alert-error {
    background-color: rgba(192, 57, 43, 0.1);
    color: var(--color-rojo);
    border: 1px solid rgba(192, 57, 43, 0.2);
}

/* Dashboard Layout */
.dashboard-container {
    display: grid;
    grid-template-columns: 240px 1fr;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

/* Sidebar navigation */
.sidebar {
    background-color: var(--color-tierra);
    color: #FFF;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}
.sidebar-logo {
    font-family: var(--font-headings);
    font-size: 1.8rem;
    color: var(--color-oro);
    margin-bottom: 2.5rem;
    font-weight: 700;
}
.sidebar-nav {
    list-style: none;
    flex: 1;
}
.sidebar-nav li {
    margin-bottom: 0.5rem;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    font-weight: 500;
    transition: var(--transition-fast);
}
.sidebar-nav a:hover, .sidebar-nav li.active a {
    color: #FFF;
    background-color: rgba(255, 255, 255, 0.08);
}
.sidebar-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}
.user-info {
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
}
.logout-btn {
    display: block;
    width: 100%;
    text-align: center;
    background-color: rgba(168, 51, 26, 0.2);
    color: #FFF;
    border: 1px solid var(--color-barro);
}
.logout-btn:hover {
    background-color: var(--color-barro);
}

/* Main Content Wrapper */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.header-bar {
    background-color: #FFF;
    border-bottom: 1px solid var(--color-border);
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-bar h2 {
    font-size: 1.5rem;
}
.tenant-badge {
    background-color: rgba(224, 163, 62, 0.1);
    color: var(--color-oro-hover);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid rgba(224, 163, 62, 0.25);
}

/* Inbox Screen Specifics */
.inbox-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    flex: 1;
    overflow: hidden;
}

/* Conversation List Pane */
.conversations-pane {
    background-color: #FFF;
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.pane-title {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    font-weight: 600;
    font-size: 1.1rem;
    background-color: rgba(248, 245, 240, 0.5);
}
.conversation-list {
    list-style: none;
}
.conversation-item a {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-tinta);
    transition: var(--transition-fast);
}
.conv-body {
    flex: 1;
    min-width: 0; /* allows the ellipsis on .conv-last-msg to work */
}
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-oro) 0%, var(--color-barro) 130%);
    color: #FFF;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-headings);
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
    text-transform: uppercase;
}
.avatar-sm { width: 36px; height: 36px; font-size: 0.85rem; }
.conversation-item:hover a {
    background-color: rgba(248, 245, 240, 0.7);
}
.conversation-item.active a {
    background-color: rgba(168, 51, 26, 0.05);
    border-left: 4px solid var(--color-barro);
}
.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.4rem;
}
.conv-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.conv-time {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.conv-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.conv-last-msg {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}
.badge {
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
}
.badge-open { background-color: rgba(30, 122, 77, 0.1); color: var(--color-verde); }
.badge-closed { background-color: #EEE; color: #666; }
.badge-booked { background-color: rgba(224, 163, 62, 0.1); color: var(--color-oro); }

/* Chat Window Pane */
.chat-pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--color-crema);
}
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--color-text-muted);
    text-align: center;
    padding: 2rem;
}
.chat-empty h3 {
    margin-bottom: 0.5rem;
    font-size: 1.4rem;
}
.chat-header {
    background-color: #FFF;
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-contact-info h3 {
    font-size: 1.1rem;
    margin-bottom: 0.1rem;
}
.chat-contact-info p {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Chat bubble styling */
.message-bubble {
    max-width: 70%;
    padding: 1rem;
    border-radius: 12px;
    font-size: 0.95rem;
    position: relative;
    box-shadow: var(--shadow-soft);
}

.msg-inbound {
    align-self: flex-start;
    background-color: #FFF;
    border-bottom-left-radius: 2px;
    border: 1px solid var(--color-border);
}

.msg-outbound {
    align-self: flex-end;
    background-color: var(--color-barro);
    color: #FFF;
    border-bottom-right-radius: 2px;
}

.msg-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

.msg-inbound .msg-meta {
    color: var(--color-text-muted);
}
.msg-outbound .msg-meta {
    color: rgba(255, 255, 255, 0.7);
}

.msg-sender-badge {
    text-transform: uppercase;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}
.msg-inbound .msg-sender-badge {
    background-color: rgba(34, 28, 24, 0.05);
    color: var(--color-tierra);
}
.msg-outbound .msg-sender-badge {
    background-color: rgba(255, 255, 255, 0.2);
    color: #FFF;
}
.tokens-badge {
    background-color: rgba(224, 163, 62, 0.2);
    color: var(--color-oro);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 700;
}

/* Mobile back link (list <- chat). Hidden on desktop. */
.mobile-back {
    display: none;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
    margin-right: 0.5rem;
}

/* Responsive adjustments — the owner lives on the phone, so this matters. */
@media (max-width: 768px) {
    .dashboard-container {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }
    /* Sidebar collapses into a slim top bar */
    .sidebar {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
    }
    .sidebar-logo { margin-bottom: 0; font-size: 1.4rem; }
    .sidebar-nav { display: none; }
    .sidebar-footer { border-top: none; padding-top: 0; display: flex; align-items: center; gap: 0.75rem; }
    .user-info { margin-bottom: 0; }
    .logout-btn { width: auto; padding: 0.4rem 0.8rem; font-size: 0.8rem; }

    .inbox-grid { grid-template-columns: 1fr; }

    /* Default (no conversation open): show the list, hide the chat. */
    .inbox-grid .chat-pane { display: none; }
    .inbox-grid .conversations-pane { display: flex; }

    /* A conversation is selected: show the chat full-screen, hide the list. */
    .inbox-grid.has-selection .conversations-pane { display: none; }
    .inbox-grid.has-selection .chat-pane { display: flex; }

    .mobile-back { display: inline-flex; }
    .conv-last-msg { max-width: 60vw; }
}
