:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --success: #0f9d58;
    --success-light: #e6f4ea;
    --danger: #d93025;
    --danger-light: #fce8e6;
    --warning: #f9ab00;
    --warning-light: #fef7e0;
    --text: #202124;
    --text-secondary: #5f6368;
    --bg: #f8f9fa;
    --white: #ffffff;
    --border: #dadce0;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --radius: 8px;
    --sidebar-width: 260px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ===== Auth Pages ===== */
.auth-page {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 16px;
}

.auth-container {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px 24px;
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-header h1 {
    font-size: 1.3rem;
    color: var(--primary);
    margin-bottom: 6px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.auth-form .form-group {
    margin-bottom: 14px;
}

.auth-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.85rem;
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.auth-footer {
    text-align: center;
    margin-top: 16px;
    font-size: 0.85rem;
}

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 40px;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover {
    background: #0b8043;
}

.btn-success:active {
    transform: scale(0.97);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover {
    background: #c5221f;
}

.btn-danger:active {
    transform: scale(0.97);
}

.btn-warning {
    background: var(--warning);
    color: var(--text);
}

.btn-warning:active {
    transform: scale(0.97);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
    min-height: 32px;
}

.btn-block {
    display: flex;
    width: 100%;
}

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 0.88rem;
    word-wrap: break-word;
}

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #f5c6cb;
}

.alert-success {
    background: var(--success-light);
    color: var(--success);
    border: 1px solid #c3e6cb;
}

.alert-info {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid #b6d4fe;
}

/* ===== Layout ===== */
.layout {
    display: flex;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #1a237e 0%, #283593 100%);
    color: var(--white);
    padding: 0;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s ease;
    -webkit-overflow-scrolling: touch;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 1rem;
    margin-bottom: 3px;
}

.sidebar-header p {
    font-size: 0.75rem;
    opacity: 0.7;
}

.sidebar-nav {
    padding: 8px 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 16px;
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.9rem;
    border-right: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255,255,255,0.1);
    color: var(--white);
    border-right-color: var(--white);
}

.sidebar-nav a .icon {
    font-size: 1.15rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.1);
    position: absolute;
    bottom: 0;
    right: 0;
    left: 0;
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    padding: 8px 0;
    font-size: 0.85rem;
}

.sidebar-footer a:hover {
    color: var(--white);
}

/* ===== Mobile Menu Toggle ===== */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1100;
    background: var(--primary);
    color: var(--white);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* ===== Main Content ===== */
.main-content {
    margin-right: var(--sidebar-width);
    padding: 24px 28px;
    flex: 1;
    width: 100%;
    min-width: 0;
}

/* ===== Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.page-header h1 {
    font-size: 1.4rem;
    color: var(--text);
}

/* ===== Cards Grid ===== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.2s;
}

.stat-card:active {
    transform: scale(0.98);
}

.stat-card .stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card .stat-icon.blue {
    background: var(--primary-light);
    color: var(--primary);
}

.stat-card .stat-icon.green {
    background: var(--success-light);
    color: var(--success);
}

.stat-card .stat-icon.orange {
    background: var(--warning-light);
    color: var(--warning);
}

.stat-card .stat-icon.red {
    background: var(--danger-light);
    color: var(--danger);
}

.stat-card .stat-info h3 {
    font-size: 1.4rem;
    margin-bottom: 2px;
}

.stat-card .stat-info p {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* ===== Table ===== */
.table-container {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 24px;
}

.table-container .table-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.table-container .table-header h2 {
    font-size: 1rem;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}

th, td {
    padding: 11px 14px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

th {
    background: var(--bg);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    position: sticky;
    top: 0;
}

tr:hover {
    background: #f5f7fa;
}

/* ===== Mobile Table Cards ===== */
.table-cards {
    display: none;
}

/* ===== Forms ===== */
.form-container {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.form-container h2 {
    font-size: 1rem;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235f6368' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
    padding-left: 30px;
}

.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);
}

/* ===== Badge ===== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
}

.badge-admin {
    background: #fce8e6;
    color: var(--danger);
}

.badge-doctor {
    background: var(--primary-light);
    color: var(--primary);
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal h2 {
    margin-bottom: 14px;
    font-size: 1.1rem;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* ===== Actions ===== */
.actions {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

/* ===== Report Specific ===== */
.report-summary {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.report-summary .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    gap: 12px;
}

.report-summary .summary-row:last-child {
    border-bottom: none;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary);
}

.report-filters {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.report-filters .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 140px;
}

.empty-state {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-secondary);
}

.empty-state .icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.service-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: var(--bg);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.service-item select,
.service-item input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
}

.service-item .btn-remove {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

/* ===== Report Title ===== */
.report-title {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 3px solid var(--primary);
}

.report-title h1 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.report-title p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.report-section {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.report-section h2 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    color: var(--primary);
}

/* ===== Print ===== */
@media print {
    .sidebar, .no-print, .btn, .actions, .menu-toggle, .sidebar-overlay {
        display: none !important;
    }
    .main-content {
        margin: 0 !important;
        padding: 8px !important;
    }
    .table-container, .report-section, .form-container, .report-summary {
        box-shadow: none !important;
        break-inside: avoid;
    }
    body {
        background: white;
        font-size: 12px;
    }
    table {
        min-width: auto;
    }
    th, td {
        padding: 6px 8px;
        font-size: 0.78rem;
    }
}

/* ===========================
   RESPONSIVE - LARGE TABLETS
   =========================== */
@media (max-width: 1024px) {
    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===========================
   RESPONSIVE - TABLETS
   =========================== */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
    }

    .sidebar {
        transform: translateX(100%);
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-right: 0;
        padding: 60px 16px 20px;
    }

    .layout {
        flex-direction: column;
    }

    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
        gap: 10px;
    }

    .stat-card .stat-icon {
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }

    .stat-card .stat-info h3 {
        font-size: 1.15rem;
    }

    .stat-card .stat-info p {
        font-size: 0.75rem;
    }

    .page-header h1 {
        font-size: 1.2rem;
    }

    .table-scroll {
        margin: 0 -16px;
        padding: 0 16px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .report-filters {
        flex-direction: column;
        gap: 10px;
    }

    .report-filters .form-group {
        min-width: 100%;
    }

    .report-filters .btn {
        width: 100%;
    }

    .report-summary .summary-row {
        font-size: 0.85rem;
    }

    .service-item {
        flex-direction: column;
        align-items: stretch;
    }

    .service-item select,
    .service-item input {
        width: 100%;
    }

    .service-item .btn-remove {
        align-self: flex-end;
    }

    .modal {
        margin: 8px;
        padding: 16px;
        max-height: 85vh;
    }

    .auth-container {
        padding: 24px 18px;
    }

    .auth-header h1 {
        font-size: 1.15rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    table {
        min-width: 400px;
    }

    th, td {
        padding: 8px 10px;
        font-size: 0.78rem;
        white-space: nowrap;
    }

    .pagination {
        gap: 4px !important;
    }

    .pagination .btn-sm {
        padding: 6px 10px;
        font-size: 0.72rem;
    }
}

/* ===========================
   RESPONSIVE - SMALL TABLETS / LARGE PHONES
   =========================== */
@media (max-width: 576px) {
    .main-content {
        padding: 56px 12px 16px;
    }

    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 12px 10px;
        gap: 8px;
        border-radius: 6px;
    }

    .stat-card .stat-icon {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
        border-radius: 10px;
    }

    .stat-card .stat-info h3 {
        font-size: 1rem;
    }

    .stat-card .stat-info p {
        font-size: 0.7rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .page-header h1 {
        font-size: 1.1rem;
    }

    .form-container {
        padding: 16px 12px;
    }

    .form-container h2 {
        font-size: 0.95rem;
    }

    .table-container .table-header {
        padding: 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .table-container .table-header h2 {
        font-size: 0.9rem;
    }

    table {
        min-width: 350px;
    }

    th, td {
        padding: 7px 8px;
        font-size: 0.72rem;
    }

    .btn {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .btn-sm {
        padding: 5px 10px;
        font-size: 0.73rem;
    }

    .actions {
        gap: 4px;
    }

    .report-summary {
        padding: 14px;
    }

    .report-summary .summary-row {
        font-size: 0.82rem;
        padding: 8px 0;
    }

    .report-title h1 {
        font-size: 1rem;
    }

    .report-title p {
        font-size: 0.78rem;
    }

    .auth-page {
        padding: 12px;
    }

    .auth-container {
        padding: 20px 16px;
    }

    .badge {
        padding: 2px 6px;
        font-size: 0.65rem;
    }
}

/* ===========================
   RESPONSIVE - PHONES
   =========================== */
@media (max-width: 400px) {
    .main-content {
        padding: 52px 10px 14px;
    }

    .cards-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .stat-card {
        padding: 10px 8px;
        gap: 6px;
    }

    .stat-card .stat-icon {
        width: 34px;
        height: 34px;
        font-size: 1rem;
        border-radius: 8px;
    }

    .stat-card .stat-info h3 {
        font-size: 0.9rem;
    }

    .stat-card .stat-info p {
        font-size: 0.65rem;
    }

    .page-header h1 {
        font-size: 1rem;
    }

    .actions {
        flex-direction: column;
    }

    .actions .btn {
        width: 100%;
    }

    .sidebar {
        width: 260px;
    }
}

/* ===========================
   RESPONSIVE - VERY SMALL PHONES
   =========================== */
@media (max-width: 340px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
}

/* ===========================
   LANDSCAPE PHONE
   =========================== */
@media (max-height: 500px) and (orientation: landscape) {
    .auth-page {
        align-items: flex-start;
        padding-top: 20px;
    }

    .auth-container {
        max-height: 95vh;
        overflow-y: auto;
    }
}

/* ===========================
   TABLET LANDSCAPE
   =========================== */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    .cards-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===========================
   TOUCH DEVICE OPTIMIZATIONS
   =========================== */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
    }

    .btn-sm {
        min-height: 36px;
    }

    .sidebar-nav a {
        padding: 14px 16px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        min-height: 44px;
    }

    .service-item .btn-remove {
        width: 36px;
        height: 36px;
    }
}

/* ===========================
   SAFE AREA (Notch devices)
   =========================== */
@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar-footer {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .main-content {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* ===========================
   DARK MODE SUPPORT (optional)
   =========================== */
@media (prefers-color-scheme: dark) {
    /* Light theme stays default - system uses light mode */
}

/* ===========================
   REDUCED MOTION
   =========================== */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* ===========================
   HORIZONTAL SCROLL FIX
   =========================== */
.table-container {
    max-width: 100%;
}

.table-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
}

/* ===========================
   FOCUS VISIBLE (Accessibility)
   =========================== */
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

/* ===========================
   LOADING STATE
   =========================== */
.btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

/* ===========================
   STICKY HEADER ON SCROLL
   =========================== */
.table-container .table-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--white);
}