:root {
    --primary: #0055FF;
    --primary-dark: #0044CC;
    --primary-light: #E6EEFF;
    --white: #FFFFFF;
    --bg: #F3F4F6;
    --bg-alt: #F9FAFB;
    --text: #111827;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --ok: #10B981;
    --ok-light: #D1FAE5;
    --warn: #F59E0B;
    --warn-light: #FEF3C7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-w: 250px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

h1, h2, h3 {
    margin: 0 0 0.5rem 0;
    font-weight: 600;
    color: var(--text);
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 0.75rem 0; }

.text-muted { color: var(--text-muted); font-size: 0.875rem; }

.hidden { display: none !important; }

/* ---------- LOGIN ---------- */
.login-body {
    background: linear-gradient(135deg, #0055FF 0%, #003BB8 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.login-container { width: 100%; max-width: 480px; }

.login-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.logo-area { margin-bottom: 1.5rem; }

.logo-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: var(--primary);
    color: var(--white);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.75rem;
    margin-bottom: 0.75rem;
}

.logo-icon.small {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    border-radius: 10px;
}

.logo-icon.center { display: flex; margin: 0 auto 1rem; }

.logo-title {
    margin: 0;
    font-size: 2rem;
    color: var(--primary);
    font-weight: 700;
}

.logo-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.login-tagline {
    font-size: 1.125rem;
    color: var(--text);
    margin: 0.5rem 0 1rem;
    font-weight: 600;
}

.login-description {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.login-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.login-footer {
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ---------- BUTTONS ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    line-height: 1.2;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--white);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--bg);
    color: var(--text);
}

.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.85rem; }
.btn-lg { padding: 0.95rem 1.5rem; font-size: 1rem; }

/* ---------- TOPBAR ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.topbar-nav { display: flex; gap: 0.5rem; }

/* ---------- CONTAINER + FORMS ---------- */
.container {
    max-width: 720px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.form-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.form-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.form-header h1 { margin-top: 0.75rem; }

.form-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 600px) {
    .form-row { grid-template-columns: 1fr 1fr; }
}

input[type="text"],
input[type="tel"],
input[type="url"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

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

.hint {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.form-message {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}
.form-message.success { background: var(--ok-light); color: #065F46; }
.form-message.error   { background: var(--danger-light); color: #991B1B; }
.form-message.warning { background: var(--warn-light); color: #92400E; }
.form-message.info    { background: var(--primary-light); color: var(--primary-dark); }

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

/* ---------- PANEL LAYOUT ---------- */
.panel-body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.sidebar.open { transform: translateX(0); }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-weight: 600;
    color: var(--text);
}

.sidebar-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sidebar-search {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.client-list {
    flex: 1;
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    overflow-y: auto;
}

.client-item {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 0.25rem;
    transition: background 0.15s;
}

.client-item:hover { background: var(--bg); }
.client-item.active {
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
}

.client-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.client-name {
    font-weight: 500;
    color: var(--text);
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-phone {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.client-empty {
    padding: 1.5rem 0.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.4);
    z-index: 90;
}

.sidebar-backdrop.show { display: block; }

.hamburger {
    display: flex;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 110;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
    font-size: 1.25rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

.main {
    margin-left: 0;
    padding: 1rem;
    min-height: 100vh;
}

.main-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.5rem 0.5rem 1.25rem;
}

.main-header h1 { margin-bottom: 0.25rem; }

.main-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }

.content-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.card-header h3 { margin: 0; }

.card-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-body { padding: 1rem 1.25rem; }

.card-wide { grid-column: 1 / -1; }

/* ---------- STATUS / METRICS ---------- */
.status-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.status-grid > div { display: flex; flex-direction: column; gap: 0.2rem; }

.label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.value {
    font-weight: 600;
    color: var(--text);
    font-size: 0.95rem;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.metric {
    background: var(--bg-alt);
    border-radius: var(--radius-sm);
    padding: 1rem;
    border: 1px solid var(--border);
}

.metric-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

/* ---------- BADGES ---------- */
.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--bg);
    color: var(--text-muted);
}
.badge-ok      { background: var(--ok-light);      color: #065F46; }
.badge-warn    { background: var(--warn-light);     color: #92400E; }
.badge-danger  { background: var(--danger-light);   color: #991B1B; }
.badge-muted   { background: var(--bg);             color: var(--text-muted); }

/* ---------- CHAT ---------- */
.chat-window {
    max-height: 360px;
    overflow-y: auto;
    background: var(--bg-alt);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-msg.chat-ia { align-self: flex-start; }
.chat-msg.chat-client { align-self: flex-end; align-items: flex-end; }

.chat-bubble {
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    background: var(--white);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.9rem;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

.chat-msg.chat-client .chat-bubble {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

.chat-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    padding: 0 0.25rem;
}

.context-text {
    color: var(--text);
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 0;
    padding: 0.75rem;
    background: var(--bg-alt);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary);
}

/* ---------- RESPONSIVE ---------- */
@media (min-width: 900px) {
    .hamburger { display: none; }
    .sidebar {
        transform: translateX(0);
        box-shadow: none;
    }
    .sidebar-backdrop { display: none !important; }
    .main {
        margin-left: var(--sidebar-w);
        padding: 1.5rem 2rem;
    }
    .content-grid {
        grid-template-columns: 1fr 1fr;
    }
    .card-wide { grid-column: 1 / -1; }
    .metrics-grid { grid-template-columns: repeat(4, 1fr); }
    .status-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 600px) and (max-width: 899px) {
    .metrics-grid { grid-template-columns: repeat(4, 1fr); }
    .status-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .form-card { padding: 1.25rem; }
    .login-card { padding: 1.75rem 1.25rem; }
    .logo-title { font-size: 1.6rem; }
    .main-header { padding-top: 3rem; }
}