/* wwwroot/css/app.css */

/* Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 60px;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-sidebar: #1e293b;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    /* iOS Safe Area */
    --safe-area-inset-left: 0;
    --safe-area-inset-right: 0;
    --safe-area-inset-top: 0;
    --safe-area-inset-bottom: 0;
}

/* Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

    .app-container.sidebar-collapsed .sidebar {
        width: var(--sidebar-collapsed-width);
    }

    .app-container.sidebar-collapsed .main-content {
        margin-left: var(--sidebar-collapsed-width);
    }

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 1000;
    overflow-x: hidden;
    padding-top: max(0, var(--safe-area-inset-top));
    padding-left: max(0, var(--safe-area-inset-left));
}

    .sidebar.collapsed {
        width: var(--sidebar-collapsed-width);
    }

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

    .sidebar-header .logo {
        width: 40px;
        height: 40px;
    }

    .sidebar-header .brand-name {
        margin-left: 12px;
        font-size: 18px;
        font-weight: 600;
    }

.sidebar-menu {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: all 0.2s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    min-height: 44px;
    font-size: 15px;
}

    .menu-item:active,
    .menu-item:hover,
    .menu-item.active {
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
    }

    .menu-item i {
        font-size: 20px;
        min-width: 30px;
    }

    .menu-item span {
        margin-left: 12px;
        white-space: nowrap;
    }

.menu-section {
    padding: 20px 20px 10px;
    font-size: 12px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: background 0.2s;
}

    .toggle-btn:active {
        background: rgba(255, 255, 255, 0.2);
    }

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    transition: margin-left 0.3s ease;
    padding-right: max(0, var(--safe-area-inset-right));
    padding-bottom: max(0, var(--safe-area-inset-bottom));
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 max(24px, calc(24px + var(--safe-area-inset-left))) 0 24px;
    z-index: 100;
}

.menu-toggle {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
    display: none;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .menu-toggle:active {
        opacity: 0.7;
    }

.clinic-info {
    flex: 1;
    margin-left: 20px;
    overflow: hidden;
}

.clinic-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 15px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.notification-btn {
    position: relative;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

    .notification-btn:active {
        opacity: 0.7;
    }

    .notification-btn .badge {
        position: absolute;
        top: 4px;
        right: 4px;
        background: var(--danger-color);
        color: #fff;
        font-size: 10px;
        padding: 2px 6px;
        border-radius: 10px;
    }

.user-dropdown {
    position: relative;
}

.user-dropdown:hover .dropdown-menu {
    display: block;
}

.user-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius);
    min-height: 44px;
    transition: background 0.2s;
}

    .user-btn:hover,
    .user-btn:active {
        background: var(--bg-secondary);
    }

    .user-btn .avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        object-fit: cover;
    }

    .user-btn .user-name {
        font-weight: 500;
        color: var(--text-primary);
        font-size: 14px;
    }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 8px 0;
    z-index: 1000;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    text-decoration: none;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    min-height: 44px;
    font-size: 14px;
    transition: background 0.2s;
}

    .dropdown-item:hover,
    .dropdown-item:active {
        background: var(--bg-secondary);
    }

/* Page Content */
.page-content {
    padding: 24px;
    padding-left: max(24px, calc(24px + var(--safe-area-inset-left)));
    padding-right: max(24px, calc(24px + var(--safe-area-inset-right)));
    padding-bottom: max(24px, calc(24px + var(--safe-area-inset-bottom)));
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

    .page-header h1 {
        font-size: 28px;
        font-weight: 700;
        margin-bottom: 4px;
        color: var(--text-primary);
    }

/* Cards */
.card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

    .card-header h5 {
        font-size: 16px;
        font-weight: 600;
        margin: 0;
    }

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    padding: 20px;
    border-radius: var(--radius-lg);
    color: #fff;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s;
}

    .stat-card:active {
        transform: scale(0.98);
    }

    .stat-card.bg-primary {
        background: linear-gradient(135deg, #4f46e5, #7c3aed);
    }

    .stat-card.bg-success {
        background: linear-gradient(135deg, #22c55e, #16a34a);
    }

    .stat-card.bg-info {
        background: linear-gradient(135deg, #3b82f6, #2563eb);
    }

    .stat-card.bg-warning {
        background: linear-gradient(135deg, #f59e0b, #d97706);
    }

.stat-icon {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.stat-content h3 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.stat-content p {
    font-size: 14px;
    opacity: 0.9;
    margin: 0;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
}

    .table th,
    .table td {
        padding: 12px 16px;
        text-align: left;
        border-bottom: 1px solid var(--border-color);
        font-size: 14px;
    }

    .table th {
        background: var(--bg-secondary);
        font-weight: 600;
        font-size: 13px;
        text-transform: uppercase;
        color: var(--text-secondary);
    }

    .table tbody tr {
        transition: background 0.2s;
    }

.table-hover tbody tr:hover {
    background: var(--bg-secondary);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

    .form-group label {
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
        font-size: 15px;
        color: var(--text-primary);
    }

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}

    .form-control:focus,
    input[type="text"]:focus,
    input[type="email"]:focus,
    input[type="password"]:focus,
    input[type="date"]:focus,
    input[type="time"]:focus,
    input[type="number"]:focus,
    select:focus,
    textarea:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    }

.form-check {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    min-height: 44px;
}

.form-check-input {
    width: 20px;
    height: 20px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s;
}

    .form-check-input:checked {
        background: var(--primary-color);
        border-color: var(--primary-color);
    }

.form-check-label {
    cursor: pointer;
    font-size: 15px;
    user-select: none;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

/* Buttons */
.btn,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    min-height: 44px;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary,
button.btn-primary {
    background: var(--primary-color);
    color: #fff;
}

    .btn-primary:hover,
    .btn-primary:active,
    button.btn-primary:hover,
    button.btn-primary:active {
        background: var(--primary-hover);
    }

    .btn-primary:active,
    button.btn-primary:active {
        transform: scale(0.98);
    }

.btn-secondary,
button.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

    .btn-secondary:hover,
    .btn-secondary:active,
    button.btn-secondary:hover,
    button.btn-secondary:active {
        background: var(--border-color);
    }

    .btn-secondary:active,
    button.btn-secondary:active {
        transform: scale(0.98);
    }

.btn-success {
    background: var(--success-color);
    color: #fff;
}

    .btn-success:hover,
    .btn-success:active {
        background: #16a34a;
    }

.btn-danger {
    background: var(--danger-color);
    color: #fff;
}

    .btn-danger:hover,
    .btn-danger:active {
        background: #dc2626;
    }

.btn-outline-primary {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

    .btn-outline-primary:hover,
    .btn-outline-primary:active {
        background: var(--primary-color);
        color: #fff;
    }

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    min-height: 36px;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 16px;
    min-height: 52px;
}

.btn-block,
.w-100 {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 0;
}

    .btn-group .btn {
        border-radius: 0;
    }

        .btn-group .btn:first-child {
            border-radius: var(--radius) 0 0 var(--radius);
        }

        .btn-group .btn:last-child {
            border-radius: 0 var(--radius) var(--radius) 0;
        }

/* Tabs */
.nav-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 24px;
    margin: 0 -24px;
}

.nav-tabs .nav-link {
    padding: 12px 16px;
    min-height: 44px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

    .nav-tabs .nav-link:hover {
        color: var(--text-primary);
        background: rgba(0, 0, 0, 0.02);
    }

    .nav-tabs .nav-link.active {
        color: var(--primary-color);
        border-bottom-color: var(--primary-color);
        background: none;
    }

    .nav-tabs .nav-link:active {
        opacity: 0.8;
    }

.tab-content {
    padding: 20px 0;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 20px;
    white-space: nowrap;
}

.badge.bg-primary {
    background: var(--primary-color);
    color: #fff;
}

.badge.bg-success {
    background: var(--success-color);
    color: #fff;
}

.badge.bg-warning {
    background: var(--warning-color);
    color: #fff;
}

.badge.bg-danger {
    background: var(--danger-color);
    color: #fff;
}

.badge.bg-info {
    background: var(--info-color);
    color: #fff;
}

.badge.bg-secondary {
    background: var(--secondary-color);
    color: #fff;
}

/* Search Box */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

    .search-box i {
        position: absolute;
        left: 14px;
        color: var(--text-muted);
        pointer-events: none;
    }

    .search-box input {
        padding-left: 40px;
        min-width: 300px;
    }

/* Info List */
.info-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

    .info-item:last-child {
        border-bottom: none;
    }

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
        --sidebar-collapsed-width: 0px;
    }

    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1050;
        max-width: 80vw;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100%;
    }

    .menu-toggle {
        display: flex !important;
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        display: none;
    }

    .sidebar-overlay.show {
        display: block;
    }
    
    .clinic-info {
        margin-left: 10px;
    }
    
    .clinic-name {
        font-size: 14px;
    }
    
    .user-name {
        display: none;
    }
    
    .page-content {
        padding: 16px;
        padding-left: max(16px, calc(16px + var(--safe-area-inset-left)));
        padding-right: max(16px, calc(16px + var(--safe-area-inset-right)));
        padding-bottom: max(16px, calc(16px + var(--safe-area-inset-bottom)));
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header h1 {
        font-size: 24px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-actions {
        justify-content: stretch;
    }

        .form-actions .btn {
            flex: 1;
        }

    .btn {
        width: 100%;
    }

    .nav-tabs {
        padding: 0 16px;
        margin: 0 -16px;
    }

    .search-box input {
        min-width: 200px;
    }
}

@media (max-width: 480px) {
    :root {
        --radius: 6px;
        --radius-lg: 10px;
    }

    .page-content {
        padding: 12px;
        padding-left: max(12px, calc(12px + var(--safe-area-inset-left)));
        padding-right: max(12px, calc(12px + var(--safe-area-inset-right)));
        padding-bottom: max(12px, calc(12px + var(--safe-area-inset-bottom)));
    }

    .card {
        border-radius: var(--radius-lg);
    }

    .btn,
    button {
        min-height: 48px;
        padding: 12px 20px;
        font-size: 16px;
    }

    .btn-sm {
        min-height: 40px;
    }

    .topbar {
        height: 56px;
    }

    .page-header h1 {
        font-size: 22px;
    }

    .form-group label {
        font-size: 14px;
    }

    .form-control,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="time"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px;
        padding: 12px 14px;
        min-height: 48px;
    }

    .nav-tabs .nav-link {
        padding: 12px 14px;
        font-size: 14px;
    }
}

/* Custom Additions for Prescription Page */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    text-align: center;
    background: var(--bg-secondary);
    transition: all 0.2s;
    cursor: pointer;
}

    .upload-zone:hover {
        border-color: var(--primary-color);
        background: rgba(79, 70, 229, 0.05);
    }

    .upload-zone:active {
        transform: scale(0.98);
    }

.upload-icon {
    font-size: 32px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.timeline {
    position: relative;
    padding-left: 24px;
    border-left: 2px solid var(--border-color);
}

.timeline-item {
    position: relative;
    margin-bottom: 24px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -29px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary-color);
    border: 2px solid #fff;
}

.timeline-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.timeline-content {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: var(--radius);
}

.medication-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s;
}

    .medication-card:hover,
    .medication-card:active {
        border-color: var(--primary-color);
        box-shadow: var(--shadow);
    }

.patient-context-card {
    background: linear-gradient(135deg, var(--primary-color), var(--info-color));
    color: white;
}

.patient-context-card .text-muted {
    color: rgba(255, 255, 255, 0.8) !important;
}

.scrollable-history {
    max-height: 600px;
    overflow-y: auto;
    padding-right: 8px;
    -webkit-overflow-scrolling: touch;
}

/* Custom Scrollbar */
.scrollable-history::-webkit-scrollbar {
    width: 6px;
}

.scrollable-history::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

.scrollable-history::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.scrollable-history::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Print Styles */
@media print {
    .sidebar,
    .topbar,
    .no-print,
    .btn,
    .form-actions {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .page-content {
        padding: 0 !important;
    }

    .card {
        border: none !important;
        box-shadow: none !important;
    }

    .container-fluid {
        padding: 0 !important;
    }

    body {
        background-color: white !important;
    }
    
    .prescription-paper {
        border: 1px solid #ddd !important;
    }
}
