/* ===== Variables ===== */
:root {
    --primary: #2196F3;
    --primary-dark: #1976D2;
    --secondary: #757575;
    --success: #4CAF50;
    --warning: #FF9800;
    --danger: #F44336;
    --critical: #9C27B0;
    
    --bg-main: #F5F5F5;
    --bg-panel: #FFFFFF;
    --bg-input: #FAFAFA;
    
    --text-primary: #212121;
    --text-secondary: #757575;
    
    --border-color: #E0E0E0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    
    --font-family: 'Cairo', 'Tahoma', 'Arial', sans-serif;
    --transition: all 0.3s ease;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    direction: rtl;
    text-align: right;
    unicode-bidi: plaintext;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

/* ===== Utilities ===== */
.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #616161; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #388E3C; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #F57C00; }

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

.btn-critical { background: var(--critical); color: white; }
.btn-critical:hover { background: #7B1FA2; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.7rem; }
.btn-lg { padding: 0.875rem 1.75rem; font-size: 1rem; }
.btn-full { width: 100%; }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
    white-space: nowrap;
}

.badge-success { background: #E8F5E9; color: var(--success); }
.badge-warning { background: #FFF3E0; color: var(--warning); }
.badge-danger { background: #FFEBEE; color: var(--danger); }
.badge-info { background: #E3F2FD; color: var(--primary); }
.badge-secondary { background: #EEEEEE; color: var(--secondary); }
.badge-admin { background: #E1BEE7; color: var(--critical); }

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-input);
    transition: var(--transition);
    direction: rtl;
    text-align: right;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-checkbox input {
    width: auto;
}

.error-message {
    padding: 0.75rem 1rem;
    background: #FFEBEE;
    color: var(--danger);
    border-radius: 6px;
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* ===== Login Page ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header .logo {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}

.login-header h1 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
}

.login-form {
    margin-bottom: 1.5rem;
}

.login-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* ===== App Layout ===== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: var(--primary);
    color: white;
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1800px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-brand .logo {
    font-size: 2rem;
}

.header-brand h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 1rem;
    overflow: hidden;
}

.panels-container {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 1rem;
    height: calc(100vh - 140px);
    max-width: 1800px;
    margin: 0 auto;
}

/* ===== Panels ===== */
.panel {
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: #FAFAFA;
}

.panel-header h2 {
    font-size: 1rem;
    color: var(--text-primary);
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
}

.panel-body {
    flex: 1;
    overflow: auto;
    padding: 1rem;
}

.panel-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background: #FAFAFA;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

/* ===== Input Panel ===== */
.input-textarea {
    width: 100%;
    height: 100%;
    min-height: 300px;
    padding: 1rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    resize: none;
    direction: rtl;
    text-align: right;
    line-height: 1.8;
}

.input-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== Analysis Panel ===== */
.summary-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.analysis-text {
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 2;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.placeholder-text {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem;
}

/* ===== Highlights ===== */
.highlight-critical {
    background: #E1BEE7;
    color: var(--critical);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-weight: 600;
}

.highlight-violation {
    background: #FFCCCC;
    color: var(--danger);
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-weight: 600;
}

.highlight-acknowledgment {
    background: #FFE4B5;
    color: #CC6600;
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-weight: 600;
}

/* ===== Tabs ===== */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.tab-btn:hover {
    background: #F5F5F5;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: #E3F2FD;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===== Violations List ===== */
.violations-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.violation-card,
.acknowledgment-card,
.ignored-card {
    background: #F9F9F9;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.violation-card.violation-critical {
    background: #F3E5F5;
    border-color: var(--critical);
}

.violation-header,
.ack-header,
.ignored-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid var(--border-color);
}

.violation-number,
.ack-number {
    font-weight: 600;
    font-size: 0.875rem;
}

.violation-card.violation-critical .violation-number {
    color: var(--critical);
}

.violation-body,
.ack-body,
.ignored-body {
    padding: 0.75rem 1rem;
}

.violation-body p,
.ack-body p,
.ignored-body p {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.6;
}

.violation-body p:last-child,
.ack-body p:last-child {
    margin-bottom: 0;
}

.violation-footer,
.ignored-footer {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.02);
}

.no-ignore-text {
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 500;
}

.success-message {
    text-align: center;
    padding: 2rem;
    color: var(--success);
    font-weight: 500;
}

.critical-warning {
    background: #F3E5F5;
    border: 2px solid var(--critical);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--critical);
    font-weight: 600;
}

.critical-warning span {
    font-size: 1.5rem;
}

/* ===== Status Bar ===== */
.status-bar {
    padding: 0.5rem 1.5rem;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    text-align: left;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-content.modal-lg {
    max-width: 700px;
}

.modal-content.modal-critical {
    border: 3px solid var(--critical);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-header.critical-header {
    background: #F3E5F5;
    color: var(--critical);
}

.critical-icon {
    font-size: 2rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: #FAFAFA;
}

.critical-message {
    text-align: center;
    line-height: 1.8;
}

.critical-message .quote {
    font-style: italic;
    color: var(--critical);
    font-weight: 500;
    padding: 0.5rem 1rem;
    background: #F3E5F5;
    border-radius: 6px;
    display: inline-block;
    margin: 0.5rem 0;
}

/* ===== Legal Reference ===== */
.legal-reference p {
    margin-bottom: 0.75rem;
}

.legal-explanation {
    margin-top: 1rem;
    padding: 1rem;
    background: #F5F5F5;
    border-radius: 8px;
}

.legal-explanation p {
    margin-top: 0.5rem;
}

/* ===== Admin Page ===== */
.admin-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.admin-table-container {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.admin-table th {
    background: #FAFAFA;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.admin-table td {
    font-size: 0.875rem;
}

.admin-table tr:hover {
    background: #F5F5F5;
}

.actions-cell {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-start;
}

.loading-cell,
.empty-cell,
.error-cell {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem !important;
}

.error-cell {
    color: var(--danger);
}

/* ===== Error Page ===== */
.error-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.error-card {
    text-align: center;
    background: white;
    padding: 3rem;
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.error-card h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.error-card p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* ===== Responsive ===== */
@media (max-width: 1200px) {
    .panels-container {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
    }
    
    .panel-input {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .panels-container {
        grid-template-columns: 1fr;
        height: auto;
    }
    
    .panel {
        min-height: 400px;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .admin-table-container {
        overflow-x: auto;
    }
    
    .actions-cell {
        flex-direction: column;
    }
}
