/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --green:    #2e7d32;
  --green-l:  #43a047;
  --green-ll: #e8f5e9;
  --red:      #c62828;
  --red-l:    #ffebee;
  --amber:    #f57f17;
  --amber-l:  #fff8e1;
  --ink:      #1a1a1a;
  --muted:    #616161;
  --border:   #e0e0e0;
  --bg:       #f5f5f5;
  --card:     #ffffff;
  --radius:   12px;
  --shadow:   0 2px 12px rgba(0,0,0,.08);
  --header-h:  60px;
}
body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  direction: rtl;
  overflow-x: hidden;
}

/* ===== Header ===== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  background: linear-gradient(135deg, var(--green) 0%, var(--green-l) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 500;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  gap: 10px;
}
.header-title { flex: 1; }
.header-title h1 { font-size: 1.2rem; font-weight: 700; }
.header-title p  { font-size: .75rem; opacity: .85; }

/* ===== Header Back Button ===== */
.header-back {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  flex-shrink: 0;
  margin-left: auto;
}
.header-back:hover {
  background: rgba(255,255,255,.25);
}

/* ===== Main Content ===== */
.main-wrapper {
  padding-top: var(--header-h);
  min-height: 100vh;
}
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ===== Sections ===== */
.section { display: none; }
.section.active { display: block; }

/* ===== Page Title ===== */
.page-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--green);
  text-align: center;
  margin-bottom: 24px;
}

/* ===== Home Grid ===== */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  padding: 8px 0;
}

.home-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all .25s ease;
  font-family: inherit;
  text-align: center;
}
.home-card:hover {
  border-color: var(--green);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(46,125,50,.15);
}
.home-card:active {
  transform: translateY(-1px);
}
.home-card .home-icon {
  font-size: 2.8rem;
  line-height: 1;
}
.home-card .home-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}
.home-card .home-desc {
  font-size: .78rem;
  color: var(--muted);
}

/* ===== Add Toggle Button ===== */
.add-toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--card);
  border: 2px dashed var(--green);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--green);
  cursor: pointer;
  font-family: inherit;
  margin-bottom: 16px;
  transition: all .2s;
  box-shadow: var(--shadow);
}
.add-toggle-btn:hover {
  background: var(--green-ll);
  border-color: var(--green);
}
.add-toggle-btn .add-toggle-icon { font-size: 1.3rem; }
.add-toggle-btn .add-toggle-arrow {
  margin-right: auto;
  transition: transform .3s;
  font-size: .8rem;
}
.add-toggle-btn.open .add-toggle-arrow {
  transform: rotate(180deg);
}
.toggle-form {
  animation: slideDown .3s ease;
}
@keyframes slideDown {
  from { opacity:0; transform:translateY(-10px); max-height:0; }
  to   { opacity:1; transform:translateY(0); max-height:1000px; }
}

/* ===== Lists Section ===== */
.list-add-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.list-add-row input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  font-family: inherit;
  background: #fafafa;
  transition: border-color .2s;
  direction: rtl;
}
.list-add-row input:focus {
  outline: none;
  border-color: var(--green);
  background: #fff;
}
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-ll);
  border: 1.5px solid var(--green);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--green);
}
.tag .tag-del {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  font-weight: 700;
  transition: opacity .2s;
}
.tag .tag-del:hover { opacity: .7; }

/* ===== Back Button ===== */
.back-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: .85rem;
  font-family: inherit;
  color: var(--green);
  cursor: pointer;
  margin-bottom: 16px;
  transition: all .2s;
  font-weight: 600;
}
.back-btn:hover {
  background: var(--green-ll);
  border-color: var(--green);
}

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Summary Boxes ===== */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.sum-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.sum-box .label { font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.sum-box .value { font-size: 1.4rem; font-weight: 800; }
.sum-box.green  { border-top: 4px solid var(--green);  }
.sum-box.red    { border-top: 4px solid var(--red);    }
.sum-box.amber  { border-top: 4px solid var(--amber);  }
.sum-box.green .value { color: var(--green); }
.sum-box.red    .value { color: var(--red); }
.sum-box.amber  .value { color: var(--amber); }

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  font-family: inherit;
  background: #fafafa;
  transition: border-color .2s;
  direction: rtl;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--green);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 70px; }

/* ===== Calc Row ===== */
.calc-row {
  background: var(--green-ll);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.calc-row span { font-size: .85rem; color: var(--muted); }
.calc-row strong { color: var(--green); font-size: 1rem; }

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 11px 24px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { opacity: .88; }
.btn-sm { padding: 7px 14px; font-size: .8rem; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  background: var(--green);
  color: #fff;
  padding: 10px 14px;
  text-align: right;
  font-weight: 600;
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--green-ll); }
tbody td { padding: 10px 14px; vertical-align: middle; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }

/* ===== Inventory Big Number ===== */
.inv-hero {
  text-align: center;
  padding: 32px;
  background: linear-gradient(135deg, var(--green-ll), #fff);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.inv-hero .num { font-size: 3.5rem; font-weight: 900; color: var(--green); line-height: 1; }
.inv-hero .sub { color: var(--muted); margin-top: 6px; font-size: .9rem; }

/* ===== Modal Overlay ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  position: relative;
  animation: slideUp .3s ease;
}
@keyframes slideUp { from { transform:translateY(40px); opacity:0; } to { transform:translateY(0); opacity:1; } }

.modal-close {
  position: absolute;
  top: 12px;
  left: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--ink); }

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 20px;
  text-align: center;
}

/* ===== Timeline ===== */
.timeline {
  position: relative;
  padding: 0;
}
.timeline::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 20px;
  width: 3px;
  background: var(--border);
  border-radius: 2px;
}
.timeline-item {
  position: relative;
  padding-right: 52px;
  padding-bottom: 20px;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
  position: absolute;
  right: 12px;
  top: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px var(--green);
  z-index: 1;
}
.timeline-dot.red    { background: var(--red);    box-shadow: 0 0 0 2px var(--red); }
.timeline-dot.amber  { background: var(--amber);  box-shadow: 0 0 0 2px var(--amber); }
.timeline-dot.blue   { background: #1976d2;       box-shadow: 0 0 0 2px #1976d2; }

.timeline-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  transition: box-shadow .2s;
}
.timeline-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
}
.timeline-card .tl-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.timeline-card .tl-icon { font-size: 1.1rem; }
.timeline-card .tl-type {
  font-size: .82rem;
  font-weight: 700;
  color: var(--ink);
}
.timeline-card .tl-date {
  font-size: .72rem;
  color: var(--muted);
  margin-right: auto;
}
.timeline-card .tl-desc {
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.5;
}
.timeline-card .tl-amount {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 4px;
}
.timeline-card .tl-amount.positive { color: var(--green); }
.timeline-card .tl-amount.negative { color: var(--red); }
.timeline-empty {
  text-align: center;
  color: var(--muted);
  padding: 30px 0;
  font-size: .9rem;
}

/* ===== Debt / Receivable Cards ===== */
.cards-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.status-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  transition: box-shadow .2s;
}
.status-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,.1);
}
.status-card.paid {
  opacity: .6;
  border-color: var(--green);
  background: var(--green-ll);
}
.status-card .sc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.status-card .sc-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
}
.status-card .sc-status {
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}
.status-card .sc-status.pending {
  background: var(--amber-l);
  color: var(--amber);
}
.status-card .sc-status.paid {
  background: var(--green-ll);
  color: var(--green);
}
.status-card .sc-details {
  display: flex;
  gap: 16px;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.status-card .sc-details span {
  display: flex;
  align-items: center;
  gap: 4px;
}
.status-card .sc-details strong {
  color: var(--ink);
}
.status-card .sc-actions {
  display: flex;
  gap: 8px;
}
.status-card .btn-settle {
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s, transform .1s;
}
.status-card .btn-settle:hover { opacity: .85; }
.status-card .btn-settle:active { transform: scale(.97); }

/* ===== Confirm Dialog ===== */
.confirm-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .25s ease;
}
.confirm-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px 20px;
  width: 90%;
  max-width: 360px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  text-align: center;
  animation: slideUp .3s ease;
}
.confirm-box .confirm-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}
.confirm-box .confirm-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}
.confirm-box .confirm-desc {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1.5;
}
.confirm-box .confirm-btns {
  display: flex;
  gap: 10px;
}
.confirm-box .confirm-btns button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s;
}
.confirm-box .confirm-btns .btn-yes {
  background: var(--green);
  color: #fff;
}
.confirm-box .confirm-btns .btn-yes:hover { opacity: .85; }
.confirm-box .confirm-btns .btn-no {
  background: var(--red-l);
  color: var(--red);
}
.confirm-box .confirm-btns .btn-no:hover { opacity: .85; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: .9rem;
  transition: bottom .3s;
  z-index: 2000;
  white-space: nowrap;
}
.toast.show    { bottom: 24px; }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }

/* ===== Summary Section ===== */
.summary-section {
  margin-bottom: 28px;
}
.summary-heading {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 16px;
  text-align: center;
}

.summary-main-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  border: 2px solid var(--border);
}
.summary-main-icon {
  font-size: 2.2rem;
  line-height: 1;
}
.summary-main-content { flex: 1; }
.summary-main-label {
  font-size: .85rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.summary-main-value {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--ink);
}

.summary-main-card.purchases-main { border-top: 5px solid #e65100; }
.summary-main-card.sales-main { border-top: 5px solid #1565c0; }
.summary-main-card.difference-main { border-top: 5px solid #2e7d32; }

.summary-sub-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.summary-sub-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1.5px solid var(--border);
}
.summary-sub-icon { font-size: 1.5rem; }
.summary-sub-content { flex: 1; }
.summary-sub-label {
  font-size: .78rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}
.summary-sub-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--ink);
}

.summary-sub-card.paid { border-top: 4px solid #2e7d32; }
.summary-sub-card.paid .summary-sub-value { color: #2e7d32; }

.summary-sub-card.cash { border-top: 4px solid #43a047; }
.summary-sub-card.cash .summary-sub-value { color: #2e7d32; }

.summary-sub-card.credit { border-top: 4px solid #f57f17; }
.summary-sub-card.credit .summary-sub-value { color: #f57f17; }

/* ===== Login Screen ===== */
.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}
.login-screen.active { display: flex; }

.login-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 40px 30px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.08);
  border: 1px solid #e0e0e0;
}

.login-logo {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 20px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: #1a1a1a;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: .9rem;
  color: #616161;
  margin-bottom: 28px;
}

.login-field {
  margin-bottom: 16px;
}

.login-field input {
  width: 100%;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1.1rem;
  font-family: inherit;
  text-align: center;
  background: #fafafa;
  transition: border-color .2s;
  direction: rtl;
}
.login-field input:focus {
  outline: none;
  border-color: #2e7d32;
  background: #fff;
}

.btn-login {
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .2s, transform .1s;
}
.btn-login:hover { opacity: .88; }
.btn-login:active { transform: scale(.97); }

.login-error {
  color: #c62828;
  font-size: .85rem;
  margin-top: 12px;
  font-weight: 600;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .header h1 { font-size: 1.1rem; }
  .inv-hero .num { font-size: 2.5rem; }
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 16px 10px; }
  .home-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }
  .home-card { padding: 20px 14px; }
  .home-card .home-icon { font-size: 2.2rem; }
}