/* ======================================================================
   سامانه اتوماسیون جامع دامداری - طراحی حرفه‌ای بازطراحی شده
   Design System: Organic Biophilic | Font: Vazirmatn + Fira Code
   ====================================================================== */

/* Close Modal Button (utility class) */
.btn-close-modal {
    cursor: pointer;
    transition: var(--transition);
}
.btn-close-modal.btn-icon:hover {
    background: var(--danger-light);
    border-color: var(--danger);
    color: var(--danger);
}

/* Textarea input */
textarea.input-field {
    resize: vertical;
    min-height: 80px;
    line-height: 1.6;
}

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;600&family=Vazirmatn:wght@300;400;500;700;900&display=swap');

/* --- CSS Variables / Design Tokens --- */
:root {
    --primary: #16a34a;
    --primary-dark: #15803d;
    --primary-light: #dcfce7;
    --primary-subtle: #f0fdf4;
    
    --accent: #d97706;
    --accent-light: #fef3c7;
    
    --danger: #dc2626;
    --danger-light: #fee2e2;
    
    --blue: #0ea5e9;
    --blue-light: #e0f2fe;
    
    --purple: #7c3aed;
    --purple-light: #ede9fe;

    --bg-base: #f8faf8;
    --bg-card: #ffffff;
    --bg-sidebar: #fafdf9;
    --bg-header: #ffffff;
    
    --text-primary: #1a2e1a;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.12), 0 4px 8px rgba(0,0,0,0.06);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --transition: all 0.2s ease;
    --sidebar-width: 300px;
    --header-height: 64px;
}

/* --- Base Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: 'Vazirmatn', 'Tahoma', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    direction: rtl;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 { font-weight: 700; line-height: 1.3; color: var(--text-primary); }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 0.9375rem; }

.en-num { font-family: 'Fira Code', monospace; font-size: 0.875em; letter-spacing: 0.03em; }

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

/* --- Header & AI Navigation Bar --- */
.main-header {
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { 
    width: 40px; height: 40px; 
    color: var(--primary); 
    background: var(--primary-light); 
    border-radius: var(--radius-sm);
    padding: 7px;
    flex-shrink: 0;
}
.brand-text h1 { 
    font-size: 1.15rem; 
    font-weight: 800; 
    color: var(--primary-dark);
}
.brand-text .sub-text { 
    font-size: 0.75rem; 
    color: var(--text-muted); 
    display: block;
    margin-top: 2px;
}

/* AI Operation Toolbar */
.ai-operation-toolbar {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.ai-nav-chip {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 10px;
    font-weight: 700;
}

.ai-nav-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* --- Main Workspace --- */
.workspace {
    display: flex;
    gap: 0;
    margin-top: 0;
    min-height: calc(100vh - 120px);
}

/* --- Sidebar --- */
.sidebar-console {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: calc(100vh - 120px);
    position: sticky;
    top: 0;
    padding: 16px;
    gap: 12px;
}

.sidebar-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.card-title {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-base);
}

/* --- Dashboard Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    padding: 0;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 8px;
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    cursor: default;
}
.stat-box:nth-child(odd) { border-left: none; }
.stat-box:nth-last-child(-n+2) { border-bottom: none; }

.stat-num {
    font-size: 1.875rem;
    font-weight: 900;
    font-family: 'Fira Code', monospace;
    color: var(--primary);
    line-height: 1;
}
.stat-box.alert-box .stat-num { color: var(--danger); }
.stat-box.success-box .stat-num { color: var(--primary); }
.stat-box.primary-box .stat-num { color: var(--blue); }

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 4px;
    font-weight: 500;
}

/* --- Quick Actions --- */
.vertical-actions { padding: 10px; display: flex; flex-direction: column; gap: 6px; }

/* --- Cow List --- */
.search-list-wrapper { display: flex; flex-direction: column; }
.mini-search {
    margin: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8125rem;
    outline: none;
    transition: var(--transition);
    background: var(--bg-base);
}
.mini-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1); }

.cows-list { list-style: none; max-height: 400px; overflow-y: auto; }
.cow-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    gap: 8px;
}
.cow-item:last-child { border-bottom: none; }
.cow-item:hover { background: var(--primary-subtle); }
.cow-item.active { background: var(--primary-light); border-right: 3px solid var(--primary); }

.cow-item-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.cow-item-tag { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cow-item-name { font-size: 0.8125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-list-message { text-align: center; color: var(--text-muted); font-size: 0.8125rem; padding: 20px; }

/* --- Main Content Area --- */
.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: calc(100vh - var(--header-height));
}

/* --- Search Bar Card --- */
.search-bar-card {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    flex-shrink: 0;
}
.search-form-layout { display: flex; gap: 10px; align-items: center; }
.search-input-container { position: relative; flex: 1; }
.search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}
.search-field {
    width: 100%;
    padding: 10px 40px 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    background: var(--bg-base);
    outline: none;
    transition: var(--transition);
}
.search-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.1); }

/* --- Empty State --- */
.empty-state-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 60px 40px;
    text-align: center;
    gap: 16px;
}
.empty-state-icon { width: 80px; height: 80px; color: var(--border-strong); }
.empty-state-card h2 { color: var(--text-secondary); font-size: 1.25rem; }
.empty-state-card p { color: var(--text-muted); max-width: 440px; font-size: 0.875rem; line-height: 1.7; }
.empty-quick-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }

/* --- Cow Detail Container --- */
.cow-detail-container { display: flex; flex-direction: column; flex: 1; }

/* --- Cow Profile Header --- */
.cow-profile-header-card {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    padding: 20px 24px 0;
    color: white;
    flex-shrink: 0;
}

.profile-header-main {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.profile-avatar-placeholder {
    width: 60px;
    height: 60px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
}
.profile-avatar-placeholder .big-icon { width: 32px; height: 32px; color: white; }

.profile-name-details { flex: 1; min-width: 0; }
.name-status-row { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.cow-title { 
    font-size: 1.375rem; 
    font-weight: 900; 
    color: white; 
    margin: 0;
}
.meta-row { 
    display: flex; 
    gap: 8px; 
    flex-wrap: wrap; 
    align-items: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.8);
}
.meta-divider { color: rgba(255,255,255,0.4); }

.profile-header-actions { 
    display: flex; 
    gap: 8px; 
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* --- Withdrawal Warning Bar --- */
.withdrawal-warning-bar {
    background: rgba(220, 38, 38, 0.9);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    flex-shrink: 0;
}
.withdrawal-warning-bar svg { width: 16px; height: 16px; flex-shrink: 0; }

/* --- Quick Event Chips Bar --- */
.quick-event-bar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.quick-event-bar::-webkit-scrollbar { height: 3px; }
.quick-event-bar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
.bar-title { 
    font-size: 0.75rem; 
    font-weight: 700; 
    color: var(--text-muted);
    margin-bottom: 8px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.event-chips-wrapper { 
    display: flex; 
    gap: 6px; 
    align-items: center;
    padding-bottom: 2px;
}
.chip-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: white;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    flex-shrink: 0;
}
.chip-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.chip-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

/* --- TABS SYSTEM --- */
.tabs-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-base);
}

.tabs-nav {
    background: var(--bg-card);
    border-bottom: 2px solid var(--border);
    display: flex;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 0 16px;
}
.tabs-nav::-webkit-scrollbar { display: none; }

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 14px 16px 13px;
    border: none;
    background: transparent;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: var(--transition);
    flex-shrink: 0;
}
.tab-btn:hover { color: var(--primary); background: var(--primary-subtle); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.tab-btn.active { color: var(--primary-dark); border-bottom-color: var(--primary); font-weight: 700; }
.tab-btn svg { width: 14px; height: 14px; }

.tabs-content { flex: 1; overflow-y: auto; }
.tab-panel { display: none; padding: 20px 24px; }
.tab-panel.active { display: block; }

/* --- Info Grid (Profile Tab) --- */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
}
.info-item {
    background: var(--bg-card);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.info-item label { 
    font-size: 0.7rem; 
    font-weight: 700; 
    color: var(--text-muted); 
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.info-value { 
    font-size: 0.9rem; 
    font-weight: 600; 
    color: var(--text-primary); 
}
.info-value.highlight-value { color: var(--primary-dark); font-size: 1rem; }

/* --- Data Tables --- */
.table-container { 
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.table-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-base);
}
.section-title { 
    font-size: 0.875rem; 
    font-weight: 700; 
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-title svg { width: 15px; height: 15px; color: var(--primary); }
.section-title.alert-text { color: var(--danger); }
.section-title.alert-text svg { color: var(--danger); }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}
.data-table thead th {
    background: var(--bg-base);
    padding: 10px 12px;
    text-align: right;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table tbody td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--primary-subtle); }
.data-table .text-center { text-align: center; color: var(--text-muted); padding: 24px; }
.text-success { color: var(--primary); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-muted { color: var(--text-muted); }

/* --- Summary Cards Row (for tabs) --- */
.summary-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: var(--shadow-sm);
}
.summary-card .s-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.summary-card .s-value { font-size: 1.125rem; font-weight: 800; color: var(--text-primary); }
.summary-card.success .s-value { color: var(--primary-dark); }
.summary-card.warning .s-value { color: var(--accent); }
.summary-card.danger .s-value { color: var(--danger); }
.summary-card.info .s-value { color: var(--blue); }

/* --- CMT 4-Quarter Udder Grid --- */
.cartier-grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 8px 0;
}
.cartier-box {
    background: var(--bg-base);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cartier-title { 
    font-size: 0.75rem; 
    font-weight: 700; 
    color: var(--text-secondary);
    line-height: 1.3;
}

/* --- Hoof Selection Grid --- */
.hoof-checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: var(--bg-base);
    padding: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.hoof-box { margin-top: 10px; }
.checkbox-label, .radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    border: 1px solid transparent;
}
.checkbox-label:hover, .radio-label:hover { background: var(--primary-light); border-color: var(--primary); }
.radio-options-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- Media Gallery --- */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    padding: 16px;
}
.media-card {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
}
.media-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.media-img { width: 100%; height: 120px; object-fit: cover; display: block; }
.media-info { padding: 8px 10px; }
.media-type { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; font-weight: 700; display: block; }
.media-desc { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }
.empty-gallery-msg { text-align: center; color: var(--text-muted); padding: 30px; font-size: 0.875rem; }
.media-actions-bar { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.media-actions-bar h4 { font-size: 0.875rem; color: var(--text-secondary); }
.cursor-pointer { cursor: pointer; }

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    line-height: 1;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn.btn-block { width: 100%; justify-content: center; }

.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(22,163,74,0.3); transform: translateY(-1px); }

.btn-secondary { background: white; color: var(--text-secondary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-base); border-color: var(--primary); color: var(--primary); }

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

.btn-warning-outline { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }
.btn-warning-outline:hover { background: var(--accent); color: white; }

.btn-danger-outline { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger); color: white; }

.btn-icon {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: white;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    flex-shrink: 0;
}
.btn-icon:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-subtle); }
.btn-icon svg { width: 16px; height: 16px; }

.btn-search { padding: 10px 20px; }

/* --- BADGES --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge-text { font-size: 0.7rem; }

.badge-active { background: var(--primary-light); color: var(--primary-dark); }
.badge-sick { background: var(--danger-light); color: var(--danger); }
.badge-pregnant { background: var(--blue-light); color: #0369a1; }
.badge-sold { background: var(--accent-light); color: var(--accent); }
.badge-connected { background: var(--primary-light); color: var(--primary-dark); }
.badge-demo { background: var(--accent-light); color: var(--accent); }
.badge-warning { background: var(--danger-light); color: var(--danger); font-size: 0.75rem; padding: 6px 12px; border-radius: var(--radius-sm); font-weight: 700; }

/* --- FORM ELEMENTS --- */
.input-field {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-base);
    outline: none;
    transition: var(--transition);
}
.input-field:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.12); }
.input-field.ltr { direction: ltr; text-align: left; }
.input-field.en-num { font-family: 'Fira Code', monospace; }

select.input-field { cursor: pointer; appearance: auto; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.7875rem; font-weight: 600; color: var(--text-secondary); }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.form-section-group { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; background: var(--bg-base); }
.form-section-title { 
    font-size: 0.8125rem; 
    font-weight: 700; 
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.form-desc { color: var(--text-muted); font-size: 0.8125rem; margin-bottom: 14px; background: var(--primary-subtle); padding: 8px 12px; border-radius: var(--radius-sm); border-right: 3px solid var(--primary); }

/* --- MODALS --- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.active { display: flex !important; z-index: 99999 !important; animation: modal-in 0.2s ease; }
@keyframes modal-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}
.modal-content.large-modal { max-width: 760px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}
.modal-header h3 { font-size: 1rem; font-weight: 800; color: var(--text-primary); }

.modal form { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-base);
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
}
.right-actions { display: flex; gap: 8px; margin-right: auto; }
.settings-actions-group { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* --- PWA Banner --- */
.pwa-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-dark);
    color: white;
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 200;
    box-shadow: var(--shadow-lg);
    max-width: 90%;
}
.pwa-banner-content { display: flex; align-items: center; gap: 16px; }
.pwa-banner-text { font-size: 0.875rem; font-weight: 500; }
.pwa-banner-actions { display: flex; gap: 8px; align-items: center; }

/* --- Utilities --- */
.hidden { display: none !important; }
.mt-6 { margin-top: 20px; }
.mt-4 { margin-top: 14px; }
.mt-3 { margin-top: 10px; }

.icon { width: 20px; height: 20px; flex-shrink: 0; }

/* --- Responsive --- */
@media (max-width: 900px) {
    :root { --sidebar-width: 260px; }
    .brand-text .sub-text { display: none; }
}
@media (max-width: 700px) {
    .workspace { flex-direction: column; }
    .sidebar-console { 
        width: 100%; 
        height: auto; 
        position: static;
        max-height: 280px;
    }
    .main-content { height: auto; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr 1fr; }
}

/* ==========================================
   GATEKEEPER LOGIN & AUTH STYLES
   ========================================== */

/* Full-Screen Gatekeeper Login Screen */
.login-gate-screen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at 50% 30%, #1e293b 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 20px;
}

.login-card {
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 420px;
    padding: 36px 32px;
    animation: authPopIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes authPopIn {
    from { opacity: 0; transform: scale(0.95) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

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

.login-card-header .brand-logo-badge {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    color: #ffffff;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    box-shadow: 0 10px 20px -5px rgba(21, 128, 61, 0.45);
}

.login-card-header .brand-logo-badge svg {
    width: 32px;
    height: 32px;
}

.login-card-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.4;
    margin-bottom: 8px;
}

.login-card-header .login-subtitle {
    font-size: 0.825rem;
    color: #64748b;
    line-height: 1.5;
}

.login-card-form .form-group {
    margin-bottom: 18px;
}

.login-card-form label {
    display: block;
    font-size: 0.825rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

.btn-login-submit {
    padding: 13px !important;
    font-size: 0.95rem !important;
    font-weight: 700 !important;
    margin-top: 10px;
    border-radius: 10px !important;
    box-shadow: 0 4px 12px rgba(21, 128, 61, 0.35);
}

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

.auth-logo-badge {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #15803d 0%, #166534 100%);
    color: white;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    box-shadow: 0 8px 16px -4px rgba(21, 128, 61, 0.4);
}

.auth-logo-badge svg {
    width: 28px;
    height: 28px;
}

.auth-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 6px;
}

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

.alert-box-auth {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.825rem;
    margin-bottom: 16px;
    font-weight: 500;
}

.auth-demo-credentials {
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    padding: 12px;
    margin-top: 18px;
}

.auth-demo-credentials .demo-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 8px;
}

.auth-demo-credentials .demo-chips {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chip-user {
    display: block;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.75rem;
    color: #334155;
    cursor: pointer;
    font-family: 'Fira Code', 'Vazirmatn', monospace;
    transition: all 0.15s ease;
}

.chip-user:hover {
    background: #f0fdf4;
    border-color: #86efac;
    color: #15803d;
    font-weight: 600;
}

/* Header User Profile Widget */
.user-profile-widget {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
}

.user-profile-widget .user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.user-profile-widget .user-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

.user-profile-widget .user-role-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
}

/* User Management Modal Layout */
.user-mgmt-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 24px;
    margin-top: 16px;
}

@media (max-width: 768px) {
    .user-mgmt-layout {
        grid-template-columns: 1fr;
    }
}

.user-create-form-section {
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 18px;
    border-radius: var(--radius-md);
}

.user-create-form-section h4,
.users-list-section h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 14px;
    padding-bottom: 6px;
    border-bottom: 1.5px solid var(--border);
}

/* ==========================================
   RAYKA AI SPECIALIST STYLES
   ========================================== */

/* Sparkle AI Action Button */
.btn-ai-sparkle {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    font-weight: 700 !important;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.45) !important;
    position: relative;
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.btn-ai-sparkle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.6) !important;
    background: linear-gradient(135deg, #6d28d9 0%, #4338ca 100%) !important;
}

/* AI Modal Header */
.ai-modal-header {
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    border-bottom: 1px solid #ddd6fe;
    padding: 16px 24px;
}

.ai-brand-title {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ai-glow-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    color: white;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.4);
}

.ai-loading-container {
    text-align: center;
    padding: 40px 20px;
}

.ai-pulse-ring {
    width: 56px;
    height: 56px;
    margin: 0 auto;
    border-radius: 50%;
    border: 4px solid #ede9fe;
    border-top-color: #7c3aed;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Floating AI Copilot Button */
.floating-ai-fab {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 30px;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Vazirmatn', sans-serif;
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(124, 58, 237, 0.5);
    z-index: 9000;
    transition: all 0.25s ease;
    animation: floatGlow 3s ease-in-out infinite alternate;
}

@keyframes floatGlow {
    0% { transform: translateY(0); box-shadow: 0 10px 25px rgba(124, 58, 237, 0.5); }
    100% { transform: translateY(-4px); box-shadow: 0 14px 30px rgba(124, 58, 237, 0.7); }
}

.floating-ai-fab:hover {
    transform: scale(1.05) translateY(-3px);
}

/* Floating Rayka Chat Drawer */
.rayka-chat-drawer {
    position: fixed;
    bottom: 80px;
    left: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    z-index: 9001;
    overflow: hidden;
    animation: authPopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-drawer-header {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-brand-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-dot-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px #4ade80;
}

.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
}

.chat-msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.chat-msg.user-msg {
    flex-direction: row-reverse;
}

.msg-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.85rem;
    line-height: 1.6;
    word-break: break-word;
}

.ai-msg .msg-bubble {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #e2e8f0;
    border-top-right-radius: 2px;
}

.user-msg .msg-bubble {
    background: #7c3aed;
    color: #ffffff;
    border-top-left-radius: 2px;
}

.chat-quick-prompts {
    padding: 8px 12px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
}

.quick-chip {
    display: inline-block;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.quick-chip:hover {
    background: #ede9fe;
    color: #7c3aed;
    font-weight: 600;
}

.chat-input-row {
    padding: 10px 12px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input-row .input-field {
    font-size: 0.85rem;
    padding: 8px 12px;
}

/* --- AI Actionable Recommendation Cards --- */
.ai-action-recommendations-wrapper {
    margin-top: 20px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
}

.ai-action-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.ai-action-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.ai-action-card:hover {
    border-color: #86efac;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(21, 128, 61, 0.1);
}

.ai-action-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 8px;
}

.ai-action-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-impact-badge {
    font-size: 0.725rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.impact-green {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.impact-amber {
    background: #fef9c3;
    color: #854d0e;
    border: 1px solid #fef08a;
}

.impact-blue {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.impact-purple {
    background: #faf5ff;
    color: #6b21a8;
    border: 1px solid #e9d5ff;
}

.ai-action-desc {
    font-size: 0.8rem;
    color: #475569;
    line-height: 1.5;
    margin-bottom: 12px;
}

.btn-apply-optimization {
    width: 100%;
    padding: 7px 12px;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.btn-apply-green {
    background: #15803d;
    color: white;
}
.btn-apply-green:hover {
    background: #166534;
}

.btn-apply-amber {
    background: #a16207;
    color: white;
}
.btn-apply-amber:hover {
    background: #854d0e;
}

.btn-apply-blue {
    background: #2563eb;
    color: white;
}
.btn-apply-blue:hover {
    background: #1d4ed8;
}

.btn-apply-purple {
    background: #7c3aed;
    color: white;
}
.btn-apply-purple:hover {
    background: #6d28d9;
}

/* Feed Management Modal Styling */
#modal-feed-management .modal-content {
    max-width: 1100px;
    width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#modal-feed-management .modal-body {
    flex: 1;
    overflow-y: auto;
    max-height: calc(90vh - 75px);
    padding: 20px;
}


/* Isolated demo environment marker */
#demo-environment-banner {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 10050;
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 8px 18px;
    color: #4a2d00;
    background: linear-gradient(90deg, #fff3bf, #ffe08a, #fff3bf);
    border-bottom: 1px solid #e8bd43;
    box-shadow: 0 3px 14px rgba(88, 60, 0, 0.18);
    font-size: 13px;
    text-align: center;
}

#demo-environment-banner strong {
    white-space: nowrap;
    color: #7a4300;
}

#demo-environment-banner .demo-guide-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 28px;
    padding: 4px 12px;
    color: #fff;
    background: #8a5200;
    border: 1px solid #704100;
    border-radius: 8px;
    font-weight: 700;
    text-decoration: none;
    transition: transform 0.15s ease, background 0.15s ease;
}

#demo-environment-banner .demo-guide-link:hover {
    color: #fff;
    background: #653b00;
    transform: translateY(-1px);
}

#demo-environment-banner.hidden {
    display: none !important;
}

body.demo-mode #app-container {
    padding-top: 42px;
    box-sizing: border-box;
}

@media (max-width: 720px) {
    #demo-environment-banner {
        align-items: flex-start;
        gap: 4px;
        flex-direction: column;
        font-size: 11px;
    }
    #demo-environment-banner .demo-guide-link {
        width: 100%;
    }
    body.demo-mode #app-container {
        padding-top: 58px;
    }
}
