* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Tahoma, Arial, sans-serif;
}

body {
    background: #f0f2f5;
    direction: rtl;
}

/* ===== Header ===== */
.header {
    background: #1a73e8;
    color: white;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header h1 {
    font-size: 20px;
}

.header-btns {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    padding: 7px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    font-family: Tahoma, Arial, sans-serif;
    transition: background 0.2s;
}

.btn-save {
    background: #34a853;
    color: white;
}

.btn-save:hover { background: #2d8f47; }

.btn-add-sheet {
    background: white;
    color: #1a73e8;
}

.btn-add-sheet:hover { background: #e8f0fe; }

/* ===== Formula Bar ===== */
.formula-bar {
    background: white;
    padding: 6px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #ddd;
}

.cell-ref {
    width: 70px;
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
    background: #f8f9fa;
}

.formula-input {
    flex: 1;
    padding: 4px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 13px;
}

/* ===== Sheets Tab ===== */
.sheets-tabs {
    background: #fff;
    padding: 0 15px;
    display: flex;
    align-items: flex-end;
    gap: 3px;
    border-bottom: 2px solid #1a73e8;
    overflow-x: auto;
}

.sheet-tab {
    padding: 8px 18px;
    background: #e8eaed;
    border: 1px solid #ccc;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.sheet-tab:hover { background: #d2e3fc; }

.sheet-tab.active {
    background: white;
    border-bottom: 2px solid white;
    color: #1a73e8;
    font-weight: bold;
    margin-bottom: -2px;
}

.sheet-tab .delete-sheet {
    color: #999;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
}

.sheet-tab .delete-sheet:hover { color: #d32f2f; background: #fce8e6; }

/* ===== Table ===== */
.table-container {
    overflow: auto;
    height: calc(100vh - 160px);
    background: white;
}

table {
    border-collapse: collapse;
    min-width: 100%;
}

/* Header ستون (A, B, C...) */
thead th {
    background: #f8f9fa;
    border: 1px solid #d0d0d0;
    padding: 5px 10px;
    text-align: center;
    font-size: 12px;
    color: #555;
    position: sticky;
    top: 0;
    z-index: 10;
    min-width: 100px;
    user-select: none;
}

thead th:first-child {
    width: 50px;
    min-width: 50px;
    position: sticky;
    left: 0;
    z-index: 20;
    background: #f8f9fa;
}

/* شماره ردیف */
.row-num {
    background: #f8f9fa;
    border: 1px solid #d0d0d0;
    padding: 4px 8px;
    text-align: center;
    font-size: 12px;
    color: #555;
    position: sticky;
    left: 0;
    z-index: 5;
    user-select: none;
}

/* سلول‌ها */
td.cell {
    border: 1px solid #d0d0d0;
    padding: 0;
    min-width: 100px;
    height: 28px;
    position: relative;
}

td.cell input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    padding: 4px 8px;
    font-size: 13px;
    font-family: Tahoma, Arial, sans-serif;
    background: transparent;
    text-align: right;
}

td.cell.selected {
    outline: 2px solid #1a73e8;
    outline-offset: -2px;
    z-index: 2;
}

td.cell input:focus {
    background: #e8f0fe;
}

/* ردیف جمع */
.sum-row td {
    background: #e8f0fe;
    border: 1px solid #b0c8f5;
    padding: 5px 8px;
    font-weight: bold;
    font-size: 13px;
    color: #1a73e8;
    text-align: right;
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.sum-row td:first-child {
    text-align: center;
    color: #555;
    font-size: 12px;
    position: sticky;
    left: 0;
    z-index: 6;
    background: #e8f0fe;
}

/* ===== Status Bar ===== */
.status-bar {
    background: #1a73e8;
    color: white;
    padding: 4px 15px;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    position: fixed;
    bottom: 0;
    width: 100%;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: #323232;
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show { opacity: 1; }

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 500;
    align-items: center;
    justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
    background: white;
    border-radius: 10px;
    padding: 25px;
    width: 320px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.modal h3 { margin-bottom: 15px; font-size: 16px; }

.modal input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    font-family: Tahoma;
    margin-bottom: 15px;
    direction: rtl;
}

.modal-btns {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.btn-confirm { background: #1a73e8; color: white; }
.btn-confirm:hover { background: #1558b0; }
.btn-cancel { background: #e0e0e0; color: #333; }
.btn-cancel:hover { background: #ccc; }
