/* ========================================
   NIMBA ERP - Main Stylesheet
   ======================================== */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 240px;
    --header-height: 56px;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.5;
}

/* ---- Layout ---- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

#sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: width 0.2s;
}

#sidebar.collapsed { width: 0; overflow: hidden; }

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-700);
}
.sidebar-header h2 { font-size: 22px; font-weight: 700; letter-spacing: 2px; }
.sidebar-subtitle { font-size: 11px; color: var(--gray-400); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-nav { padding: 12px 0; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-300);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: var(--gray-800); color: white; }
.sidebar-link.active { background: var(--primary); color: white; }
.sidebar-icon { font-size: 16px; width: 20px; text-align: center; }

#top-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 90;
    transition: left 0.2s;
}

.header-right { display: flex; align-items: center; gap: 16px; }
.header-user { color: var(--gray-600); font-size: 13px; }

.main-area {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    padding: 24px;
    flex: 1;
    min-height: calc(100vh - var(--header-height));
    transition: margin-left 0.2s;
}

#sidebar.collapsed ~ #top-header { left: 0; }
#sidebar.collapsed ~ .main-area { margin-left: 0; }

/* ---- Page Header ---- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}
.page-header h1 { font-size: 24px; font-weight: 600; color: var(--gray-900); }

/* ---- Cards ---- */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.card h3 { font-size: 16px; font-weight: 600; color: var(--gray-800); margin-bottom: 12px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: white; border-color: var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-50); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--gray-600); padding: 4px; }
.btn-icon:hover { color: var(--gray-800); }

/* ---- Forms ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 13px; font-weight: 500; color: var(--gray-700); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid .full-width { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; padding-top: 12px; }

/* ---- Tables ---- */
.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left;
    padding: 10px 12px;
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
    color: var(--gray-600);
    white-space: nowrap;
}
.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-700);
}
.data-table tr:hover { background: var(--gray-50); }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--primary-light) !important; }

/* ---- Pagination ---- */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 13px;
    color: var(--gray-500);
}
.pagination-buttons { display: flex; gap: 8px; }

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}
.badge-active, .badge-confirmed, .badge-completed, .badge-approved { background: #dcfce7; color: #166534; }
.badge-discharged, .badge-cancelled, .badge-rejected, .badge-lost, .badge-closed { background: #fee2e2; color: #991b1b; }
.badge-tentative, .badge-pending, .badge-new, .badge-open, .badge-scheduled { background: #fef3c7; color: #92400e; }
.badge-followup, .badge-medium { background: #dbeafe; color: #1e40af; }
.badge-high { background: #fee2e2; color: #991b1b; }
.badge-low { background: #f3f4f6; color: #6b7280; }
.badge-draft { background: #f3f4f6; color: #4b5563; }
.badge-paid, .badge-converted { background: #dcfce7; color: #166534; }

/* ---- Filters ---- */
.filters { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-input {
    padding: 7px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    min-width: 220px;
}
.search-input:focus { outline: none; border-color: var(--primary); }
.filters select {
    padding: 7px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    background: white;
}

/* ---- Detail Pages ---- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-grid .full-width { grid-column: 1 / -1; }
.detail-rows { display: flex; flex-direction: column; gap: 8px; }
.detail-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--gray-100); }
.detail-row span:first-child { color: var(--gray-500); font-size: 13px; }
.detail-row span:last-child { font-weight: 500; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--gray-200); }
.tab {
    padding: 10px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s;
}
.tab:hover { color: var(--gray-800); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* ---- Stats ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-align: center;
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--gray-900); }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card.blue { border-top: 3px solid var(--primary); }
.stat-card.green { border-top: 3px solid var(--success); }
.stat-card.orange { border-top: 3px solid var(--warning); }
.stat-card.red { border-top: 3px solid var(--danger); }
.stat-card.purple { border-top: 3px solid #7c3aed; }
.stat-card.yellow { border-top: 3px solid #eab308; }
.stat-card.teal { border-top: 3px solid #0d9488; }

/* ---- Charts ---- */
.chart-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-label { width: 100px; font-size: 12px; color: var(--gray-600); text-align: right; }
.bar-track { flex: 1; height: 20px; background: var(--gray-100); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.bar-value { width: 60px; font-size: 12px; font-weight: 600; }

/* ---- Dashboard ---- */
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.quick-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-medium { width: 500px; }
.modal-large { width: 700px; }
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { margin: 0; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--gray-400); }
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 20px; }

/* ---- Login ---- */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f, #2563eb);
}
.login-box {
    background: white;
    border-radius: 12px;
    padding: 40px;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-box h1 { text-align: center; font-size: 32px; color: var(--primary); letter-spacing: 4px; margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--gray-500); margin-bottom: 32px; font-size: 13px; }

/* ---- Messages ---- */
.error-message { color: var(--danger); font-size: 13px; margin: 8px 0; padding: 8px; background: #fee2e2; border-radius: 4px; }
.success-message { color: var(--success); font-size: 13px; margin: 8px 0; padding: 8px; background: #dcfce7; border-radius: 4px; }
.empty-state { text-align: center; padding: 40px; color: var(--gray-400); font-size: 14px; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    #sidebar { width: 0; overflow: hidden; }
    #sidebar.open { width: var(--sidebar-width); }
    #top-header { left: 0; }
    .main-area { margin-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Diet Chart Grid ---- */
.diet-chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 8px;
}
.diet-day-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 12px;
}
.diet-day-card h4 {
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 14px;
}
.diet-meal-section { margin-bottom: 6px; }
.diet-meal-section strong { font-size: 12px; color: var(--gray-600); }
.diet-meal-section ul { list-style: none; padding-left: 8px; font-size: 12px; }
.diet-meal-section li { padding: 1px 0; }

/* ---- Assign Plan Steps ---- */
.assign-plan-steps .plan-step {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--gray-200);
}
.assign-plan-steps .plan-step:last-child { border-bottom: none; }
.assign-plan-steps h4 {
    margin-bottom: 10px;
    color: var(--gray-700);
    font-size: 15px;
}
.patient-info-card { margin-top: 10px; }

/* ---- Therapy Assignment Table ---- */
.therapy-assignment-table { font-size: 13px; }
.therapy-assignment-table select,
.therapy-assignment-table input[type="time"] { font-size: 12px; padding: 4px 6px; }

/* ---- Diet Day Form ---- */
.diet-day-form h4 { color: var(--primary); margin-bottom: 6px; }
.diet-meal-row label { font-size: 13px; }

/* ---- Editable Diet Grid (Assign Plan) ---- */
.diet-edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 8px;
}
.diet-day-edit-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 10px;
    min-width: 220px;
}
.diet-add-day-card {
    border: 2px dashed var(--gray-300);
    background: var(--gray-50);
    border-radius: var(--radius);
    min-height: 80px;
}
.diet-day-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--gray-100);
}
.diet-meal-edit-section { margin-bottom: 6px; }
.diet-meal-edit-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--gray-500);
    margin-bottom: 4px;
}
.diet-item-edit-row {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    padding: 6px;
    margin-bottom: 4px;
}
.diet-item-type-toggle {
    display: flex;
    gap: 12px;
    margin-bottom: 4px;
    font-size: 12px;
}
.diet-item-type-toggle label { cursor: pointer; }

/* ---- Recipe Maker ---- */
.rm-config-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}
.rm-add-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    padding: 12px;
    background: var(--gray-50);
    border-radius: var(--radius);
}
.rm-alert {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 4px;
}
.rm-alert--danger { background: #fef2f2; color: var(--danger); border-left: 3px solid var(--danger); }
.rm-alert--warning { background: #fffbeb; color: var(--warning); border-left: 3px solid var(--warning); }
.rm-totals-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.rm-totals-section h4 { margin-bottom: 8px; color: var(--gray-700); font-size: 14px; }
.rm-macro-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.rm-macro-card {
    text-align: center;
    padding: 12px 16px;
    background: var(--primary-light);
    border-radius: var(--radius);
    min-width: 100px;
}
.rm-macro-card.rm-over { background: #fef2f2; border: 1px solid var(--danger); }
.rm-macro-value { font-size: 22px; font-weight: 700; color: var(--primary); }
.rm-macro-card.rm-over .rm-macro-value { color: var(--danger); }
.rm-macro-label { font-size: 11px; color: var(--gray-500); margin-top: 2px; }

/* Gap analysis table */
.rm-gap-table tr.rm-status-ok { }
.rm-gap-table tr.rm-status-low { background: #fffbeb; }
.rm-gap-table tr.rm-status-deficient { background: #fef2f2; }
.rm-gap-table tr.rm-status-excess { background: #fff7ed; }
.rm-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.rm-status-ok .rm-status-badge { background: #dcfce7; color: var(--success); }
.rm-status-low .rm-status-badge { background: #fef3c7; color: var(--warning); }
.rm-status-deficient .rm-status-badge { background: #fecaca; color: var(--danger); }
.rm-status-excess .rm-status-badge { background: #fed7aa; color: #c2410c; }

/* Recipe Maker Tabs (Material 3 Style) */
.rm-card { padding-bottom: 0; }
.rm-card > .card-header { padding-bottom: 0; }
.rm-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--gray-200);
    margin: 16px -20px 0 -20px;
    padding: 0 16px;
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
}
.rm-tabs::-webkit-scrollbar { display: none; /* Safari/Chrome */ }

.rm-tab {
    padding: 0 16px;
    height: 48px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-600);
    position: relative;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 8px 8px 0 0;
}

.rm-tab::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background-color: transparent;
    border-radius: 4px 4px 0 0;
    transition: background-color 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.rm-tab:hover {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

.rm-tab.active {
    color: var(--primary);
}

.rm-tab.active::after {
    background-color: var(--primary);
}

.rm-tab-content {
    padding: 24px 0 16px;
    min-height: 200px;
}
.rm-tab-content:not(.active) { display: none; }

@media (max-width: 768px) {
    .rm-config-row, .rm-add-row { flex-direction: column; }
    .rm-totals-grid { grid-template-columns: 1fr; }
    .rm-tabs { gap: 0; padding: 0 4px; }
    .rm-tab { padding: 8px 10px; font-size: 12px; }
}
