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

:root {
    --bg: #1a1a1c;
    --surface: #242426;
    --surface-2: #2e2e30;
    --surface-3: #38383a;
    --border: #3c3c3e;
    --border-light: #4c4c4e;
    --text: #ececee;
    --text-soft: #c4c4c6;
    --text-muted: #848486;
    --text-faint: #646466;
    --accent: #f59e0b;
    --accent-light: #fbbf24;
    --accent-dark: #d97706;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --green: #10b981;
    --red: #ef4444;
    --orange: #f59e0b;
    --radius: 14px;
    --radius-sm: 10px;
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text-soft);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.sidebar {
    background: var(--surface);
    border-left: 2px solid var(--accent);
    box-shadow: -2px 0 16px var(--accent-glow);
}

.card, .stat-card {
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.stat-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.3); }

.modal-box {
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.login-card {
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

.product-card:hover { box-shadow: 0 10px 30px rgba(0,0,0,0.3); }

::-webkit-scrollbar-track { background: var(--surface-2); }
::-webkit-scrollbar-thumb { background: var(--border-light); }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text-soft);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

.sidebar {
    width: 240px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 24px 16px;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 100;
}

.sidebar-brand {
    font-size: 1.25em;
    font-weight: 800;
    color: var(--accent-light);
    padding: 8px 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-brand .logo {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    color: #1a1a1c;
    font-weight: 900;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.92em;
    transition: all var(--transition);
    text-decoration: none;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--accent-light);
    border-color: var(--border);
}
.nav-item.active {
    background: linear-gradient(90deg, var(--accent-glow), transparent);
    color: var(--accent-light);
    border-right: 3px solid var(--accent);
}

.nav-item .icon { width: 20px; text-align: center; font-size: 1.1em; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }

/* ===== Language Selector ===== */
.lang-selector { position: relative; margin: 8px 0; }

.lang-current {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid var(--border);
}

.lang-current:hover { border-color: var(--border-light); }

.lang-flag { font-size: 1.3em; line-height: 1; }
.lang-flag-img { width: 22px; height: 16px; object-fit: cover; border-radius: 2px; display: block; }

/* ===== Mini Language Selector (Login) ===== */
.lang-selector-mini .lang-current-mini {
    padding: 6px;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
}
.lang-selector-mini .lang-current-mini:hover { border-color: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.lang-flag-mini { width: 24px; height: 18px; object-fit: cover; border-radius: 3px; display: block; }
.lang-selector-mini .lang-dropdown {
    top: 100%;
    bottom: auto;
    right: 0;
    left: auto;
    min-width: 160px;
}
/* في الـ sidebar تفتح للأعلى */
.sidebar-footer .lang-selector-mini .lang-dropdown {
    bottom: 100%;
    top: auto;
}
.lang-name { flex: 1; font-size: 0.88em; font-weight: 600; color: var(--text-soft); }
.lang-arrow { font-size: 0.7em; color: var(--text-muted); transition: transform var(--transition); }
.lang-selector:hover .lang-arrow { transform: rotate(180deg); }

.lang-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--surface-3);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    overflow: hidden;
    display: none;
    z-index: 200;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.3);
}

.lang-selector.open .lang-dropdown { display: block; }

.lang-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    color: var(--text-soft);
    text-decoration: none;
    font-size: 0.88em;
    font-weight: 600;
    transition: all var(--transition);
    border-bottom: 1px solid var(--border);
}

.lang-option:last-child { border-bottom: none; }
.lang-option:hover { background: var(--surface-2); color: var(--text); }
.lang-option.active { color: var(--accent-light); background: var(--accent-glow); }
.lang-option .lang-flag { font-size: 1.2em; }
.lang-option .lang-flag-img { width: 22px; height: 16px; object-fit: cover; border-radius: 2px; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.sidebar-user .info { flex: 1; min-width: 0; }

.sidebar-user .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #1a1a1c;
    font-size: 0.85em;
}

.sidebar-user .info { flex: 1; }
.sidebar-user .name { font-size: 0.88em; font-weight: 600; color: var(--text); }
.sidebar-user .role { font-size: 0.75em; color: var(--text-muted); }

/* ===== Main ===== */
.main { flex: 1; margin-right: 240px; padding: 28px 32px; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 { font-size: 1.7em; font-weight: 800; color: var(--text); }
.page-header .subtitle { color: var(--text-muted); font-size: 0.9em; margin-top: 4px; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.9em;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    font-family: inherit;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #1a1a1c;
    border: 1px solid var(--accent);
    box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 6px 20px var(--accent-glow); }

.btn-ghost {
    background: var(--surface);
    color: var(--text-soft);
    border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--border-light); color: var(--text); background: var(--surface-2); }

.btn-success { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-warning { background: var(--orange); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8em; border-radius: 8px; }

/* ===== Stats ===== */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    position: relative;
    overflow: hidden;
    transition: all var(--transition);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    opacity: 0;
    transition: opacity var(--transition);
}

.stat-card:hover { border-color: var(--accent); transform: translateY(-3px); }
.stat-card:hover::before { opacity: 1; }

.stat-card .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    margin-bottom: 14px;
    box-shadow: 0 0 10px var(--accent-glow);
}

.stat-card .stat-value { font-size: 2.2em; font-weight: 800; color: var(--accent-light); line-height: 1; }
.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.82em;
    margin-top: 6px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.card-header h2 { font-size: 1.1em; font-weight: 700; color: var(--accent-light); }

.card-body { padding: 22px; }

/* ===== Tables ===== */
table { width: 100%; border-collapse: collapse; }

th {
    padding: 14px 22px;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    background: var(--surface-2);
    white-space: nowrap;
}

td { padding: 16px 22px; border-top: 1px solid var(--border); font-size: 0.92em; }
tr:hover td { background: var(--surface-2); }

/* RTL/LTR table alignment */
html[dir="rtl"] th, html[dir="rtl"] td { text-align: right; }
html[dir="ltr"] th, html[dir="ltr"] td { text-align: left; }

/* Table responsive wrapper */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }

/* Table row hover accent */
tbody tr { transition: background var(--transition); }
tbody tr:hover td { border-top-color: var(--accent); }

/* Table cell styling for logs */
.log-table td { vertical-align: middle; }
.log-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.log-table th:last-child { border-radius: 0 var(--radius-sm) 0 0; }

/* Product ID monospace */
.product-id { font-family: 'Courier New', monospace; font-size: 0.88em; color: var(--accent-light); }

/* Date formatting */
.log-date { color: var(--text-muted); font-size: 0.85em; white-space: nowrap; }

.user-cell { display: flex; align-items: center; gap: 10px; }

.user-cell .avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #1a1a1c;
    font-size: 0.8em;
}

.subscription-editor,
.subscription-actions {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.plan-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.plan-picker label {
    cursor: pointer;
    user-select: none;
}

.plan-picker input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.plan-picker span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    min-width: 94px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.84em;
    font-weight: 700;
    transition: all var(--transition);
}

.plan-picker input:checked + span {
    border-color: var(--accent);
    background: linear-gradient(180deg, var(--accent-light), var(--accent));
    color: #1a1a1c;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.plan-select {
    min-width: 135px;
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font-weight: 700;
}

.subscription-actions .btn {
    min-height: 36px;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78em;
    font-weight: 700;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }

.badge-green { background: rgba(34, 197, 94, 0.1); color: var(--green); }
.badge-green::before { background: var(--green); }

.badge-red { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.badge-red::before { background: var(--red); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

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

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

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.92em;
    font-family: inherit;
    transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.form-control {
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.92em;
    font-family: inherit;
    transition: border-color var(--transition);
}

.form-group input::placeholder, .form-group textarea::placeholder { color: var(--text-muted); }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 0.9em;
    border: 1px solid transparent;
}

.alert-error { background: rgba(239, 68, 68, 0.1); color: #f87171; border-color: rgba(239, 68, 68, 0.2); }
.alert-success { background: rgba(34, 197, 94, 0.1); color: #4ade80; border-color: rgba(34, 197, 94, 0.2); }
.alert-info { background: var(--accent-glow); color: var(--accent-light); border-color: rgba(245, 158, 11, 0.2); }

.hint { color: var(--text-muted); font-size: 0.85em; margin-top: 12px; }

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

/* ===== Login ===== */
.login-box {
    max-width: 420px;
    margin: 80px auto;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 36px;
    box-shadow: 0 0 40px var(--accent-glow), 0 20px 60px rgba(0,0,0,0.4);
}

.login-card h1 {
    color: var(--accent-light);
    font-size: 1.5em;
    margin-bottom: 24px;
    text-align: center;
}

.login-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4em;
    color: #1a1a1c;
    font-weight: 900;
    margin: 0 auto 20px;
    box-shadow: 0 4px 16px var(--accent-glow);
}

/* ===== Empty ===== */
.empty { text-align: center; padding: 50px 20px; color: var(--text-muted); font-size: 0.95em; }

/* ===== Products Grid ===== */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 12px;
}

.product-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all var(--transition);
}

.product-card:hover {
    border-color: var(--accent);
    transform: translateY(-4px);
    box-shadow: 0 0 24px var(--accent-glow), 0 10px 30px rgba(0,0,0,0.3);
}

.product-thumb {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--border);
}

.product-noimg {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85em;
}

.product-name { font-size: 0.95em; font-weight: 700; color: var(--text); min-height: 2.4em; overflow: hidden; }
.product-alias { font-size: 0.82em; color: var(--accent-light); font-style: italic; font-weight: 600; }
.product-actions { display: flex; gap: 5px; justify-content: center; flex-wrap: wrap; margin-top: auto; }

/* ===== Product Preview ===== */
.product-preview-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface-2);
    padding: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.product-thumb-lg {
    width: 100px;
    height: 100px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--border);
}

.product-name-lg { flex: 1; font-weight: 700; color: var(--text); min-width: 150px; font-size: 1.05em; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.15s ease;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    width: 100%;
    max-width: 460px;
    padding: 28px;
    box-shadow: 0 0 40px var(--accent-glow), 0 20px 60px rgba(0,0,0,0.5);
    animation: slideUp 0.15s ease-out;
}

.modal-box h2 {
    color: var(--accent-light);
    font-size: 1.2em;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.modal-box-lg { max-width: 1000px; max-height: 90vh; overflow-y: auto; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

::selection { background: var(--accent-glow); color: var(--accent-light); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar { width: 60px; padding: 16px 8px; }
    .sidebar-brand span, .nav-item span:not(.icon), .sidebar-user .info { display: none; }
    .main { margin-right: 60px; padding: 20px 16px; }
}
