/* ميزان الماء — نظام التصميم (RTL, IBM Plex Sans Arabic) */
:root {
  --bg: #f2f6f8;
  --card: #ffffff;
  --ink: #142230;
  --muted: #5d6f7d;
  --line: #dfe7ec;
  --line-2: #eef2f5;
  --primary: #0e6e8c;
  --primary-2: #0a5169;
  --primary-soft: #e4f2f7;
  --accent: #1c8f52;
  --accent-soft: #e3f5ea;
  --warn: #c8710a;
  --warn-soft: #fdf1e0;
  --danger: #c23b2b;
  --danger-soft: #fbe7e4;
  --info: #2457c5;
  --info-soft: #e6edfb;
  --solar: #d99a06;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 34, 48, .05), 0 4px 16px rgba(20, 34, 48, .06);
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  line-height: 1.55; min-height: 100vh; padding-bottom: 72px;
}
@media (min-width: 900px) { body { padding-bottom: 32px; } }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 700; line-height: 1.3; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.tiny { font-size: .78rem; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.nowrap { white-space: nowrap; }
.tc { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; }
.grow { flex: 1; }

/* ---------- الهيكل ---------- */
#app-header {
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #fff; padding: .6rem 1rem; position: sticky; top: 0; z-index: 30;
  box-shadow: 0 2px 10px rgba(10, 81, 105, .25);
}
.hdr-in { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: .8rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; color: #fff; }
.brand svg { width: 28px; height: 28px; }
.brand small { display: block; font-weight: 400; font-size: .72rem; opacity: .85; line-height: 1.1; }
.user-chip {
  margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; background: rgba(255, 255, 255, .14);
  padding: .3rem .7rem .3rem .4rem; border-radius: 999px; font-size: .85rem; color: #fff; max-width: 60%;
}
.user-chip .avatar { width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--primary-2); display: grid; place-items: center; font-weight: 700; flex: none; }
.user-chip .who { line-height: 1.15; overflow: hidden; }
.user-chip .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .who span { font-size: .72rem; opacity: .85; }
.btn-logout { background: transparent; border: 0; color: #fff; cursor: pointer; padding: .25rem; border-radius: 8px; display: grid; place-items: center; }
.btn-logout:hover { background: rgba(255, 255, 255, .2); }
.btn-logout svg { width: 20px; height: 20px; }

#app-nav { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 52px; z-index: 25; }
#app-nav ul { list-style: none; margin: 0 auto; padding: 0 .5rem; max-width: 1200px; display: flex; gap: .15rem; overflow-x: auto; }
#app-nav a { display: flex; align-items: center; gap: .4rem; padding: .7rem .9rem; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 3px solid transparent; font-size: .95rem; }
#app-nav a svg { width: 18px; height: 18px; }
#app-nav a.active { color: var(--primary); border-bottom-color: var(--primary); }
#app-nav a:hover { text-decoration: none; color: var(--primary); }
#app-nav .badge { margin-inline-start: .2rem; }
@media (max-width: 899px) {
  #app-nav { position: fixed; top: auto; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--line); border-bottom: 0; box-shadow: 0 -2px 10px rgba(20, 34, 48, .08); }
  #app-nav ul { justify-content: space-around; gap: 0; padding: 0; }
  #app-nav a { flex-direction: column; gap: .15rem; padding: .45rem .3rem; font-size: .68rem; border-bottom: 0; border-top: 3px solid transparent; flex: 1; text-align: center; }
  #app-nav a.active { border-top-color: var(--primary); }
  #app-nav a svg { width: 22px; height: 22px; }
}

.container { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.page-head { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- البطاقات ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card + .card { margin-top: 1rem; }
.card-title { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.card-title h2 { font-size: 1rem; }
.card-title .actions { margin-inline-start: auto; display: flex; gap: .4rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-kpi { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 700px) { .grid-kpi { grid-template-columns: repeat(4, 1fr); } }
.grid-eq { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
@media (min-width: 600px) { .grid-eq { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .grid-eq { grid-template-columns: repeat(7, 1fr); } }

.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; position: relative; overflow: hidden; }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi .value { font-size: 1.5rem; font-weight: 700; margin-top: .15rem; line-height: 1.2; }
.kpi .value small { font-size: .8rem; font-weight: 500; color: var(--muted); margin-inline-start: .2rem; }
.kpi .sub { font-size: .78rem; color: var(--muted); margin-top: .25rem; }
.kpi.main { background: linear-gradient(135deg, #14713f, var(--accent)); color: #fff; }
.kpi.main .label, .kpi.main .sub, .kpi.main .value small { color: rgba(255, 255, 255, .85); }
.kpi.main .value { font-size: 1.9rem; }
.kpi::after { content: ''; position: absolute; inset-inline-end: -20px; top: -20px; width: 80px; height: 80px; border-radius: 50%; background: currentColor; opacity: .05; }
.eq { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: .6rem .7rem; text-align: center; }
.eq .value { font-weight: 700; font-size: 1.1rem; }
.eq .label { font-size: .72rem; color: var(--muted); }

/* شريط الميزان المائي */
.balance-bar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; background: var(--line-2); margin: .6rem 0; }
.balance-bar > div { min-width: 2px; transition: width .4s; }
.balance-bar .b-active { background: var(--accent); }
.balance-bar .b-planned { background: #7cc4a5; }
.balance-bar .b-bought { background: #c8d3da; }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-inline-end: .3rem; vertical-align: -1px; }

/* ---------- الشارات ---------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: var(--line-2); color: var(--muted); white-space: nowrap; }
.badge.ok, .badge.active, .badge.suitable, .badge.improvement { background: var(--accent-soft); color: var(--accent); }
.badge.warn, .badge.paused, .badge.overdue, .badge.overuse, .badge.high, .badge.conditional { background: var(--warn-soft); color: var(--warn); }
.badge.danger, .badge.leak, .badge.no_flow, .badge.critical, .badge.unsuitable, .badge.zero { background: var(--danger-soft); color: var(--danger); }
.badge.info, .badge.planned, .badge.low, .badge.first { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge.solar { background: #fff4d6; color: #9a6b00; }
.badge.dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- الأزرار والنماذج ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap; }
.btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c7c2; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: .3rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.lg { padding: .8rem 1.2rem; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-icon { padding: .35rem; border-radius: 8px; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .8rem; }
.field label { font-size: .85rem; font-weight: 600; color: var(--ink); }
.field .hint { font-size: .75rem; color: var(--muted); }
.field.error input, .field.error select, .field.error textarea { border-color: var(--danger); }
.field .err { font-size: .78rem; color: var(--danger); }
input, select, textarea {
  font: inherit; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type="number"], input[type="datetime-local"], input[type="date"] { direction: ltr; text-align: right; }
input.big { font-size: 1.7rem; font-weight: 700; padding: .7rem .9rem; text-align: center; letter-spacing: .02em; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; }
.form-row { display: grid; gap: 0 .8rem; grid-template-columns: 1fr; }
@media (min-width: 600px) { .form-row { grid-template-columns: 1fr 1fr; } .form-row.three { grid-template-columns: 1fr 1fr 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .9rem .2rem; margin: 0 0 .9rem; }
legend { font-size: .82rem; font-weight: 600; color: var(--muted); padding: 0 .4rem; }

/* ---------- الجداول ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; background: #fff; }
th, td { padding: .55rem .7rem; text-align: right; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { background: #f7fafb; color: var(--muted); font-weight: 600; font-size: .78rem; white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbfc; }
td .who b { display: block; }
td .who span { color: var(--muted); font-size: .76rem; direction: ltr; unicode-bidi: isolate; }
.tr-late td { background: #fffaf3; }

/* ---------- التنبيهات والتوست ---------- */
.alert-item { display: flex; gap: .7rem; padding: .7rem .8rem; border-radius: 10px; border: 1px solid var(--line); background: #fff; align-items: flex-start; }
.alert-item + .alert-item { margin-top: .5rem; }
.alert-item .sev { width: 6px; align-self: stretch; border-radius: 4px; background: var(--warn); flex: none; }
.alert-item.critical .sev { background: var(--danger); }
.alert-item.info .sev { background: var(--info); }
.alert-item .body { flex: 1; min-width: 0; }
.alert-item .meta { font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.alert-item.resolved { opacity: .7; }
.note { padding: .7rem .9rem; border-radius: 10px; font-size: .88rem; border: 1px solid; }
.note.warn { background: var(--warn-soft); border-color: #f2d7b2; color: #7a4508; }
.note.danger { background: var(--danger-soft); border-color: #f1c7c2; color: #7d2419; }
.note.info { background: var(--info-soft); border-color: #c4d3f4; color: #1c3f8f; }
.note.ok { background: var(--accent-soft); border-color: #bfe6cf; color: #145f38; }
#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: .4rem; align-items: center; pointer-events: none; }
@media (min-width: 900px) { #toast { bottom: 24px; } }
.toast { background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; box-shadow: var(--shadow); animation: fade .25s; max-width: 90vw; }
.toast.ok { background: var(--accent); } .toast.danger { background: var(--danger); }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

/* ---------- النوافذ ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 30, 45, .5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
@media (min-width: 700px) { .modal-bg { align-items: center; padding: 1rem; } }
.modal { background: #fff; width: 100%; max-width: 680px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 1rem; animation: up .2s; }
@media (min-width: 700px) { .modal { border-radius: 16px; } }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; }
.modal-head h2 { flex: 1; }
.modal-foot { display: flex; gap: .5rem; justify-content: flex-start; margin-top: 1rem; flex-wrap: wrap; }

/* ---------- عناصر متنوعة ---------- */
.site-card { display: flex; flex-direction: column; gap: .5rem; }
.site-card .head { display: flex; align-items: flex-start; gap: .5rem; }
.site-card .head h3 { flex: 1; font-size: 1.02rem; }
.site-card .badges { display: flex; flex-wrap: wrap; gap: .3rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.stats div { background: #f7fafb; border-radius: 8px; padding: .4rem .5rem; }
.stats .l { font-size: .68rem; color: var(--muted); }
.stats .v { font-weight: 700; font-size: .95rem; }
.last-read { font-size: .8rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: .5rem; }
.last-read b { color: var(--ink); }
.site-card .foot { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: auto; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: .82rem; cursor: pointer; font-weight: 500; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filters { display: grid; gap: .6rem; grid-template-columns: 1fr; align-items: end; }
@media (min-width: 700px) { .filters { grid-template-columns: 2fr 1fr 1fr auto auto; } }
.filters .field { margin: 0; }
.chart-box { position: relative; height: 300px; }
.chart-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; text-align: center; color: var(--muted); font-size: .88rem; padding: 1rem; background: repeating-linear-gradient(45deg, #fbfcfd, #fbfcfd 10px, #f6f8fa 10px, #f6f8fa 20px); border-radius: 10px; }
.chart-empty b { color: var(--ink); font-size: .95rem; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 260px; }
.preview { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.preview div { background: #f7fafb; border-radius: 10px; padding: .5rem .7rem; }
.preview .l { font-size: .72rem; color: var(--muted); }
.preview .v { font-weight: 700; font-size: 1.05rem; }
.big-read { text-align: center; padding: .6rem 0; }
.big-read .v { font-size: 2rem; font-weight: 700; color: var(--primary); }
.big-read .m { font-size: .8rem; color: var(--muted); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, var(--primary-2), var(--primary) 60%, #1a8fa8); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 18px; padding: 1.6rem 1.4rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.login-card .logo { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem; }
.login-card .logo svg { width: 40px; height: 40px; color: var(--primary); }
.sticky-save { position: sticky; bottom: 76px; background: linear-gradient(transparent, var(--bg) 30%); padding-top: .8rem; }
@media (min-width: 900px) { .sticky-save { bottom: 0; } }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff; border-radius: 50%; animation: rot .8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .88rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; }
.progress { height: 8px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media print { #app-header, #app-nav, .btn, .filters { display: none !important; } body { background: #fff; padding: 0; } .card { box-shadow: none; border: 1px solid var(--line); } }
