/* ===== Shared CSS Variables & Base (TrustFlow Apps) ===== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-input: #1a1a25;
    --border-color: rgba(255,255,255,0.06);
    --border-hover: rgba(255,255,255,0.12);
    --text-primary: #f0f0f5;
    --text-secondary: #8b8b9e;
    --text-muted: #5a5a6e;
    --accent-indigo: #6366f1;
    --accent-cyan: #06b6d4;
    --accent-purple: #8b5cf6;
    --accent-pink: #d946ef;
    --accent-green: #10b981;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #06b6d4 100%);
    --gradient-secondary: linear-gradient(135deg, #8b5cf6 0%, #d946ef 100%);
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Space Grotesk', 'Inter', sans-serif;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --topbar-height: 64px;
}

/* Light mode overrides */
body.light-mode {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f0f5;
    --bg-input: #f0f0f5;
    --border-color: rgba(0,0,0,0.08);
    --border-hover: rgba(0,0,0,0.15);
    --text-primary: #1a1a2e;
    --text-secondary: #64648c;
    --text-muted: #9999b0;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 8px 32px rgba(0,0,0,0.1);
    --shadow-lg: 0 16px 64px rgba(0,0,0,0.12);
}

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

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

body.rtl {
    direction: rtl;
    font-family: 'Tajawal', 'Inter', sans-serif;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ===== Modal System ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.95);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

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

.modal-header h3 {
    font-family: var(--font-display);
    font-size: 1.15rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

.modal-body { padding: 24px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* ===== Form Controls ===== */
.form-group {
    margin-bottom: 16px;
}

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

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all var(--transition-fast);
}

.form-control:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.form-control::placeholder { color: var(--text-muted); }

select.form-control {
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238b8b9e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

body.rtl select.form-control {
    background-position: left 12px center;
    padding-right: 14px;
    padding-left: 36px;
}

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    cursor: pointer;
    border: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-primary);
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(99,102,241,0.3);
}

.btn-secondary {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--border-hover);
    background: rgba(255,255,255,0.08);
}

.btn-danger {
    background: rgba(239,68,68,0.15);
    color: var(--accent-red);
}

.btn-danger:hover {
    background: rgba(239,68,68,0.25);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-icon {
    width: 36px; height: 36px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }

/* ===== Data Tables ===== */
.data-table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

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

.data-table thead {
    background: rgba(255,255,255,0.03);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

body.rtl .data-table th,
body.rtl .data-table td {
    text-align: right;
}

.data-table td {
    padding: 12px 16px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: rgba(255,255,255,0.03);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ===== Status Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-open { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.badge-progress { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.badge-closed { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.badge-hold { background: rgba(139,92,246,0.15); color: var(--accent-purple); }
.badge-appealed { background: rgba(217,70,239,0.15); color: var(--accent-pink); }
.badge-pending { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.badge-review { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.badge-approved { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.badge-rejected { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-high { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.badge-medium { background: rgba(245,158,11,0.15); color: var(--accent-amber); }
.badge-low { background: rgba(16,185,129,0.15); color: var(--accent-green); }

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

body.rtl .toast-container {
    right: auto;
    left: 20px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    min-width: 300px;
    animation: toastIn 0.3s ease-out;
}

.toast.toast-success { border-left: 3px solid var(--accent-green); }
.toast.toast-error { border-left: 3px solid var(--accent-red); }
.toast.toast-info { border-left: 3px solid var(--accent-blue); }

body.rtl .toast.toast-success,
body.rtl .toast.toast-error,
body.rtl .toast.toast-info {
    border-left: none;
    border-right: 3px solid var(--accent-green);
}
body.rtl .toast.toast-error { border-right-color: var(--accent-red); }
body.rtl .toast.toast-info { border-right-color: var(--accent-blue); }

.toast-message { font-size: 0.875rem; flex: 1; }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ===== Command Bar ===== */
.command-bar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 9000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
}

.command-bar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.command-bar {
    width: 560px;
    background: var(--bg-card);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform: translateY(-10px) scale(0.98);
    transition: transform var(--transition-fast);
}

.command-bar-overlay.active .command-bar {
    transform: translateY(0) scale(1);
}

.command-bar-input {
    width: 100%;
    padding: 16px 20px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
}

.command-bar-results {
    max-height: 320px;
    overflow-y: auto;
    padding: 8px;
}

.command-bar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.command-bar-item:hover,
.command-bar-item.active {
    background: rgba(99,102,241,0.1);
}

.command-bar-item-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
}

.command-bar-item-text {
    flex: 1;
}

.command-bar-item-text span {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
}

.command-bar-item-text small {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.command-bar-shortcut {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 2px 6px;
    background: rgba(255,255,255,0.05);
    border-radius: 4px;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    margin: 0 auto 16px;
    opacity: 0.3;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.875rem;
    margin-bottom: 20px;
}

/* ===== Filter Bar ===== */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    flex-wrap: wrap;
}

.filter-bar .form-control {
    width: auto;
    min-width: 150px;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.filter-bar .search-input {
    flex: 1;
    min-width: 200px;
}

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

.page-header h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
}

.page-header-actions {
    display: flex;
    gap: 8px;
}

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

.stat-card {
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.stat-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
}

.stat-card-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.stat-card-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-card-trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
}

.stat-card-trend.up { color: var(--accent-green); }
.stat-card-trend.down { color: var(--accent-red); }

/* ===== Kanban Board ===== */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    min-height: 400px;
}

.kanban-column {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    min-height: 300px;
}

.kanban-column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.kanban-column-title {
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.kanban-count {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: rgba(255,255,255,0.05);
    border-radius: 100px;
    color: var(--text-muted);
}

.kanban-cards {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 100px;
}

.kanban-cards.drag-over {
    background: rgba(99,102,241,0.05);
    border-radius: var(--radius-sm);
}

.kanban-card {
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: all var(--transition-fast);
}

.kanban-card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
}

.kanban-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.kanban-card-title {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.kanban-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Chat Interface (AI) ===== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 120px);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-message {
    display: flex;
    gap: 12px;
    max-width: 80%;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

body.rtl .chat-message.user {
    flex-direction: row;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-message.assistant .chat-avatar {
    background: var(--gradient-primary);
}

.chat-message.user .chat-avatar {
    background: rgba(255,255,255,0.1);
}

.chat-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    line-height: 1.6;
}

.chat-message.assistant .chat-bubble {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
}

.chat-message.user .chat-bubble {
    background: var(--accent-indigo);
    color: #fff;
}

.chat-input-bar {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.chat-input {
    flex: 1;
    padding: 10px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
}

.chat-input:focus {
    border-color: var(--accent-indigo);
}

/* ===== Notification Panel ===== */
.notification-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 360px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 4000;
    display: none;
    max-height: 400px;
    overflow-y: auto;
}

body.rtl .notification-panel {
    right: auto;
    left: 0;
}

.notification-panel.active { display: block; }

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

.notification-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
    cursor: pointer;
}

.notification-item:hover { background: rgba(255,255,255,0.03); }
.notification-item.unread { background: rgba(99,102,241,0.05); }

.notification-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-indigo);
    flex-shrink: 0;
    margin-top: 6px;
}

.notification-item:not(.unread) .notification-dot { opacity: 0; }

.notification-text { flex: 1; }
.notification-text p { font-size: 0.85rem; }
.notification-text small { font-size: 0.75rem; color: var(--text-muted); }

/* ===== Trial Banner ===== */
.trial-banner {
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(6,182,212,0.15));
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: var(--radius-sm);
    margin: 12px;
    text-align: center;
}

.trial-banner-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.trial-banner-days {
    font-size: 1.2rem;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--accent-indigo);
}

/* ===== Lock Screen ===== */
.lock-screen {
    position: fixed;
    inset: 0;
    background: rgba(10,10,15,0.95);
    backdrop-filter: blur(10px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.lock-screen-content {
    max-width: 440px;
    padding: 40px;
}

.lock-screen h2 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    margin-bottom: 12px;
}

.lock-screen p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* ===== Print Styles ===== */
@media print {
    .sidebar, .topbar, .command-bar-overlay, .toast-container, .notification-panel,
    .modal-overlay, .trial-banner, .no-print, .btn { display: none !important; }
    body {
        background: #fff !important;
        color: #000 !important;
    }
    .main-content { margin: 0 !important; padding: 20px !important; }
    .data-table th, .data-table td { color: #000 !important; border-color: #ddd !important; }
    .stat-card { border: 1px solid #ddd !important; background: #fff !important; }
    .badge { border: 1px solid #999 !important; }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .kanban-board { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .stat-cards { grid-template-columns: 1fr; }
    .kanban-board { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-control { width: 100%; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-card-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

::selection { background: rgba(99,102,241,0.3); color: var(--text-primary); }
