/* =====================================================
   Alwaled Cafe - Main Styles (RTL, responsive)
   ===================================================== */

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

html {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: 'Cairo', 'Tajawal', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    direction: rtl;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 100% 0%, rgba(142, 182, 155, 0.35), transparent 45%),
        radial-gradient(circle at 0% 100%, rgba(35, 83, 71, 0.15), transparent 40%);
    background-attachment: fixed;
}

.main { min-width: 0; overflow-x: hidden; }
.content { min-width: 0; }

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

h1, h2, h3, h4, h5, h6 {
    color: var(--text-heading);
    font-weight: 700;
    margin: 0 0 0.75rem;
}

img { max-width: 100%; height: auto; display: block; }

/* ============= App Shell ============= */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
    transition: grid-template-columns var(--transition);
}

.app.sidebar-collapsed {
    grid-template-columns: var(--sidebar-w-sm) 1fr;
}

/* ============= Sidebar ============= */
.sidebar {
    background: linear-gradient(180deg, var(--c-darkest) 0%, var(--c-dark) 100%);
    color: var(--text-on-dark);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    z-index: 40;
    box-shadow: -4px 0 24px rgba(5, 31, 32, 0.15);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px 20px;
    border-bottom: 1px solid rgba(218, 241, 222, 0.08);
    margin-bottom: 16px;
}

.sidebar-brand .brand-logo {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--c-light), var(--c-mid));
    display: grid;
    place-items: center;
    color: var(--c-darkest);
    font-weight: 800;
    font-size: 20px;
    flex-shrink: 0;
}

.sidebar-brand .brand-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.sidebar-brand .brand-name {
    color: var(--c-lightest);
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
}

.sidebar-brand .brand-tag {
    color: var(--c-light);
    font-size: 0.75rem;
    opacity: 0.85;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
}

.sidebar-nav-title {
    color: var(--c-light);
    opacity: 0.7;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 14px 12px 6px;
    margin: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--c-lightest);
    font-size: 0.92rem;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}

.sidebar-nav a .nav-icon {
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    opacity: 0.85;
}

.sidebar-nav a:hover {
    background: rgba(218, 241, 222, 0.06);
    color: #fff;
}

.sidebar-nav a.active {
    background: linear-gradient(135deg, var(--c-mid), var(--c-mid-dark));
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(218, 241, 222, 0.15);
}

.sidebar-nav a .badge {
    margin-inline-start: auto;
    background: var(--c-light);
    color: var(--c-darkest);
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 999px;
    font-weight: 700;
}

.sidebar-footer {
    padding-top: 16px;
    border-top: 1px solid rgba(218, 241, 222, 0.08);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(218, 241, 222, 0.04);
    border-radius: var(--radius-sm);
}

.sidebar-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-light), var(--c-mid));
    color: var(--c-darkest);
    display: grid;
    place-items: center;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-user .user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.sidebar-user .user-name {
    color: var(--c-lightest);
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    color: var(--c-light);
    font-size: 0.72rem;
}

/* Collapsed sidebar */
.sidebar-collapsed .sidebar-brand .brand-info,
.sidebar-collapsed .sidebar-nav a span:not(.badge):not(.nav-icon),
.sidebar-collapsed .sidebar-nav-title,
.sidebar-collapsed .sidebar-user .user-info {
    display: none;
}
.sidebar-collapsed .sidebar-nav a { justify-content: center; }
.sidebar-collapsed .sidebar { padding: 20px 8px; }

/* ============= Main Area ============= */
.main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--header-h);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 30;
    box-shadow: var(--shadow-sm);
}

.topbar-toggle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background var(--transition);
}
.topbar-toggle:hover { background: var(--bg-hover); }

.topbar-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-heading);
    margin: 0;
}

.topbar-spacer { flex-grow: 1; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-btn {
    background: var(--bg-card-alt);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}
.icon-btn:hover {
    background: var(--accent-soft);
    border-color: var(--border-strong);
}
.icon-btn .dot {
    position: absolute;
    top: 8px;
    inset-inline-end: 8px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border: 2px solid #fff;
    border-radius: 50%;
}

/* Notifications dropdown */
.notif-wrapper { position: relative; }
.notif-badge {
    position: absolute;
    top: 4px;
    inset-inline-end: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 800;
    display: grid;
    place-items: center;
    line-height: 1;
}
.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-end: 0;
    width: 360px;
    max-width: calc(100vw - 20px);
    max-height: 480px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: notifPop 160ms ease-out;
}
.notif-dropdown[hidden] { display: none; }
@keyframes notifPop {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.notif-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--c-darkest), var(--c-mid-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.notif-header strong { color: #fff; }
.notif-body {
    overflow-y: auto;
    max-height: 400px;
}
.notif-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-secondary);
}
.notif-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--transition);
}
.notif-item:hover { background: var(--bg-hover); }
.notif-item:last-child { border-bottom: none; }
.notif-item.notif-danger {
    border-inline-start: 3px solid var(--danger);
    background: rgba(201, 59, 59, 0.04);
}
.notif-item.notif-warning {
    border-inline-start: 3px solid var(--warning);
    background: rgba(210, 154, 43, 0.05);
}
.notif-item-icon {
    font-size: 1.3rem;
    line-height: 1;
    flex-shrink: 0;
}
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title {
    font-weight: 700;
    font-size: 0.88rem;
    color: var(--text-heading);
    margin-bottom: 2px;
}
.notif-item-text {
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

.content {
    padding: 24px;
    flex-grow: 1;
    max-width: 100%;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-header .page-title {
    font-size: 1.5rem;
    margin: 0;
}
.page-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 4px 0 0;
}

/* ============= Cards ============= */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}
.card-title {
    margin: 0 0 14px;
    font-size: 1rem;
    color: var(--text-heading);
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-card.dark {
    background: linear-gradient(135deg, var(--c-darkest), var(--c-mid-dark));
    color: var(--text-on-dark);
    border-color: var(--c-mid-dark);
}
.stat-card.dark .stat-label { color: var(--c-light); }
.stat-card.dark .stat-value { color: #fff; }

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}
.stat-card .stat-value {
    color: var(--text-heading);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.stat-card .stat-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.stat-card .stat-hint.up { color: var(--success); }
.stat-card .stat-hint.down { color: var(--danger); }

/* Grid */
.grid {
    display: grid;
    gap: 18px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ============= Buttons ============= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--c-mid-dark);
    color: #fff;
}
.btn-primary:hover { background: var(--c-dark); color: #fff; }

.btn-dark {
    background: var(--c-darkest);
    color: var(--c-lightest);
}
.btn-dark:hover { background: var(--c-dark); }

.btn-light {
    background: var(--c-lightest);
    color: var(--c-darkest);
    border-color: var(--c-light);
}
.btn-light:hover { background: var(--c-light); }

.btn-outline {
    background: transparent;
    color: var(--c-mid-dark);
    border-color: var(--c-mid);
}
.btn-outline:hover { background: var(--accent-soft); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a52e2e; }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-lg { padding: 14px 28px; font-size: 1.05rem; }

/* ============= Forms ============= */
.form-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9rem;
}

.form-control {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
}
.form-control:focus {
    outline: none;
    border-color: var(--c-mid);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-control::placeholder { color: var(--text-muted); }

/* Force English (ASCII) digits and LTR direction for numeric-style inputs everywhere.
   Cairo font auto-switches to Arabic-Indic digits under RTL context via OpenType 'locl'
   (localized forms). Using a Latin-only font stack for these inputs prevents that. */
input[type="number"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="tel"],
input[type="email"],
input[type="url"],
code {
    direction: ltr !important;
    text-align: end;
    font-family: 'Segoe UI', 'Roboto', 'Arial', system-ui, sans-serif !important;
    font-feature-settings: "lnum" 1, "tnum" 1, "locl" 0;
    font-variant-numeric: lining-nums tabular-nums;
    -webkit-locale: "en-US";
    unicode-bidi: plaintext;
}
code { text-align: start; }

.form-hint { color: var(--text-muted); font-size: 0.8rem; }
.form-error { color: var(--danger); font-size: 0.85rem; }

/* ============= Alerts ============= */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    border: 1px solid transparent;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-success { background: #e8f5ec; color: #1c6a48; border-color: #b9dfc8; }
.alert-error   { background: #fbe9e9; color: #8a2a2a; border-color: #f0c4c4; }
.alert-warning { background: #fdf3e0; color: #8a5a1a; border-color: #f0dcb2; }
.alert-info    { background: #e6f0f7; color: #1c5378; border-color: #b8d4e6; }

/* ============= Badges ============= */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--accent-soft);
    color: var(--c-mid-dark);
}
.badge-success { background: #dcefe4; color: #1c6a48; }
.badge-warning { background: #fbeacf; color: #7a4b12; }
.badge-danger  { background: #fbdcdc; color: #8a2a2a; }
.badge-dark    { background: var(--c-darkest); color: var(--c-lightest); }

/* ============= Tables ============= */
.table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: var(--shadow-sm);
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
.table th, .table td {
    padding: 12px 14px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}
.table th {
    background: var(--bg-card-alt);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.82rem;
    text-transform: none;
}
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: none; }

/* ============= Login Page ============= */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--c-darkest) 0%, var(--c-mid-dark) 55%, var(--c-mid) 100%);
    position: relative;
    overflow: hidden;
}
.auth-shell::before, .auth-shell::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    z-index: 0;
}
.auth-shell::before {
    width: 400px; height: 400px;
    background: var(--c-light);
    top: -100px; inset-inline-end: -100px;
}
.auth-shell::after {
    width: 500px; height: 500px;
    background: var(--c-mid);
    bottom: -150px; inset-inline-start: -150px;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    max-width: 420px;
    width: 100%;
    position: relative;
    z-index: 1;
}

.auth-brand {
    text-align: center;
    margin-bottom: 28px;
}
.auth-brand .brand-logo {
    width: 64px; height: 64px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--c-darkest), var(--c-mid));
    color: var(--c-lightest);
    display: grid;
    place-items: center;
    font-size: 28px;
    font-weight: 800;
    margin: 0 auto 12px;
    box-shadow: 0 8px 20px rgba(5, 31, 32, 0.2);
}
.auth-brand h1 {
    margin: 0 0 4px;
    font-size: 1.4rem;
}
.auth-brand p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* ============= Utilities ============= */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-end { text-align: left; } /* logical: since RTL, text-end = visually left */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.flex-between { justify-content: space-between; }
.flex-center { justify-content: center; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 14px; }
.gap-3 { gap: 20px; }

/* ============= Mobile menu overlay ============= */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 31, 32, 0.55);
    z-index: 35;
    backdrop-filter: blur(2px);
}

/* ============= Responsive ============= */
@media (max-width: 1200px) {
    .grid-4 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 992px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    :root { --sidebar-w: 280px; }
    .app {
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: fixed;
        top: 0;
        inset-inline-end: -100%;
        width: var(--sidebar-w);
        transition: inset-inline-end var(--transition);
    }
    .sidebar-open .sidebar {
        inset-inline-end: 0;
    }
    .sidebar-open .sidebar-backdrop {
        display: block;
    }
    /* Sidebar toggle on mobile switches to open/close */
    .app.sidebar-collapsed { grid-template-columns: 1fr; }
    .app.sidebar-collapsed .sidebar-brand .brand-info,
    .app.sidebar-collapsed .sidebar-nav a span:not(.badge):not(.nav-icon),
    .app.sidebar-collapsed .sidebar-nav-title,
    .app.sidebar-collapsed .sidebar-user .user-info { display: flex; }
    .app.sidebar-collapsed .sidebar-nav a { justify-content: flex-start; }

    .content { padding: 16px; }
    .topbar { padding: 0 14px; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .auth-card { padding: 28px 22px; }
    .page-header .page-title { font-size: 1.25rem; }
    .stat-card .stat-value { font-size: 1.4rem; }
}

@media (max-width: 480px) {
    html { font-size: 14px; }
    .content { padding: 12px; }
    .card { padding: 16px; }
}

/* SVG icon defaults */
.icon { width: 1em; height: 1em; stroke-width: 2; }
