/* Fan & Ibdaa department system — RTL, mobile first */
:root {
  --bg: #f5f2ec;
  --card: #ffffff;
  --ink: #1d1a16;
  --muted: #6f675d;
  --line: #e6dfd3;
  --doors: #9a5b25;
  --doors-soft: #f6eadf;
  --furn: #1f6f68;
  --furn-soft: #e0f0ee;
  --shared: #6b6b8a;
  --review: #c2410c;
  --review-soft: #fff1e8;
  --ok: #15803d;
  --bad: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(29, 26, 22, .06), 0 4px 16px rgba(29, 26, 22, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--furn); }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
code { background: #eee; padding: 0 .3em; border-radius: 4px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: left; }
.hidden { display: none !important; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 230px; background: var(--ink); color: #f4efe6; padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 1.05rem; margin-bottom: 18px; }
.brand small { display: block; font-weight: 400; color: #b9b0a2; font-size: .8rem; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: #e9e2d6; text-decoration: none;
  padding: 9px 12px; border-radius: 10px; font-weight: 500;
}
.nav a.on, .nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav .badge { margin-inline-start: auto; }
.side .me { margin-top: auto; font-size: .85rem; color: #b9b0a2; }
.main { flex: 1; min-width: 0; padding: 22px; max-width: 1200px; }
.topbar { display: none; }
.bottomnav { display: none; }

@media (max-width: 860px) {
  .side { display: none; }
  .main { padding: 14px 12px 90px; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; background: var(--ink); color: #fff;
    padding: 12px 14px; position: sticky; top: 0; z-index: 20;
  }
  .topbar .brand { margin: 0; font-size: 1rem; }
  .bottomnav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; inset-inline: 0;
    background: #fff; border-top: 1px solid var(--line); z-index: 30; padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a {
    text-align: center; padding: 8px 2px 6px; font-size: .72rem; color: var(--muted); text-decoration: none; position: relative;
  }
  .bottomnav a .ico { display: block; font-size: 1.25rem; line-height: 1.2; }
  .bottomnav a.on { color: var(--ink); font-weight: 600; }
  .bottomnav .badge { position: absolute; top: 4px; inset-inline-end: 18%; }
  .shell { display: block; }
}

/* Cards & grids */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.narrow { max-width: 640px; margin: 30px auto; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 8px; }
@media (max-width: 860px) {
  .g2, .g3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: 1fr; }
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

/* Department cards */
.dept { border-top: 5px solid var(--doors); }
.dept.furniture { border-top-color: var(--furn); }
.dept .head { display: flex; justify-content: space-between; align-items: baseline; }
.dept .net { font-size: 1.7rem; font-weight: 700; }
.dept .net.neg { color: var(--bad); }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv.total { font-weight: 700; border-bottom: 0; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.stat { text-align: center; }
.stat .v { font-size: 1.35rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .82rem; }
.share-bar { height: 12px; border-radius: 999px; overflow: hidden; display: flex; background: var(--line); margin: 6px 0; }
.share-bar span:first-child { background: var(--doors); }
.share-bar span:last-child { background: var(--furn); }

/* Pills / badges */
.pill { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.pill.doors { background: var(--doors-soft); color: var(--doors); }
.pill.furniture { background: var(--furn-soft); color: var(--furn); }
.pill.shared { background: #ececf4; color: var(--shared); }
.pill.review { background: var(--review-soft); color: var(--review); }
.pill.income { background: #e7f6ec; color: var(--ok); }
.pill.expense { background: #fdeaea; color: var(--bad); }
.pill.by { background: #f1efe9; color: var(--muted); font-weight: 500; }
.badge { background: var(--review); color: #fff; border-radius: 999px; font-size: .7rem; padding: 0 7px; font-weight: 700; }

/* Forms */
label { display: block; font-size: .86rem; color: var(--muted); margin-bottom: 10px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; margin-top: 3px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c9a27a; border-color: transparent; }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox] { width: auto; margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 10px; padding: 9px 16px;
  cursor: pointer; text-decoration: none; min-height: 42px;
}
.btn:hover { border-color: #cfc5b5; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: wait; }
.tabs { display: flex; gap: 6px; background: #ebe5da; border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.tabs button {
  flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600; padding: 9px; border-radius: 9px; cursor: pointer; color: var(--muted);
}
.tabs button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.drop {
  border: 2px dashed #cfc5b5; border-radius: var(--radius); padding: 28px 14px; text-align: center; color: var(--muted);
  cursor: pointer; background: #fbf9f5;
}
.drop.over { background: var(--doors-soft); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: right; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
td input, td select { margin: 0; padding: 6px 8px; }
td select { min-width: 105px; }

/* Draft editor lines */
.line {
  display: grid; grid-template-columns: 2.2fr 1fr 1.1fr 1.1fr auto; gap: 8px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: #fff;
}
.line.review { border-color: #f3b58f; background: var(--review-soft); }
.line input, .line select { margin: 0; }
.line .learn { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; font-size: .82rem; color: var(--muted); }
.line .learn input[type=text] { max-width: 260px; padding: 5px 8px; }
@media (max-width: 860px) {
  .line { grid-template-columns: 1fr 1fr; }
  .line .desc { grid-column: 1 / -1; }
}
.sumbar { display: flex; justify-content: space-between; align-items: center; font-weight: 700; padding: 10px 2px; }

/* Lists */
.txn { display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.txn:hover { background: #faf8f4; }
.txn .body { flex: 1; min-width: 0; }
.txn .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn .amt { font-weight: 700; white-space: nowrap; }
.txn .amt.income { color: var(--ok); }

/* Alerts & toast */
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; }
.alert.ok { background: #e7f6ec; color: var(--ok); }
.alert.err { background: #fdeaea; color: var(--bad); }
.alert.warn { background: var(--review-soft); color: var(--review); }
.alert.info { background: #eef3f8; color: #284b6b; }
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 12px; z-index: 100; box-shadow: var(--shadow); max-width: 92vw;
}
#toast.err { background: var(--bad); }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(20, 18, 15, .45); z-index: 60; display: flex; align-items: flex-start;
  justify-content: center; padding: 5vh 10px; overflow-y: auto;
}
.modal { background: #fff; border-radius: var(--radius); padding: 18px; width: 100%; max-width: 860px; }
.modal img.inv { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }

/* Login */
.login { max-width: 380px; margin: 14vh auto; }
.login .logo { font-size: 2.2rem; text-align: center; }
.install { padding: 10px; }

.chart-box { position: relative; height: 280px; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
