/* ===========================================================
   Sistema Medico - Tema profesional
   Paleta clinica: azul/teal medico sobre neutros limpios.
   =========================================================== */

:root {
    --sm-primary: #0E7490;
    --sm-primary-dark: #155E75;
    --sm-primary-light: #0EA5A4;
    --sm-accent: #2563EB;
    --sm-success: #16A34A;
    --sm-warning: #D97706;
    --sm-danger: #DC2626;
    --sm-info: #0284C7;

    --sm-bg: #F1F5F9;
    --sm-surface: #FFFFFF;
    --sm-border: #E2E8F0;
    --sm-text: #0F172A;
    --sm-muted: #64748B;

    --sm-sidebar-bg: #0F172A;
    --sm-sidebar-bg-2: #1E293B;
    --sm-sidebar-text: #CBD5E1;
    --sm-sidebar-active: #0EA5A4;

    --sm-sidebar-width: 256px;
    --sm-radius: 12px;
    --sm-shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }

body {
    background-color: var(--sm-bg);
    color: var(--sm-text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
}

/* Bootstrap primary override */
.btn-primary {
    --bs-btn-bg: var(--sm-primary);
    --bs-btn-border-color: var(--sm-primary);
    --bs-btn-hover-bg: var(--sm-primary-dark);
    --bs-btn-hover-border-color: var(--sm-primary-dark);
    --bs-btn-active-bg: var(--sm-primary-dark);
    --bs-btn-active-border-color: var(--sm-primary-dark);
}
.btn-outline-primary {
    --bs-btn-color: var(--sm-primary);
    --bs-btn-border-color: var(--sm-primary);
    --bs-btn-hover-bg: var(--sm-primary);
    --bs-btn-hover-border-color: var(--sm-primary);
    --bs-btn-active-bg: var(--sm-primary);
}
.text-primary { color: var(--sm-primary) !important; }
.bg-primary { background-color: var(--sm-primary) !important; }
a { color: var(--sm-primary); }
.link-muted { color: var(--sm-muted); text-decoration: none; }
.link-muted:hover { color: var(--sm-primary); }

/* ===================== Layout ===================== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sm-sidebar-width);
    background: linear-gradient(180deg, var(--sm-sidebar-bg), var(--sm-sidebar-bg-2));
    color: var(--sm-sidebar-text);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .25s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .logo {
    width: 36px; height: 36px;
    background: var(--sm-primary-light);
    border-radius: 10px;
    display: grid; place-items: center;
    color: #fff; font-size: 1.2rem;
}
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
}
.sidebar-nav .nav-section {
    text-transform: uppercase;
    font-size: .7rem;
    letter-spacing: .08em;
    color: #64748B;
    padding: 14px 12px 6px;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--sm-sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 2px;
    font-size: .92rem;
    transition: background .15s, color .15s;
}
.sidebar-nav a i { font-size: 1.1rem; width: 20px; text-align: center; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active {
    background: var(--sm-primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(14,116,144,.4);
}

.main-wrap {
    flex: 1;
    margin-left: var(--sm-sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: 64px;
    background: var(--sm-surface);
    border-bottom: 1px solid var(--sm-border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 1030;
}
.topbar .menu-toggle { display: none; background: none; border: 0; font-size: 1.4rem; color: var(--sm-text); }
.topbar .page-title { font-weight: 600; font-size: 1.05rem; margin: 0; }

.content { padding: 24px; flex: 1; }

/* ===================== Cards ===================== */
.card {
    border: 1px solid var(--sm-border);
    border-radius: var(--sm-radius);
    box-shadow: var(--sm-shadow);
}
.card-header {
    background: var(--sm-surface);
    border-bottom: 1px solid var(--sm-border);
    font-weight: 600;
}

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
    width: 52px; height: 52px;
    border-radius: 12px;
    display: grid; place-items: center;
    font-size: 1.5rem;
}
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat-card .stat-label { color: var(--sm-muted); font-size: .85rem; }

.icon-soft-primary { background: rgba(14,116,144,.12); color: var(--sm-primary); }
.icon-soft-success { background: rgba(22,163,74,.12); color: var(--sm-success); }
.icon-soft-warning { background: rgba(217,119,6,.12); color: var(--sm-warning); }
.icon-soft-info { background: rgba(2,132,199,.12); color: var(--sm-info); }
.icon-soft-danger { background: rgba(220,38,38,.12); color: var(--sm-danger); }

/* ===================== Tables ===================== */
.table { --bs-table-hover-bg: #f8fafc; }
.table > thead th {
    background: #f8fafc;
    color: var(--sm-muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--sm-border);
    font-weight: 600;
}
.table > tbody td { vertical-align: middle; }

/* ===================== Badges ===================== */
.badge.rounded-pill { padding: .4em .8em; font-weight: 600; }
.status-scheduled, .status-pending { background: rgba(217,119,6,.15); color: #b45309; }
.status-confirmed { background: rgba(2,132,199,.15); color: #0369a1; }
.status-in_progress { background: rgba(37,99,235,.15); color: #1d4ed8; }
.status-completed, .status-paid { background: rgba(22,163,74,.15); color: #15803d; }
.status-cancelled, .status-void, .status-no_show { background: rgba(220,38,38,.15); color: #b91c1c; }
.status-partial { background: rgba(14,116,144,.15); color: var(--sm-primary-dark); }
.status-draft { background: rgba(100,116,139,.15); color: #475569; }

/* ===================== Forms ===================== */
.form-label { font-weight: 600; font-size: .85rem; color: #334155; margin-bottom: .3rem; }
.form-control, .form-select { border-color: var(--sm-border); }
.form-control:focus, .form-select:focus {
    border-color: var(--sm-primary-light);
    box-shadow: 0 0 0 .2rem rgba(14,116,144,.15);
}
.required::after { content: " *"; color: var(--sm-danger); }

/* ===================== Auth / Login ===================== */
.auth-body { margin: 0; background: var(--sm-surface); }
.auth-split { min-height: 100vh; display: flex; }

.auth-brand {
    flex: 1 1 55%;
    position: relative;
    background: linear-gradient(135deg, #0B3A4F 0%, var(--sm-primary-dark) 45%, var(--sm-primary) 100%);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    padding: 48px;
    overflow: hidden;
}
.auth-brand::before {
    content: "";
    position: absolute; inset: 0;
    background-image:
        radial-gradient(circle at 18% 28%, rgba(255,255,255,.10) 0, transparent 38%),
        radial-gradient(circle at 82% 72%, rgba(255,255,255,.07) 0, transparent 42%);
}
.auth-brand::after {
    content: "\F33A";
    font-family: "bootstrap-icons";
    position: absolute; right: -40px; bottom: -40px;
    font-size: 320px; opacity: .06; line-height: 1;
}
.auth-brand-content { position: relative; max-width: 440px; z-index: 1; }
.auth-brand .brand-logo {
    width: 72px; height: 72px; border-radius: 20px;
    background: rgba(255,255,255,.14);
    border: 1px solid rgba(255,255,255,.20);
    display: grid; place-items: center; font-size: 2.2rem; margin-bottom: 26px;
}
.auth-brand h1 { font-size: 2rem; font-weight: 700; margin-bottom: 12px; line-height: 1.2; }
.auth-brand .lead { color: rgba(255,255,255,.82); font-size: 1.05rem; margin-bottom: 34px; }
.auth-feature { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; font-size: .98rem; }
.auth-feature i {
    width: 42px; height: 42px; border-radius: 11px;
    background: rgba(255,255,255,.13);
    display: grid; place-items: center; font-size: 1.2rem; flex-shrink: 0;
}

.auth-panel {
    flex: 1 1 45%;
    display: flex; align-items: center; justify-content: center;
    padding: 40px 24px;
}
.auth-card { width: 100%; max-width: 400px; }
.auth-logo {
    width: 60px; height: 60px; background: var(--sm-primary);
    border-radius: 16px; display: grid; place-items: center;
    color: #fff; font-size: 1.8rem; margin: 0 auto 16px;
}

@media (max-width: 991.98px) {
    .auth-brand { display: none; }
    .auth-panel { flex-basis: 100%; }
}

/* ===================== Public prescription ===================== */
.public-body { background: #f1f5f9; }
.rx-wrap { max-width: 720px; margin: 0 auto; padding: 24px 16px; }
.rx-card { background: #fff; border-radius: 16px; box-shadow: var(--sm-shadow); overflow: hidden; }
.rx-header { background: linear-gradient(135deg, var(--sm-primary-dark), var(--sm-primary)); color: #fff; padding: 24px; }
.rx-body { padding: 24px; }
.rx-med { border: 1px solid var(--sm-border); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; }
.rx-med .med-name { font-weight: 700; color: var(--sm-primary-dark); }

/* ===================== CRM / Chat ===================== */
.crm-grid { display: grid; grid-template-columns: 340px 1fr; gap: 0; height: calc(100vh - 64px - 48px); border: 1px solid var(--sm-border); border-radius: var(--sm-radius); overflow: hidden; background: #fff; }
.crm-list { border-right: 1px solid var(--sm-border); overflow-y: auto; }
.crm-conv { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--sm-border); cursor: pointer; text-decoration: none; color: inherit; }
.crm-conv:hover, .crm-conv.active { background: #f1f5f9; }
.crm-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--sm-primary-light); color: #fff; display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.crm-thread { display: flex; flex-direction: column; height: 100%; }
.crm-messages { flex: 1; overflow-y: auto; padding: 20px; background: #f8fafc; display: flex; flex-direction: column; gap: 8px; }
.crm-empty { display: grid; place-items: center; height: 100%; color: var(--sm-muted); }
.msg { max-width: 70%; padding: 9px 13px; border-radius: 12px; font-size: .92rem; line-height: 1.35; box-shadow: var(--sm-shadow); word-wrap: break-word; }
.msg-inbound { align-self: flex-start; background: #fff; border-bottom-left-radius: 3px; }
.msg-outbound { align-self: flex-end; background: #d1f5e0; border-bottom-right-radius: 3px; }
.msg .msg-meta { font-size: .68rem; color: var(--sm-muted); margin-top: 3px; text-align: right; }
.crm-composer { border-top: 1px solid var(--sm-border); padding: 12px 16px; display: flex; gap: 10px; background: #fff; }

/* ===================== Misc ===================== */
.empty-state { text-align: center; padding: 48px 20px; color: var(--sm-muted); }
.empty-state i { font-size: 3rem; opacity: .4; }
.avatar-sm { width: 36px; height: 36px; border-radius: 50%; background: var(--sm-primary-light); color:#fff; display:grid; place-items:center; font-weight:600; font-size:.85rem; }
.cursor-pointer { cursor: pointer; }
.sidebar-backdrop { display: none; }

/* ===================== Responsive ===================== */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main-wrap { margin-left: 0; }
    .topbar .menu-toggle { display: block; }
    .crm-grid { grid-template-columns: 1fr; }
    .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 1035; }
}
