/* ==========================================================
   Shop Expenses App — Mobile-first RTL stylesheet
   ========================================================== */

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #e11d48;
    --success: #16a34a;
    --bg: #f4f5f9;
    --surface: #ffffff;
    --text: #1e2130;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 10px rgba(20, 20, 43, 0.06);
    --shadow-lg: 0 10px 30px rgba(20, 20, 43, 0.16);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", Tahoma, "Cairo", "Noto Sans Arabic", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    -webkit-font-smoothing: antialiased;
    padding-bottom: calc(96px + var(--safe-bottom));
}

button, input {
    font-family: inherit;
}

/* ---------------- Login page ---------------- */

.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #4f46e5 0%, #312e81 100%);
    padding: 20px;
}

.login-wrap {
    width: 100%;
    max-width: 380px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px 24px;
    text-align: center;
}

.login-icon {
    font-size: 42px;
    margin-bottom: 8px;
}

.login-card h1 {
    font-size: 22px;
    margin: 0 0 6px;
}

.login-sub {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 24px;
}

.login-error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecdd3;
    border-radius: var(--radius-sm);
    padding: 10px;
    font-size: 14px;
    margin-bottom: 16px;
}

/* ---------------- Form fields & buttons ---------------- */

.field {
    display: block;
    text-align: right;
    margin-bottom: 16px;
}

.field span {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.field input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 16px;
    background: #fafafa;
    color: var(--text);
    transition: border-color .15s, background .15s;
}

.field input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 15px 20px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .08s, opacity .15s, background .15s;
}

.btn:active {
    transform: scale(0.97);
}

.btn-block {
    width: 100%;
}

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

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

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

.btn-ghost {
    background: #f1f2f6;
    color: var(--text);
    margin-top: 10px;
}

/* ---------------- Header ---------------- */

.app-header {
    background: linear-gradient(160deg, #4f46e5 0%, #4338ca 100%);
    color: #fff;
    padding: 18px 16px 22px;
    border-radius: 0 0 24px 24px;
    box-shadow: var(--shadow-lg);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-top h1 {
    font-size: 19px;
    margin: 0;
    font-weight: 800;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-date {
    font-size: 13px;
    opacity: 0.85;
    margin-top: 4px;
}

.hero-stat {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    padding: 18px 12px;
}

.hero-label {
    font-size: 13px;
    opacity: 0.85;
    margin-bottom: 6px;
}

.hero-value {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.hero-count {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 6px;
}

/* ---------------- Main layout ---------------- */

.app-main {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px;
}

/* ---------------- Search ---------------- */

.search-box {
    position: relative;
    margin-bottom: 14px;
}

.search-box input {
    width: 100%;
    padding: 13px 42px 13px 16px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--surface);
    font-size: 15px;
    box-shadow: var(--shadow);
}

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

.search-icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 15px;
    opacity: 0.5;
}

/* ---------------- Quick filters ---------------- */

.quick-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    margin-bottom: 12px;
    scrollbar-width: none;
}

.quick-filters::-webkit-scrollbar {
    display: none;
}

.chip {
    flex: none;
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--text);
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
}

.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ---------------- Date filter ---------------- */

.date-filter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.date-filter label {
    font-size: 13.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.date-filter input {
    border: none;
    background: transparent;
    font-size: 14.5px;
    color: var(--text);
    font-weight: 600;
    text-align: left;
}

.date-filter input:focus {
    outline: none;
}

/* ---------------- Stats grid ---------------- */

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    display: block;
    font-size: 17px;
    font-weight: 800;
    color: var(--text);
}

/* ---------------- Actions row ---------------- */

.actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 18px;
}

.action-btn {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.action-btn:active {
    transform: scale(0.97);
}

/* ---------------- Expense list & cards ---------------- */

.list-section {
    min-height: 120px;
}

.expense-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.expense-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

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

.expense-name {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expense-amount {
    font-size: 18px;
    font-weight: 800;
    color: var(--primary);
    margin: 0 0 6px;
}

.expense-date {
    font-size: 12.5px;
    color: var(--text-muted);
}

.expense-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mini-btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.mini-btn.edit {
    background: #eef2ff;
    color: var(--primary);
}

.mini-btn.delete {
    background: #fef2f2;
    color: var(--danger);
}

/* ---------------- Loading / Empty state ---------------- */

.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 40px 0;
    color: var(--text-muted);
    font-size: 14px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 44px;
    margin-bottom: 10px;
}

/* ---------------- Floating Add Button ---------------- */

.fab {
    position: fixed;
    bottom: calc(20px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 15px 28px;
    border-radius: 999px;
    font-size: 16px;
    font-weight: 800;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.45);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 40;
    max-width: 90vw;
}

.fab:active {
    transform: translateX(-50%) scale(0.96);
}

.fab-plus {
    font-size: 20px;
    line-height: 1;
}

/* ---------------- Modal ---------------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 15, 35, 0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    padding: 0;
}

.modal-sheet {
    background: var(--surface);
    width: 100%;
    max-width: 480px;
    border-radius: 22px 22px 0 0;
    padding: 12px 20px calc(24px + var(--safe-bottom));
    box-shadow: var(--shadow-lg);
    animation: slideUp .2s ease-out;
}

@media (min-width: 540px) {
    .modal-overlay {
        align-items: center;
    }
    .modal-sheet {
        border-radius: var(--radius);
    }
}

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

.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 0 auto 14px;
}

.modal-sheet h2 {
    font-size: 18px;
    margin: 0 0 18px;
    text-align: center;
}

.modal-actions {
    margin-top: 6px;
}

.modal-sheet-small {
    text-align: center;
}

.confirm-text {
    font-size: 16px;
    font-weight: 600;
    margin: 6px 0 20px;
}

/* ---------------- Toasts ---------------- */

.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 92%;
    max-width: 420px;
    align-items: center;
}

.toast {
    background: #1e2130;
    color: #fff;
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    text-align: center;
    animation: toastIn .2s ease-out;
    width: 100%;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

@keyframes toastIn {
    from { transform: translateY(-12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---------------- Print report ---------------- */

.print-area {
    display: none;
}

@media print {
    body * {
        visibility: hidden;
    }
    .print-area, .print-area * {
        visibility: visible;
    }
    .print-area {
        display: block;
        position: absolute;
        top: 0;
        right: 0;
        width: 100%;
        padding: 20px;
    }
    .print-area table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 14px;
    }
    .print-area th, .print-area td {
        border: 1px solid #999;
        padding: 8px;
        text-align: right;
        font-size: 13px;
    }
    .print-total {
        margin-top: 16px;
        font-size: 15px;
        font-weight: 800;
    }
}

/* ---------------- Larger screens ---------------- */

@media (min-width: 768px) {
    .app-main {
        padding: 24px;
    }
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .actions-row {
        grid-template-columns: repeat(4, 1fr);
    }
}
