/* === shadcn/ui Light Theme Variables === */
:root {
    --background: #ffffff;
    --foreground: #09090b;
    --card: #ffffff;
    --card-foreground: #09090b;
    --primary: #171717;
    --primary-foreground: #fafafa;
    --secondary: #f5f5f5;
    --secondary-foreground: #171717;
    --muted: #f5f5f5;
    --muted-foreground: #737373;
    --border: #e5e5e5;
    --input: #e5e5e5;
    --destructive: #ef4444;
    --radius: 0.625rem;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

/* === Base === */
body {
    background: var(--secondary);
    color: var(--foreground);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a {
    color: var(--primary);
}

/* === Navbar === */
.navbar {
    background: var(--card) !important;
    border-bottom: 1px solid var(--border) !important;
    box-shadow: var(--shadow-sm);
}

.navbar .navbar-brand {
    color: var(--foreground) !important;
    font-weight: 700;
}

.navbar .nav-link {
    color: var(--muted-foreground) !important;
    font-weight: 500;
    border-radius: var(--radius);
    padding: 0.4rem 0.75rem !important;
    transition: background 0.15s, color 0.15s;
}

.navbar .nav-link:hover {
    color: var(--foreground) !important;
    background: var(--muted);
}

.navbar .nav-link.active {
    color: var(--foreground) !important;
    background: var(--muted);
    font-weight: 600;
}

.navbar-toggler {
    border-color: var(--border) !important;
}

.navbar-toggler-icon {
    filter: invert(0) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2823,23,23,0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") !important;
}

/* === Cards === */
.card {
    background: var(--card) !important;
    border: 1px solid var(--border) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow);
    color: var(--card-foreground) !important;
}

.card .text-muted {
    color: var(--muted-foreground) !important;
}

.card .fw-bold, .card .fs-3 {
    color: var(--foreground) !important;
}

/* === Tables === */
.table {
    color: var(--foreground) !important;
    --bs-table-bg: var(--card);
    --bs-table-striped-bg: #fafafa;
    --bs-table-hover-bg: var(--muted);
    border-color: var(--border) !important;
}

.table thead th {
    background: var(--muted) !important;
    color: var(--muted-foreground) !important;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border) !important;
}

.table td, .table th {
    border-color: var(--border) !important;
    vertical-align: middle;
    padding: 0.5rem 0.75rem;
}

.table-sm td, .table-sm th {
    vertical-align: middle;
}

.table a {
    color: var(--primary);
    font-weight: 500;
}

.table a:hover {
    text-decoration: underline;
}

/* === Buttons === */
.btn-primary, .btn-primary:visited {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: var(--primary-foreground) !important;
    border-radius: var(--radius);
    font-weight: 500;
}

.btn-primary:hover {
    background: #333 !important;
    border-color: #333 !important;
}

.btn-outline-primary {
    color: var(--primary) !important;
    border-color: var(--border) !important;
    border-radius: var(--radius);
}

.btn-outline-primary:hover {
    background: var(--primary) !important;
    color: var(--primary-foreground) !important;
}

.btn-outline-secondary, .btn-outline-light {
    color: var(--foreground) !important;
    border-color: var(--border) !important;
    border-radius: var(--radius);
    font-weight: 500;
}

.btn-outline-secondary:hover, .btn-outline-light:hover {
    background: var(--muted) !important;
    color: var(--foreground) !important;
    border-color: var(--border) !important;
}

.btn-outline-danger {
    border-radius: var(--radius);
}

.btn-sm {
    border-radius: calc(var(--radius) - 2px);
}

/* === Badges === */
.badge {
    border-radius: calc(var(--radius) - 2px);
    font-weight: 500;
    font-size: 0.75rem;
}

.badge-low { background-color: #dbeafe !important; color: #1e40af !important; }
.badge-medium { background-color: #fef3c7 !important; color: #92400e !important; }
.badge-high { background-color: #fed7aa !important; color: #c2410c !important; }
.badge-critical { background-color: #fecaca !important; color: #b91c1c !important; }

.bg-info { background-color: #dbeafe !important; color: #1e40af !important; }
.bg-warning { background-color: #fef3c7 !important; color: #92400e !important; }
.bg-secondary { background-color: var(--muted) !important; color: var(--muted-foreground) !important; }
.bg-success { background-color: #dcfce7 !important; color: #166534 !important; }
.bg-primary { background-color: var(--primary) !important; color: var(--primary-foreground) !important; }
.bg-danger { background-color: #fecaca !important; color: #b91c1c !important; }

/* === Forms === */
.form-control, .form-select {
    border: 1px solid var(--input) !important;
    border-radius: var(--radius);
    background: var(--card) !important;
    color: var(--foreground) !important;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px rgba(23,23,23,.1) !important;
}

.form-check-input:checked {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.form-label {
    color: var(--foreground);
    font-weight: 500;
}

/* === Login page === */
body.login-page {
    background: var(--secondary);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.login-card h2 {
    color: var(--foreground);
    text-align: center;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.login-card .form-label {
    color: var(--muted-foreground);
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.6rem;
}

/* === Severity text colors === */
.text-warning { color: #b45309 !important; }

/* === Reason text expand === */
.reason-text {
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.reason-text.expanded {
    white-space: normal;
    overflow: visible;
}

/* === Channel toggle === */
.channel-toggle {
    cursor: pointer;
}

/* === Flash messages === */
.flash-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 1050;
    max-width: 400px;
}

.flash-container .alert {
    animation: fadeIn 0.3s ease;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.alert-success {
    background: #dcfce7 !important;
    color: #166534 !important;
    border-color: #bbf7d0 !important;
}

.alert-danger {
    background: #fef2f2 !important;
    color: #b91c1c !important;
    border-color: #fecaca !important;
}

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

/* === List group (escalations sidebar) === */
.list-group-item {
    background: var(--card) !important;
    border-color: var(--border) !important;
    color: var(--foreground) !important;
}

.list-group-item:hover {
    background: var(--muted) !important;
}

/* === Text utilities override === */
.text-muted {
    color: var(--muted-foreground) !important;
}

/* === Headings === */
h4, h5, h6, .h4, .h5, .h6 {
    color: var(--foreground);
    font-weight: 600;
}

/* === Page container === */
.container-fluid {
    background: var(--secondary);
}

/* === Table responsive wrapper === */
.table-responsive {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.table-responsive .table {
    margin-bottom: 0;
}

/* ==============================
   Chat View (Conversation)
   ============================== */

.chat-header {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.chat-header h5 {
    margin: 0;
    font-weight: 600;
}

.chat-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--muted-foreground);
}

.chat-meta-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-meta-label {
    font-weight: 500;
    color: var(--muted-foreground);
}

.chat-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    max-height: 70vh;
    overflow-y: auto;
}

.chat-bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-bubble-client {
    background: var(--muted);
    color: var(--foreground);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.chat-bubble-agent {
    background: var(--primary);
    color: var(--primary-foreground);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-bubble-sender {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.chat-bubble-client .chat-bubble-sender {
    color: var(--muted-foreground);
}

.chat-bubble-agent .chat-bubble-sender {
    color: rgba(255,255,255,.7);
}

.chat-bubble-time {
    font-size: 0.7rem;
    margin-top: 0.35rem;
    text-align: right;
}

.chat-bubble-client .chat-bubble-time {
    color: var(--muted-foreground);
}

.chat-bubble-agent .chat-bubble-time {
    color: rgba(255,255,255,.5);
}

.chat-empty {
    text-align: center;
    color: var(--muted-foreground);
    padding: 3rem 1rem;
    font-size: 0.9rem;
}

/* External link icon button */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--muted-foreground);
    transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
    background: var(--muted);
    color: var(--foreground);
}

/* Status badges */
.status-open { background-color: #dbeafe !important; color: #1e40af !important; }
.status-closed { background-color: var(--muted) !important; color: var(--muted-foreground) !important; }
.status-pending { background-color: #fef3c7 !important; color: #92400e !important; }

/* Sync button */
.btn-sync {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
