@import url('../shared/zepmed-theme.css');

:root {
    --teal: #0d9488;
    --teal-dark: #0f766e;
    --green: #059669;
    --green-light: #ccfbf1;
    --bg: #ecfdf5;
    --surface: #ffffff;
    --sidebar: linear-gradient(180deg, #0f766e 0%, #0d9488 50%, #6366f1 110%);
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --radius: 14px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--zm-font, "Inter", "Segoe UI", system-ui, -apple-system, sans-serif);
    font-size: 14px;
    line-height: 1.5;
}

.layout { display: grid; grid-template-columns: var(--zm-sidebar-width) 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar {
    background: var(--sidebar);
    background-size: 100% 200%;
    animation: zm-gradient-shift 12s ease infinite;
    color: #fff;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0, 77, 86, 0.15);
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    margin-bottom: 16px;
}
.brand-logo {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: #fff;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 3px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.brand-logo img { width: 100%; height: 100%; object-fit: contain; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.brand p { margin: 0; font-size: 11px; opacity: 0.75; text-transform: uppercase; letter-spacing: 0.06em; }
.sidebar-footer {
    margin-top: auto;
    padding: 12px;
    font-size: 11px;
    opacity: 0.6;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.menu-btn {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    color: rgba(255,255,255,0.85);
    padding: 11px 14px;
    border-radius: 10px;
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s, transform 0.1s;
    cursor: pointer;
}
.menu-btn i { font-size: 18px; width: 22px; opacity: 0.9; }
.menu-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.menu-btn.active {
    background: rgba(255,255,255,0.18);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 3px 0 0 #fff;
}
.menu-btn.menu-logout { margin-top: 8px; color: #fecaca; }
.menu-btn.menu-logout:hover { background: rgba(239,68,68,0.2); }

/* Main content */
.content { padding: 24px 28px; overflow-x: hidden; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.topbar h2 { margin: 0; font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.topbar-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.btn-teal {
    background: var(--teal);
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-teal:hover { background: var(--teal-dark); color: #fff; }
.btn-outline-teal {
    background: #fff;
    border: 1px solid var(--teal);
    color: var(--teal-dark);
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-outline-teal:hover { background: #e0f7fa; }

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--green-light);
    color: var(--green);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse-dot 2s infinite; }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
#liveStatus.polling .live-dot { animation: pulse-dot 0.5s infinite; }

/* Cards */
.card-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: transform 0.15s, box-shadow 0.15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(15,23,42,0.1); }
.kpi-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 22px;
    flex-shrink: 0;
}
.kpi-icon.teal { background: #e0f7fa; color: var(--teal); }
.kpi-icon.green { background: var(--green-light); color: var(--green); }
.kpi-icon.orange { background: #ffedd5; color: #ea580c; }
.kpi-icon.blue { background: #dbeafe; color: #2563eb; }
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.2; margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.chart-card h6 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--text); }

/* Table section */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}
.section-header h6 { margin: 0; font-size: 18px; font-weight: 700; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .form-control {
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 8px 14px;
    min-width: 180px;
    font-size: 13px;
}

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--teal); color: var(--teal); }
.filter-btn.active {
    background: var(--teal);
    border-color: var(--teal);
    color: #fff;
}
.order-filters { display: none; }
.order-filters.visible { display: flex; }
.generic-filters.visible { display: flex; }
.generic-filters { display: none; }

.table-wrap {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow-x: auto;
}
.table { margin: 0; width: 100%; }
.table thead th {
    background: #f8fafc;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.table tbody td {
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    background: #fff;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }

.order-id-cell strong { color: var(--teal-dark); font-size: 14px; }
.order-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.btn-action {
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin: 2px;
    transition: opacity 0.15s;
}
.btn-action:hover { opacity: 0.85; }
.btn-action.primary { background: var(--teal); color: #fff; }
.btn-action.success { background: var(--green-light); color: var(--green); }
.btn-action.info { background: #dbeafe; color: #1d4ed8; }
.btn-action.warning { background: #ffedd5; color: #c2410c; }
.btn-action.danger { background: #fee2e2; color: #b91c1c; }

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: capitalize;
}
.status-partial-forward, .status-forwarded, .status-partial { background: #ffedd5; color: #c2410c; }

.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.pagination-bar small { color: var(--text-muted); }

/* Modals */
.panel-modal {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    display: grid;
    place-items: center;
    z-index: 1000;
    padding: 16px;
}
.panel-modal-card {
    width: min(440px, 96vw);
    background: var(--surface);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}
.login-modal-card {
    width: min(400px, 96vw);
    text-align: center;
}
.login-modal-card .brand-logo { margin: 0 auto 16px; width: 56px; height: 56px; font-size: 26px; }
.login-modal-card h5 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-modal-card .login-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.panel-modal-card .form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.panel-modal-card .form-control, .panel-modal-card .form-select {
    border-radius: 10px;
    border: 1px solid var(--border);
    padding: 10px 14px;
}

.order-modal-wide { width: min(960px, 98vw); max-height: 90vh; overflow-y: auto; }
.order-modal-wide .modal-header-bar {
    background: linear-gradient(135deg, var(--teal-dark), var(--teal));
    color: #fff;
    margin: -28px -28px 20px;
    padding: 20px 28px;
    border-radius: 16px 16px 0 0;
}
.order-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.meta-chip {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 12px;
}
.meta-chip strong { display: block; color: var(--text-muted); font-size: 10px; text-transform: uppercase; margin-bottom: 2px; }

/* Alerts & toast */
.new-order-alert {
    background: linear-gradient(90deg, #059669, #10b981);
    color: #fff;
    padding: 14px 20px;
    margin-bottom: 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    box-shadow: 0 4px 20px rgba(5, 150, 105, 0.35);
    animation: flash 0.6s ease 4;
}
.new-order-flash td { animation: flash-row 0.5s ease 3; }
@keyframes flash { 50% { filter: brightness(1.1); } }
@keyframes flash-row { 50% { background: #ecfdf5 !important; } }

.panel-toast {
    position: fixed; right: 20px; bottom: 20px; z-index: 1100;
    background: var(--text);
    color: #fff;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow);
    max-width: 320px;
}

.app-locked .layout { filter: blur(3px); pointer-events: none; user-select: none; }

.integrations-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.integration-status-card {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}
.integration-status-card.ok { border-left: 4px solid var(--green); }
.integration-status-card.warn { border-left: 4px solid #f59e0b; }

.pharmacy-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: start;
}
.stock-low { color: #dc2626; font-weight: 700; }
.stock-ok { color: var(--green); font-weight: 600; }

#recentOrdersList .recent-order-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
#recentOrdersList .recent-order-item:hover { background: #f8fafc; margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
#recentOrdersList .recent-order-item:last-child { border-bottom: none; }


/* Wholesaler panel extras */
.sidebar { background: linear-gradient(180deg, #0f4c5c 0%, #0f766e 45%, #6366f1 110%); }
.kpi-card.warn { border-left: 4px solid #f59e0b; }
.kpi-card.success { border-left: 4px solid #10b981; }
.order-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; background: #fff; }
.order-card.pending { border-left: 4px solid #f59e0b; }
.order-card.confirmed { border-left: 4px solid #3b82f6; }
.order-card.fulfilled { border-left: 4px solid #10b981; }
.order-card.rejected { border-left: 4px solid #ef4444; opacity: 0.85; }
.status-pill { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 999px; text-transform: uppercase; display: inline-block; }
.status-pill.placed { background: #fef3c7; color: #92400e; }
.status-pill.confirmed { background: #dbeafe; color: #1e40af; }
.status-pill.partially_fulfilled { background: #fef3c7; color: #92400e; }
.status-pill.fulfilled { background: #d1fae5; color: #065f46; }
.order-card.partially_fulfilled { border-left: 4px solid #f59e0b; }
.status-pill.rejected, .status-pill.cancelled { background: #fee2e2; color: #991b1b; }
.wh-hero { background: linear-gradient(135deg, #0f766e, #115e59); color: #fff; border-radius: 16px; padding: 20px 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.wh-hero h3 { margin: 0 0 6px; font-weight: 800; }
.wh-hero p { margin: 0; opacity: 0.9; font-size: 14px; }
.login-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.55); backdrop-filter: blur(4px); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { background: #fff; border-radius: 16px; padding: 28px; width: min(400px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,0.2); }
.toast-banner { position: fixed; right: 20px; bottom: 20px; z-index: 1100; background: var(--text); color: #fff; padding: 14px 20px; border-radius: 12px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow); max-width: 320px; }
.app-locked .layout { filter: blur(3px); pointer-events: none; user-select: none; }
