/* ========================
   VARIABLES & RESET
======================== */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --border: #e2e8f0;
  --text: #1a202c;
  --text2: #4a5568;
  --text3: #718096;
  --accent: #e63946;
  --accent2: #c1121f;
  --gold: #f4a261;
  --green: #38a169;
  --red: #e53e3e;
  --orange: #dd6b20;
  --blue: #3182ce;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
  --radius: 14px;
  --radius-sm: 8px;
  --header-h: 60px;
  --font: 'Cairo', 'Tajawal', sans-serif;
}

body.dark-mode {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --border: #2d2d4e;
  --text: #e8eaf6;
  --text2: #b0b8d8;
  --text3: #7986a8;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background .3s, color .3s;
  padding-top: var(--header-h);
  padding-bottom: 48px;
}

/* ========================
   HEADER
======================== */
.app-header {
  position: fixed;
  top: 0; right: 0; left: 0;
  height: var(--header-h);
  background: var(--accent);
  z-index: 1000;
  box-shadow: 0 2px 16px rgba(230,57,70,.3);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 1rem;
  max-width: 600px;
  margin: 0 auto;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.brand-icon {
  font-size: 1.5rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%,100%{transform:translateY(0);}
  50%{transform:translateY(-3px);}
}

.brand-name {
  font-family: 'Tajawal', sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: .5px;
}

.hamburger-btn {
  background: rgba(255,255,255,.15);
  border: none;
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: background .2s;
}
.hamburger-btn:hover { background: rgba(255,255,255,.25); }
.hamburger-btn span {
  display: block;
  width: 20px; height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: .3s;
}

/* ========================
   SIDE DRAWER
======================== */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1100;
  backdrop-filter: blur(2px);
}
.drawer-overlay.open { display: block; }

.side-drawer {
  position: fixed;
  top: 0; right: -280px;
  width: 280px;
  height: 100%;
  background: var(--surface);
  z-index: 1200;
  transition: right .3s cubic-bezier(.4,0,.2,1);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}
.side-drawer.open { right: 0; }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}
.drawer-close {
  background: rgba(255,255,255,.2);
  border: none;
  color: #fff;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  transition: background .2s;
}
.drawer-close:hover { background: rgba(255,255,255,.35); }

.drawer-menu {
  list-style: none;
  padding: .5rem 0;
  overflow-y: auto;
  flex: 1;
}
.drawer-menu li a {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1.2rem;
  color: var(--text);
  text-decoration: none;
  font-size: .95rem;
  font-weight: 500;
  transition: background .15s, color .15s;
  border-radius: var(--radius-sm);
  margin: 2px .5rem;
}
.drawer-menu li a:hover {
  background: var(--bg);
  color: var(--accent);
}

/* ========================
   MAIN & PAGES
======================== */
.app-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }

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

.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.2rem;
}
.page-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: .45rem .9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: .85rem;
  transition: all .2s;
  white-space: nowrap;
}
.back-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ========================
   HOME PAGE
======================== */
.home-hero {
  background: linear-gradient(135deg, var(--accent) 0%, #c1121f 100%);
  border-radius: var(--radius);
  padding: 1.4rem 1.2rem;
  margin-bottom: 1rem;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 4px 20px rgba(230,57,70,.35);
}

.hero-text h1 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: .3rem;
  line-height: 1.3;
}
.hero-text h1 span { color: #ffd166; }
.hero-text p { font-size: .85rem; opacity: .85; }

.hero-stats {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  text-align: center;
  flex-shrink: 0;
}
.hero-stat {
  background: rgba(255,255,255,.15);
  border-radius: var(--radius-sm);
  padding: .4rem .7rem;
  backdrop-filter: blur(8px);
}
.hero-stat .val {
  font-size: 1.1rem;
  font-weight: 800;
  display: block;
}
.hero-stat .lbl {
  font-size: .68rem;
  opacity: .8;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.home-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.3rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
  transition: all .2s cubic-bezier(.4,0,.2,1);
  box-shadow: var(--shadow);
  font-family: var(--font);
  color: var(--text);
}
.home-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.home-card:active { transform: scale(.97); }
.home-card.accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  grid-column: span 2;
}
.home-card.accent:hover { background: var(--accent2); }
.card-icon { font-size: 2rem; }
.card-label { font-size: .9rem; font-weight: 700; text-align: center; }

/* ========================
   FORM CARD
======================== */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.form-card.compact { padding: .9rem 1rem; }

.section-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .9rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--border);
}

.form-row {
  margin-bottom: .9rem;
}
.form-row label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: .35rem;
}
.form-row.flex-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.form-row.inline {
  display: flex;
  gap: .6rem;
  align-items: center;
}
.form-row.inline input { flex: 1; }

input, select, textarea {
  width: 100%;
  padding: .65rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font);
  font-size: .9rem;
  outline: none;
  transition: border .2s, box-shadow .2s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(230,57,70,.15);
}
.readonly-input { background: var(--bg); color: var(--text3); cursor: not-allowed; }
textarea { resize: vertical; min-height: 65px; }

.date-toggle-row {
  margin-bottom: .4rem;
}
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  font-size: .82rem;
  color: var(--text2);
  font-weight: 600;
}
.toggle-label input[type=checkbox] { display: none; }
.toggle-slider {
  width: 36px; height: 20px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px; right: 3px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle-label input:checked + .toggle-slider { background: var(--accent); }
.toggle-label input:checked + .toggle-slider::after { transform: translateX(-16px); }

/* CALC PREVIEW */
.calc-preview {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .9rem;
  margin: .5rem 0 .9rem;
}
.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .3rem 0;
  font-size: .85rem;
  color: var(--text2);
  border-bottom: 1px dashed var(--border);
}
.calc-row:last-child { border-bottom: none; }
.calc-row.total { color: var(--green); font-weight: 700; font-size: .95rem; }
.calc-row.worker { color: var(--orange); font-weight: 600; }

.radio-group { display: flex; gap: 1rem; }
.radio-label {
  display: flex;
  align-items: center;
  gap: .4rem;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
}
.radio-label.paid { color: var(--green); }
.radio-label.unpaid { color: var(--red); }
.radio-label input { width: auto; }

/* ========================
   BUTTONS
======================== */
.btn-primary, .btn-secondary, .btn-danger {
  padding: .7rem 1.3rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: #ff4d4f; color: #fff; }
.btn-danger:hover { background: #d9363e; }
.full-width { width: 100%; }

/* ========================
   FILTER BAR
======================== */
.filter-bar {
  display: flex;
  gap: .6rem;
  margin-bottom: 1rem;
}
.filter-bar select { flex-shrink: 0; width: auto; }
.filter-bar input { flex: 1; }

/* ========================
   INVOICE ITEM
======================== */
.invoice-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: .75rem;
  box-shadow: var(--shadow);
  transition: transform .15s;
}
.invoice-item:hover { transform: translateX(-2px); }
.invoice-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .5rem;
}
.invoice-num {
  font-size: .82rem;
  color: var(--text3);
  font-weight: 600;
}
.badge {
  padding: .2rem .7rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
}
.badge.paid { background: #c6f6d5; color: #276749; }
.badge.unpaid { background: #fed7d7; color: #9b2335; }
body.dark-mode .badge.paid { background: #1c4532; color: #68d391; }
body.dark-mode .badge.unpaid { background: #4a1a1a; color: #fc8181; }

.invoice-customer { font-size: 1rem; font-weight: 700; margin-bottom: .3rem; }
.invoice-details {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: .82rem;
  color: var(--text3);
  margin-bottom: .5rem;
}
.invoice-amount {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent);
}
.invoice-actions { display: flex; gap: .5rem; margin-top: .6rem; }
.action-btn {
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  font-size: .78rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all .2s;
  font-weight: 600;
}
.action-btn.mark-paid { border-color: var(--green); color: var(--green); }
.action-btn.mark-paid:hover { background: var(--green); color: #fff; }
.action-btn.delete-inv { border-color: var(--red); color: var(--red); }
.action-btn.delete-inv:hover { background: var(--red); color: #fff; }

/* ========================
   STATS
======================== */
.stats-controls {
  display: flex;
  gap: .75rem;
  margin-bottom: 1rem;
}
.stats-controls select { flex: 1; }

.stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .s-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--accent);
  display: block;
}
.stat-card .s-lbl {
  font-size: .75rem;
  color: var(--text3);
  margin-top: .2rem;
  display: block;
}

.stats-table-wrap { overflow-x: auto; }
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.stats-table th {
  background: var(--accent);
  color: #fff;
  padding: .65rem .8rem;
  text-align: center;
  font-weight: 700;
}
.stats-table td {
  padding: .55rem .8rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.stats-table tr:last-child td { border-bottom: none; }
.stats-table tr:hover td { background: var(--surface2); }
.day-status {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
}
.day-status.green { background: var(--green); }
.day-status.red { background: var(--red); }
.day-status.orange { background: var(--orange); }
.day-status.gray { background: var(--border); }

/* ========================
   CUSTOMERS LIST
======================== */
.customers-list, .invoices-list, .movements-list { }

.customer-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-bottom: .6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.customer-info { display: flex; align-items: center; gap: .7rem; }
.customer-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}
.customer-name { font-weight: 700; font-size: .92rem; }
.customer-id { font-size: .75rem; color: var(--text3); }
.del-btn {
  background: none;
  border: 1.5px solid var(--red);
  color: var(--red);
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: .9rem;
  transition: all .2s;
}
.del-btn:hover { background: var(--red); color: #fff; }

/* ========================
   WALLET CARDS
======================== */
.wallet-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: 1rem;
}
.wallet-card {
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  color: #fff;
}
.wallet-card.main { background: linear-gradient(135deg, #e63946, #c1121f); }
.wallet-card.worker { background: linear-gradient(135deg, #f4a261, #e76f51); }
.wallet-card .wc-label { font-size: .75rem; opacity: .85; margin-bottom: .3rem; }
.wallet-card .wc-amount {
  font-size: 1.3rem;
  font-weight: 800;
  direction: ltr;
  display: block;
}
.wallet-card .wc-sub { font-size: .7rem; opacity: .75; margin-top: .3rem; }

/* ========================
   MOVEMENTS
======================== */
.movement-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  margin-bottom: .6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.mov-info {}
.mov-type {
  font-size: .78rem;
  color: var(--text3);
  margin-bottom: .1rem;
}
.mov-amount {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--red);
}
.mov-date { font-size: .75rem; color: var(--text3); text-align: left; }
.mov-icon {
  font-size: 1.4rem;
  opacity: .7;
}

/* ========================
   DARK MODE TOGGLE
======================== */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  transition: .3s;
}
.slider.round { border-radius: 26px; }
.slider::before {
  content: "";
  position: absolute;
  height: 18px; width: 18px;
  left: 4px; bottom: 4px;
  background: white;
  border-radius: 50%;
  transition: .3s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* ========================
   TOAST
======================== */
.toast {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1a202c;
  color: #fff;
  padding: .65rem 1.4rem;
  border-radius: 30px;
  font-size: .88rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all .3s;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========================
   MODAL
======================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .25s ease;
}
@keyframes modalIn {
  from { transform: scale(.9); opacity: 0; }
  to   { transform: scale(1);  opacity: 1; }
}
.modal-title {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: .75rem;
  color: var(--text);
}
.modal-body { font-size: .88rem; color: var(--text2); margin-bottom: 1rem; line-height: 1.6; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; }

/* ========================
   FOOTER
======================== */
.app-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: .5rem;
  font-size: .7rem;
  color: var(--text3);
  z-index: 900;
}

/* ========================
   EMPTY STATE
======================== */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text3);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: .75rem; }
.empty-state p { font-size: .9rem; }

/* ========================
   RESPONSIVE
======================== */
@media (min-width: 480px) {
  .home-card.accent { grid-column: span 1; }
}

@media (max-width: 340px) {
  .home-grid { grid-template-columns: 1fr; }
  .home-card.accent { grid-column: span 1; }
}
