/* ============================================================
   سندس للدهانات — نظام تصميم مشترك (RTL)
   هوية بصرية: أبيض ناصع (خلفية دافئة قريبة من البياض)
   + أخضر بحري هادئ (نظافة/رطوبة) + عنبري دافئ (صبغات الدهان)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

:root {
  --bg: #F7F5F1;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --ink: #21231F;
  --muted: #6B6D63;
  --border: #E4E1D8;

  --primary: #1F6F63;
  --primary-dark: #154F46;
  --primary-tint: #E4F1EE;

  --warm: #C98A3B;
  --warm-tint: #FBF0DF;

  --danger: #B3492F;
  --danger-tint: #FBEAE4;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(33,35,31,.06), 0 1px 1px rgba(33,35,31,.04);
  --font: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  direction: rtl;
  text-align: right;
  font-size: 15px;
  line-height: 1.6;
}

body { min-height: 100vh; }

h1, h2, h3, h4 { font-weight: 700; margin: 0 0 .4em; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .6em; }
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.nums { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- تخطيط عام للوحة الإدارة ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.sidebar .brand .logo-dot { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); flex-shrink: 0; display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700; }
.sidebar .brand div b { display: block; font-size: .95rem; }
.sidebar .brand div span { font-size: .72rem; color: var(--muted); }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink); font-size: .9rem; font-weight: 500;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--primary-tint); color: var(--primary-dark); }
.nav-link .ic { width: 18px; text-align: center; opacity: .85; }

.main { flex: 1; min-width: 0; padding: 20px 26px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.topbar h1 { margin: 0; }

/* شريط جوال سفلي بديل عن القائمة الجانبية */
.mobile-topbar { display: none; }
.mobile-nav { display: none; }

@media (max-width: 880px) {
  .sidebar { display: none; }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
  }
  .main { padding: 14px 14px 76px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom,0px));
  }
  .mobile-nav a { flex:1; text-align:center; font-size: .68rem; color: var(--muted); padding: 5px 2px; border-radius: 8px; }
  .mobile-nav a.active { color: var(--primary-dark); background: var(--primary-tint); }
  .mobile-nav .ic { display:block; font-size: 1.15rem; margin-bottom: 2px; }
}

/* ---------- عناصر عامة ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; border-right: 4px solid var(--primary);
}
.stat-card.warm { border-right-color: var(--warm); }
.stat-card.danger { border-right-color: var(--danger); }
.stat-card .label { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.stat-card .value { font-size: 1.35rem; font-weight: 700; }
.stat-card .value.small { font-size: 1.05rem; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 880px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; font-size: .89rem; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content:center;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-family: var(--font); font-size: .88rem; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #8f3a24; }
.btn.ghost { background: transparent; color: var(--primary-dark); padding: 6px 8px; }
.btn.sm { padding: 6px 11px; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .74rem; font-weight: 600; }
.badge.green { background: var(--primary-tint); color: var(--primary-dark); }
.badge.warm { background: var(--warm-tint); color: #8a5a1f; }
.badge.red { background: var(--danger-tint); color: var(--danger); }
.badge.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: var(--font); font-size: .9rem; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.field { margin-bottom: 13px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 12px; }
.hint { font-size: .76rem; color: var(--muted); margin-top: 4px; }
.error-text { font-size: .8rem; color: var(--danger); margin-top: 4px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(33,35,31,.45); display:flex; align-items:center; justify-content:center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); padding: 20px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal.wide { max-width: 760px; }

.toast-stack { position: fixed; bottom: 16px; left: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-size: .86rem; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary-dark); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .ic { font-size: 2rem; margin-bottom: 8px; }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.offline-banner {
  display: none; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--warm-tint); color: #7a5423; border: 1px solid #ecd8b0;
  padding: 9px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .85rem;
}
.offline-banner.show { display: flex; }

.search-box { position: relative; }
.search-results {
  position: absolute; top: calc(100% + 4px); right: 0; left: 0; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto; z-index: 40;
}
.search-results .item { padding: 9px 11px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: .87rem; }
.search-results .item:last-child { border-bottom: none; }
.search-results .item:hover { background: var(--surface-2); }
.search-results .item small { color: var(--muted); display:block; font-size: .74rem; }

/* ---------- صفحة تسجيل الدخول ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 30px 26px; box-shadow: var(--shadow); }
.login-card .logo-dot { width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); display:flex; align-items:center; justify-content:center; color:#fff; font-weight:700; font-size:1.3rem; margin: 0 auto 14px; }
.login-card h1 { text-align:center; }
.login-card .sub { text-align:center; color: var(--muted); font-size: .85rem; margin-bottom: 20px; }

/* ---------- صفحة العميل العامة ---------- */
.portal-hero {
  background: linear-gradient(160deg, var(--primary-dark), var(--primary));
  color: #fff; padding: 26px 20px 56px; border-radius: 0 0 22px 22px;
}
.portal-hero .store { font-size: .82rem; opacity: .85; margin-bottom: 6px; }
.portal-wrap { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; }
.portal-card { margin-top: -38px; }
.portal-balance { text-align: center; padding: 6px 0 14px; }
.portal-balance .amount { font-size: 2rem; font-weight: 700; }
.portal-balance .amount.zero { color: var(--primary-dark); }
.portal-balance .amount.owe { color: var(--danger); }
.workshop-chip { display:flex; justify-content:space-between; align-items:center; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; }
.workshop-chip .name { font-weight: 600; }
.invoice-row { display:flex; justify-content:space-between; align-items:center; padding: 11px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.invoice-row:last-child { border-bottom: none; }
.invoice-row:hover { background: var(--surface-2); }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .card, .portal-card { box-shadow: none; border: none; }
}
