/* ===================================================================
   Smart Prescription OCR - Application Styles
   =================================================================== */

/* ---- CSS Variables ------------------------------------------------ */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #059669;
    --secondary-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --info: #0891b2;
    --info-light: #cffafe;
    --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;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-lg: 12px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --transition: all 0.2s ease;
}

/* ---- Reset / Base ------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; }

/* ---- Navbar ------------------------------------------------------- */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--gray-900);
}
.nav-icon { font-size: 1.5rem; }
.nav-links { display: flex; gap: 0.25rem; }
.nav-link {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    color: var(--gray-600);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* ---- Main Content ------------------------------------------------- */
.main-content {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 2rem;
    min-height: calc(100vh - 180px);
}

/* ---- Footer ------------------------------------------------------- */
.footer {
    text-align: center;
    padding: 1.5rem 2rem;
    color: var(--gray-500);
    font-size: 0.85rem;
    border-top: 1px solid var(--gray-200);
    margin-top: 3rem;
}

/* ---- Cards -------------------------------------------------------- */
.card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}
.card-header h2, .card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--gray-900);
}
.card-body { padding: 0; }

/* ---- Dashboard Grid ----------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    text-align: center;
}
.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}
.stat-card .stat-label {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}
.stat-card.success .stat-value { color: var(--secondary); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.info .stat-value { color: var(--info); }

/* ---- Buttons ------------------------------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.2rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: var(--font-sans);
}
.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); }
.btn-success { background: var(--secondary); color: var(--white); }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline {
    background: var(--white);
    border-color: var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover:not(:disabled) {
    background: var(--gray-50);
    border-color: var(--gray-400);
}
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---- Forms -------------------------------------------------------- */
.form-group {
    margin-bottom: 1.25rem;
}
.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--gray-700);
    margin-bottom: 0.4rem;
}
.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font-sans);
    transition: var(--transition);
    background: var(--white);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea.form-control {
    min-height: 200px;
    resize: vertical;
    font-family: var(--font-mono);
    line-height: 1.5;
}
select.form-control { cursor: pointer; }

/* ---- File Upload -------------------------------------------------- */
.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--gray-50);
    margin-bottom: 1rem;
}
.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-zone .upload-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.upload-zone .upload-text {
    font-size: 0.95rem;
    color: var(--gray-600);
}
.upload-zone .upload-hint {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-top: 0.25rem;
}
.upload-zone input[type="file"] { display: none; }

/* ---- Tables ------------------------------------------------------- */
.table-wrapper { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
}
th {
    background: var(--gray-50);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
tr:hover { background: var(--gray-50); }

/* ---- Confidence Badges -------------------------------------------- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-high { background: var(--secondary-light); color: var(--secondary); }
.badge-medium { background: var(--warning-light); color: var(--warning); }
.badge-low { background: var(--danger-light); color: var(--danger); }
.badge-draft { background: var(--info-light); color: var(--info); }
.badge-reviewed { background: var(--warning-light); color: var(--warning); }
.badge-approved { background: var(--secondary-light); color: var(--secondary); }
.badge-rejected { background: var(--danger-light); color: var(--danger); }

/* ---- Confidence Bar ----------------------------------------------- */
.confidence-bar {
    width: 100%;
    height: 6px;
    background: var(--gray-200);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.25rem;
}
.confidence-bar .fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}
.confidence-bar .fill.high { background: var(--secondary); }
.confidence-bar .fill.medium { background: var(--warning); }
.confidence-bar .fill.low { background: var(--danger); }

/* ---- Prescription Detail ------------------------------------------ */
.prescription-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--gray-100);
}
.info-row:last-child { border-bottom: none; }
.info-label {
    font-size: 0.85rem;
    color: var(--gray-500);
    font-weight: 500;
}
.info-value {
    font-size: 0.9rem;
    color: var(--gray-800);
    font-weight: 500;
}

/* ---- Medication Card ---------------------------------------------- */
.med-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
    gap: 0.75rem;
    align-items: center;
}
.med-card .drug-name {
    font-weight: 600;
    color: var(--gray-900);
}
.med-card .drug-category {
    font-size: 0.8rem;
    color: var(--gray-500);
}

/* ---- Raw Text Display --------------------------------------------- */
.raw-text-box {
    background: var(--gray-800);
    color: #e5e7eb;
    padding: 1rem;
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

/* ---- Audit Log ---------------------------------------------------- */
.audit-entry {
    display: flex;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.85rem;
}
.audit-entry:last-child { border-bottom: none; }
.audit-time {
    color: var(--gray-400);
    white-space: nowrap;
    min-width: 140px;
}
.audit-action { font-weight: 500; color: var(--gray-700); }
.audit-details { color: var(--gray-500); }

/* ---- Tabs --------------------------------------------------------- */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 1.5rem;
    gap: 0;
}
.tab {
    padding: 0.75rem 1.25rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--gray-500);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
    font-family: var(--font-sans);
}
.tab:hover { color: var(--gray-700); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- Toast Notifications ------------------------------------------ */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    color: var(--white);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
    max-width: 400px;
}
.toast-success { background: var(--secondary); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
.toast-warning { background: var(--warning); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ---- Loading Spinner ---------------------------------------------- */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--gray-500);
    gap: 0.75rem;
}

/* ---- Empty State -------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-400);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 {
    font-size: 1.1rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}
.empty-state p { font-size: 0.9rem; }

/* ---- Editable Field ----------------------------------------------- */
.editable-field {
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: var(--transition);
}
.editable-field:hover { background: var(--primary-light); }
.editable-field input, .editable-field select {
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 0.9rem;
    width: 100%;
}

/* ---- Responsive --------------------------------------------------- */
@media (max-width: 768px) {
    .navbar { padding: 0 1rem; }
    .nav-title { display: none; }
    .main-content { padding: 0 1rem; margin: 1rem auto; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .section-grid { grid-template-columns: 1fr; }
    .med-card {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    .prescription-header { flex-direction: column; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .nav-links { gap: 0; }
    .nav-link { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
}
