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

body {
  font-family: Arial, sans-serif;
  direction: rtl;
  background: #F9F5FD;
  color: #1a1a2e;
  font-size: 13px;
}

.hidden { display: none !important; }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3B1054 0%, #7B2D8B 100%);
}

.login-box {
  background: white;
  padding: 40px 36px;
  border-radius: 16px;
  text-align: center;
  width: 320px;
  box-shadow: 0 12px 40px rgba(59,16,84,0.35);
}

.login-logo {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, #3B1054, #7B2D8B);
  color: white;
  font-size: 22px;
  font-weight: bold;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.login-box h1 {
  color: #3B1054;
  font-size: 26px;
  margin-bottom: 4px;
}

.login-subtitle {
  color: #7B2D8B;
  font-size: 13px;
  margin-bottom: 28px;
}

#pin-input {
  width: 100%;
  padding: 12px;
  font-size: 22px;
  letter-spacing: 10px;
  text-align: center;
  border: 2px solid #EAD9F7;
  border-radius: 10px;
  margin-bottom: 14px;
  font-family: Arial, sans-serif;
  direction: ltr;
}

#pin-input:focus { outline: none; border-color: #7B2D8B; }

#login-btn {
  width: 100%;
  padding: 12px;
  background: #3B1054;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-family: Arial, sans-serif;
  cursor: pointer;
  transition: background 0.2s;
}

#login-btn:hover { background: #7B2D8B; }

.login-error { color: #880E4F; font-size: 13px; margin-top: 10px; min-height: 18px; }
.login-info { color: #555; font-size: 12px; margin-top: 6px; }

/* ---- Header ---- */
.app-header {
  background: #3B1054;
  color: white;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.header-right { display: flex; align-items: center; gap: 12px; }
.header-logo { font-size: 18px; font-weight: bold; }
.header-period { font-size: 12px; opacity: 0.75; }
.header-left { display: flex; align-items: center; gap: 10px; }

.save-status { font-size: 11px; opacity: 0.7; }
.save-status.saving { color: #FFD54F; }
.save-status.saved { color: #A5D6A7; }

.btn-logout {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 12px;
}

.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* ---- Table ---- */
.table-wrapper {
  overflow-x: auto;
  padding: 12px;
  min-height: calc(100vh - 44px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

thead th {
  background: #3B1054;
  color: white;
  padding: 5px 8px;
  text-align: center;
  position: sticky;
  top: 44px;
  z-index: 50;
  white-space: nowrap;
  overflow: visible;
  border: 1px solid #2a0d3e;
  font-size: 12px;
}

thead th.col-item { text-align: right; }
thead th.col-total { background: #4A148C; }
thead th.col-cash { background: #880E4F; }

.col-narrow { width: 22px; min-width: 22px; }
.col-item { min-width: 160px; text-align: right !important; }
.col-total { min-width: 80px; }
.col-cash { min-width: 70px; }

/* ---- Row Types ---- */
td {
  padding: 1px 5px;
  border: 1px solid #e0d0f0;
  vertical-align: middle;
}

tr.row-block-header td {
  color: white;
  font-weight: bold;
  font-size: 13px;
  padding: 5px 8px;
}

tr.row-subsection td {
  background: #EAD9F7;
  color: #3B1054;
  font-weight: bold;
  font-size: 11px;
  padding: 4px 10px;
}

tr.row-manual td { background: #FFF9C4; }
tr.row-recurring td { background: #F9F5FD; }
tr.row-subtotal td { background: #EAD9F7; font-weight: bold; }
tr.row-income td { background: #E8F5E9; }
tr.row-income-sub td { background: #C8E6C9; font-weight: bold; }
tr.row-balance td { background: #FCE4EC; font-weight: bold; }
tr.row-cash-total td { background: #E0F7FA; font-weight: bold; }
tr.row-added td { background: #FFF9C4; font-style: italic; }

/* ---- Cells ---- */
td.cell-item { text-align: right; }
td.cell-amount { text-align: left; direction: ltr; }
td.cell-total { text-align: left; direction: ltr; font-weight: bold; background: #EAD9F7; }
td.cell-cash-total { text-align: left; direction: ltr; background: #E0F7FA; }
td.cell-narrow { width: 22px; padding: 2px 4px; }

/* ---- Inputs ---- */
.input-amount {
  width: 68px;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  font-size: 12px;
  font-family: Arial, sans-serif;
  direction: ltr;
  padding: 1px 3px;
  border-radius: 3px;
}

.input-amount:focus {
  outline: none;
  border-color: #7B2D8B;
  background: white;
}

/* ---- Nektat Button ---- */
.btn-nektat {
  font-size: 10px;
  padding: 1px 5px;
  background: #3B1054;
  color: white;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  display: block;
  margin-top: 2px;
  white-space: nowrap;
}

.btn-nektat:hover { background: #7B2D8B; }

.amount-collected {
  color: #aaa;
  text-decoration: line-through;
  font-size: 12px;
  direction: ltr;
  display: inline-block;
}

/* ---- Add Transaction Button ---- */
.btn-add-txn {
  font-size: 11px;
  padding: 3px 9px;
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  margin-right: 8px;
  float: left;
}

.btn-add-txn:hover { background: rgba(255,255,255,0.35); }

/* ---- Delete Button ---- */
.btn-delete {
  background: transparent;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  line-height: 1;
}

.btn-delete:hover { color: #880E4F; }

/* ---- Cash Cell ---- */
.cash-cell-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  direction: ltr;
}

.checkbox-cash {
  width: 13px;
  height: 13px;
  cursor: pointer;
  accent-color: #006064;
}

.input-cash {
  width: 52px;
  border: 1px solid #b2dfdb;
  border-radius: 3px;
  font-size: 11px;
  padding: 1px 3px;
  direction: ltr;
  font-family: Arial, sans-serif;
  background: #E0F7FA;
}

.input-cash:focus { outline: none; border-color: #006064; }

/* ---- Balance Colors ---- */
.amount-negative { color: #C62828; }
.amount-positive { color: #2E7D32; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: white;
  padding: 28px;
  border-radius: 14px;
  width: 340px;
  max-width: 92vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.modal h2 {
  color: #3B1054;
  margin-bottom: 20px;
  font-size: 16px;
}

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 5px;
}

.form-group input[type="number"],
.form-group input[type="text"],
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 7px;
  font-size: 13px;
  font-family: Arial, sans-serif;
}

.form-group input:focus,
.form-group select:focus { outline: none; border-color: #7B2D8B; }

.type-buttons { display: flex; gap: 6px; }

.type-btn {
  flex: 1;
  padding: 7px;
  border: 2px solid #EAD9F7;
  background: white;
  border-radius: 7px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 12px;
  color: #555;
  transition: all 0.15s;
}

.type-btn.active {
  background: #3B1054;
  color: white;
  border-color: #3B1054;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px !important;
  color: #333 !important;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-primary {
  background: #3B1054;
  color: white;
  border: none;
  padding: 9px 20px;
  border-radius: 7px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 13px;
}

.btn-primary:hover { background: #7B2D8B; }

.btn-secondary {
  background: #f0f0f0;
  color: #333;
  border: none;
  padding: 9px 20px;
  border-radius: 7px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 13px;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { height: 5px; width: 5px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #7B2D8B; border-radius: 3px; }

/* ---- Mobile ---- */
@media (max-width: 768px) {

  /* Header */
  .header-period { display: none; }
  .header-logo { font-size: 15px; }

  /* Table wrapper - smooth touch scroll */
  .table-wrapper {
    padding: 4px;
    -webkit-overflow-scrolling: touch;
  }

  /* Column widths */
  .col-item { min-width: 120px; }
  .col-total { min-width: 60px; }
  .col-cash { min-width: 58px; }


  /* Touch-friendly inputs — 16px prevents iOS auto-zoom */
  .input-amount {
    width: 56px;
    font-size: 16px;
    padding: 3px 2px;
    height: 30px;
  }

  /* Nektat button — bigger touch target */
  .btn-nektat {
    font-size: 11px;
    padding: 5px 7px;
    margin-top: 3px;
    min-height: 30px;
    display: block;
  }

  /* Add transaction button */
  .btn-add-txn {
    padding: 5px 9px;
    font-size: 11px;
  }

  /* Delete button — bigger tap area */
  .btn-delete {
    font-size: 16px;
    padding: 4px 5px;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Cash checkbox — bigger tap target */
  .checkbox-cash {
    width: 20px;
    height: 20px;
    min-width: 20px;
  }

  /* Login box — fits all screen widths */
  .login-box {
    width: calc(100vw - 32px);
    max-width: 320px;
    padding: 32px 20px;
  }

  /* Modal — full width on mobile */
  .modal {
    width: 95vw;
    max-width: 95vw;
    padding: 20px 16px;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Modal inputs — 16px prevents iOS auto-zoom */
  .form-group input[type="number"],
  .form-group input[type="text"],
  .form-group select {
    font-size: 16px;
    padding: 10px;
  }

  .type-btn {
    padding: 9px 4px;
    font-size: 13px;
  }

  .btn-primary,
  .btn-secondary {
    padding: 12px 16px;
    font-size: 14px;
    flex: 1;
  }
}

/* Very small screens (iPhone SE, Galaxy A02) */
@media (max-width: 380px) {
  .login-box { padding: 24px 14px; }
  .col-item { min-width: 100px; }
  thead th.col-item { min-width: 100px; }
  .input-amount { width: 48px; }
}

/* ---- Header Buttons ---- */
.btn-save {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 12px;
}
.btn-save:hover { background: rgba(255,255,255,0.25); }

.btn-undo {
  background: transparent;
  color: rgba(255,255,255,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 12px;
}
.btn-undo:not([disabled]):hover { background: rgba(255,255,255,0.15); color: white; }
.btn-undo[disabled] { opacity: 0.35; cursor: default; }

/* ---- Cash Indicator Button ---- */
.btn-cash {
  font-size: 9px;
  padding: 1px 4px;
  background: transparent;
  color: #bbb;
  border: 1px solid #e0d0f0;
  border-radius: 3px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  display: block;
  margin-top: 2px;
  white-space: nowrap;
  direction: ltr;
  line-height: 1.4;
}
.btn-cash.has-cash {
  background: #E0F7FA;
  color: #006064;
  border-color: #80DEEA;
  font-weight: bold;
}
.btn-cash:hover { border-color: #7B2D8B; color: #7B2D8B; }
.btn-cash.has-cash:hover { border-color: #00838F; }

/* ---- Subs Detail Button ---- */
.btn-subs-detail {
  font-size: 9px;
  padding: 1px 5px;
  background: #EAD9F7;
  color: #3B1054;
  border: 1px solid #7B2D8B;
  border-radius: 3px;
  cursor: pointer;
  font-family: Arial, sans-serif;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-subs-detail:hover { background: #7B2D8B; color: white; }

/* ---- Subs Modal ---- */
.subs-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  direction: rtl;
}
.subs-name { flex: 1; font-size: 13px; }
.subs-currency {
  padding: 3px 4px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  font-family: Arial, sans-serif;
}
.subs-amount {
  width: 62px;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  direction: ltr;
  font-family: Arial, sans-serif;
}
.subs-ils {
  color: #006064;
  font-size: 11px;
  min-width: 38px;
  text-align: left;
  direction: ltr;
}
.subs-total-line {
  border-top: 2px solid #EAD9F7;
  margin-top: 10px;
  padding-top: 10px;
  font-weight: bold;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  color: #3B1054;
}

@media (max-width: 768px) {
  .btn-cash { font-size: 10px; padding: 2px 5px; min-height: 22px; }
  .btn-undo, .btn-save { padding: 4px 8px; font-size: 11px; }
}
