/* MedAngel — Healthcare + Logistics SaaS design system */
:root {
    --sidebar-width: 248px;
    --sidebar-bg: #0f172a;
    --sidebar-surface: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #f8fafc;
    --sidebar-accent: #3b82f6;
    --sidebar-accent-soft: rgba(59, 130, 246, .15);
    --content-bg: #f4f6f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --info: #0ea5e9;
    --info-soft: #f0f9ff;
    --radius-sm: .5rem;
    --radius: .75rem;
    --radius-lg: 1rem;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
    --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --input-height: 2.75rem;
    --navbar-height: 60px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background: var(--content-bg);
    color: var(--text-primary);
    font-size: .9375rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Bootstrap overrides ── */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-success:hover { background: #15803d; border-color: #15803d; }
.btn-outline-primary { color: var(--primary); border-color: #bfdbfe; }
.btn-outline-primary:hover { background: var(--primary-soft); color: var(--primary-hover); border-color: var(--primary); }
.text-primary { color: var(--primary) !important; }

.badge { font-weight: 600; font-size: .7rem; letter-spacing: .02em; padding: .35em .65em; border-radius: 999px; }
.bg-primary { background-color: var(--primary) !important; }
.bg-success { background-color: var(--success) !important; }
.bg-warning { background-color: var(--warning) !important; }
.bg-danger { background-color: var(--danger) !important; }

/* ── Shell ── */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #0c1222 100%);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255,255,255,.06);
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.125rem 1.25rem;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -.02em;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

.sidebar-brand-icon {
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #fff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, .35);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .75rem 0 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.15) transparent;
}

.sidebar-group-label {
    padding: .75rem 1.25rem .35rem;
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #475569;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin: 2px .65rem;
    padding: .55rem .85rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s, color .15s, box-shadow .15s;
}

.sidebar-nav .nav-link i {
    width: 1.25rem;
    text-align: center;
    font-size: .9rem;
    opacity: .85;
}

.sidebar-nav .nav-link:hover {
    color: var(--sidebar-text-active);
    background: rgba(255,255,255,.06);
}

.sidebar-nav .nav-link.active {
    color: #fff;
    background: var(--sidebar-accent-soft);
    box-shadow: inset 3px 0 0 var(--sidebar-accent);
}

.sidebar-nav .nav-link.active i { color: #60a5fa; opacity: 1; }

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.06);
    padding: 1rem;
    flex-shrink: 0;
}

.sidebar-footer .btn {
    font-size: .8rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: .45rem .75rem;
}

.sidebar-footer .btn-outline-light {
    border-color: rgba(255,255,255,.15);
    color: #cbd5e1;
}
.sidebar-footer .btn-outline-light:hover { background: rgba(255,255,255,.08); color: #fff; }

.app-main {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

.app-navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: var(--navbar-height);
    position: sticky;
    top: 0;
    z-index: 1030;
    box-shadow: var(--shadow-xs);
}

.app-content { padding: 1.25rem 1.5rem 2rem; }

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.page-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--text-primary);
    margin: 0 0 .15rem;
}

.page-header .page-subtitle {
    font-size: .875rem;
    color: var(--text-secondary);
    margin: 0;
}

/* ── KPI cards (dashboard) ── */
.dashboard-hero {
    margin-bottom: 1.25rem;
}

.dashboard-hero h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -.03em;
    margin: 0 0 .25rem;
}

.dashboard-hero p {
    color: var(--text-secondary);
    margin: 0;
    font-size: .9rem;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    margin-bottom: 1.25rem;
}

@media (max-width: 1400px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card-v2 {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 1.125rem 1.25rem;
    box-shadow: var(--shadow-sm);
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    transition: box-shadow .2s, transform .2s;
}

.kpi-card-v2:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.kpi-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
}

.kpi-icon-v2 {
    width: 42px; height: 42px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.kpi-icon-v2.blue { background: var(--primary-soft); color: var(--primary); }
.kpi-icon-v2.green { background: var(--success-soft); color: var(--success); }
.kpi-icon-v2.amber { background: var(--warning-soft); color: var(--warning); }
.kpi-icon-v2.red { background: var(--danger-soft); color: var(--danger); }
.kpi-icon-v2.slate { background: #f1f5f9; color: #475569; }
.kpi-icon-v2.cyan { background: var(--info-soft); color: var(--info); }

.kpi-trend {
    font-size: .7rem;
    font-weight: 600;
    padding: .2rem .5rem;
    border-radius: 999px;
    white-space: nowrap;
}

.kpi-trend.up { background: var(--success-soft); color: var(--success); }
.kpi-trend.neutral { background: #f1f5f9; color: var(--text-secondary); }
.kpi-trend.warn { background: var(--warning-soft); color: #b45309; }

.kpi-value-v2 {
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -.03em;
    line-height: 1.1;
    color: var(--text-primary);
}

.kpi-label-v2 {
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.kpi-desc {
    font-size: .75rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

/* ── Chart cards ── */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    height: 100%;
    overflow: hidden;
}

.chart-card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.chart-card-header h3 {
    font-size: .95rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.chart-card-header span {
    font-size: .75rem;
    color: var(--text-muted);
}

.chart-card-body { padding: 1rem 1.25rem 1.25rem; }

/* ── Data table card ── */
.data-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.data-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    background: var(--surface-muted);
    flex-wrap: wrap;
}

.data-search {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}

.data-search i {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: .85rem;
    pointer-events: none;
}

.data-search input {
    width: 100%;
    height: 2.25rem;
    padding: 0 .875rem 0 2.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .875rem;
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}

.data-search input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.filter-pill {
    display: inline-flex;
    align-items: center;
    padding: .35rem .75rem;
    font-size: .8rem;
    font-weight: 600;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all .15s;
}

.filter-pill:hover { border-color: #bfdbfe; color: var(--primary); background: var(--primary-soft); }
.filter-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.data-table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-muted);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-secondary);
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table tbody td {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
    font-size: .875rem;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f8fafc; }

.data-table tbody tr.is-hidden { display: none; }

.data-table .cell-primary { font-weight: 600; color: var(--text-primary); }
.data-table .cell-mono { font-family: ui-monospace, monospace; font-size: .8rem; color: var(--text-secondary); }

.data-table-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border-light);
    font-size: .8rem;
    color: var(--text-muted);
    background: var(--surface-muted);
}

.data-empty {
    text-align: center;
    padding: 3rem 1.5rem !important;
    color: var(--text-muted);
}

.data-empty i { font-size: 2rem; opacity: .35; display: block; margin-bottom: .75rem; }

/* ── Action buttons ── */
.btn-action {
    width: 32px; height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all .15s;
}

.btn-action:hover { border-color: #bfdbfe; color: var(--primary); background: var(--primary-soft); }
.btn-action.primary:hover { border-color: var(--primary); color: #fff; background: var(--primary); }

.btn-add {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
    font-size: .875rem;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 2px rgba(37, 99, 235, .2);
}

/* ── Forms ── */
.mwp-form-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.form-section {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.form-section:last-of-type { border-bottom: none; }

.form-section-title {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-secondary);
    margin: 0 0 1rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.form-section-title i { color: var(--primary); font-size: .9rem; }

.mwp-form .form-label {
    font-weight: 600;
    font-size: .8rem;
    color: #334155;
    margin-bottom: .4rem;
}

.mwp-form .form-label .required-mark {
    color: var(--danger);
    margin-left: .15rem;
}

.mwp-form .form-control,
.mwp-form .form-select {
    min-height: var(--input-height);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .9375rem;
    padding: .5rem .875rem;
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}

.mwp-form .form-control:focus,
.mwp-form .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.mwp-form textarea.form-control { min-height: 5rem; }

.mwp-form .form-text { font-size: .78rem; color: var(--text-muted); }

.mwp-form .form-check {
    padding: .65rem .875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    margin-bottom: .5rem;
}

.mwp-form .form-check-input {
    width: 1.15em; height: 1.15em;
    margin-top: .15em;
    border: 2px solid #cbd5e1;
}

.mwp-form .form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.mwp-form .form-check-label { font-weight: 500; font-size: .875rem; }

.form-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.5rem;
    background: var(--surface-muted);
    border-top: 1px solid var(--border-light);
}

/* ── Quick actions ── */
.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.quick-action-btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem 1rem;
    font-size: .85rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    text-decoration: none;
    transition: all .15s;
}

.quick-action-btn:hover { border-color: #bfdbfe; background: var(--primary-soft); color: var(--primary); }
.quick-action-btn.accent { background: var(--primary); border-color: var(--primary); color: #fff; }
.quick-action-btn.accent:hover { background: var(--primary-hover); color: #fff; }

/* ── Status badges ── */
.status-badge { font-weight: 600; }

/* ── Alerts ── */
.alert {
    border: none;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow-xs);
}

.alert-success { background: var(--success-soft); color: #166534; }
.alert-danger { background: var(--danger-soft); color: #991b1b; }

/* ── Auth ── */
.auth-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #2563eb 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-wrapper { width: 100%; max-width: 440px; padding: 1rem; }
.auth-card { border-radius: var(--radius-lg); border: none; box-shadow: var(--shadow-md); }

/* ── Legacy compat ── */
.page-title, h2.h4 { color: var(--text-primary); font-weight: 700; }
.card { border: 1px solid var(--border-light); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.timeline-item { border-left: 2px solid var(--border); padding-left: 1rem; margin-left: .25rem; }

/* ── Navbar extras ── */
.navbar-user {
    display: flex;
    align-items: center;
    gap: .65rem;
    font-size: .875rem;
}

.navbar-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .8rem;
}

.lang-switch .btn {
    font-size: .75rem;
    font-weight: 700;
    padding: .3rem .55rem;
    border-color: var(--border);
}

.lang-switch .btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.sidebar-toggle {
    display: none;
    width: 38px; height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 1035;
    backdrop-filter: blur(2px);
}

@media (max-width: 991px) {
    .sidebar-toggle { display: inline-flex; }
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.is-open { transform: translateX(0); }
    .sidebar-overlay.is-visible { display: block; }
    .app-main { margin-left: 0; }
    .app-content { padding: 1rem; }
}
