:root {
  --brown-900: #2e2118;
  --brown-800: #3e2c1e;
  --brown-700: #6b4a2f;
  --coffee: #8a6b4f;
  --gold: #b98b3f;
  --gold-soft: #d9c494;
  --bg: #f4efe6;
  --card: #fffdf8;
  --line: #e4d9c6;
  --text: #2e2118;
  --muted: #8a6b4f;
  --danger: #b3402c;
  --ok: #2e7d4f;
  --radius: 10px;
  --shadow: 0 6px 20px rgba(46, 33, 24, .08);
}

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

body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--brown-700); }

button {
  font-family: inherit;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  min-height: 40px;
  transition: opacity .15s, background .15s;
  background: var(--brown-700);
  color: #fff;
}
button:hover { opacity: .9; }
button.ghost { background: transparent; color: var(--brown-700); border: 1px solid var(--line); }
button.danger { background: var(--danger); }
button.small { padding: 6px 10px; min-height: 32px; font-size: 12px; }
button:disabled { opacity: .45; cursor: not-allowed; }

a, button, .dropzone, .chip { -webkit-tap-highlight-color: transparent; }
a, button, input, select, textarea { touch-action: manipulation; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 4px; color: var(--brown-800); }

/* ===== التخطيط العام ===== */
.layout { display: flex; min-height: 100vh; min-height: 100svh; }

.sidebar {
  width: 230px;
  background: var(--brown-900);
  color: #efe6d8;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-inline-start: 0;
  inset-block: 0;
  z-index: 50;
  transition: transform .25s ease;
}
.sidebar .brand {
  padding: 18px;
  font-size: 17px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: var(--gold-soft); margin-top: 3px; }
.sidebar nav { flex: 1; padding: 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  margin-bottom: 3px;
  color: #d9cbb6;
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(185,139,63,.18); color: #ffe9bf; }
.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 11px; color: #a89377; }

.main { flex: 1; margin-inline-start: 230px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  height: 60px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar h1 { font-size: 17px; flex: 1; }
.topbar .user { font-size: 13px; color: var(--muted); }
.burger { display: none; background: transparent; color: var(--brown-800); padding: 0; width: 44px; height: 44px; min-height: 44px; font-size: 22px; line-height: 1; }

.content { padding: 24px; max-width: 1000px; width: 100%; margin: 0 auto; }

/* ===== بطاقات / لوحة ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border-inline-start: 4px solid var(--gold); }
.stat .num { font-size: 28px; font-weight: 700; color: var(--brown-800); }
.stat .lbl { font-size: 13px; color: var(--muted); margin-top: 4px; }
.quick { display: flex; flex-wrap: wrap; gap: 10px; }

.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px; }
.panel h2 { font-size: 16px; margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .row { grid-template-columns: 1fr; } }

.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* ===== قوائم ===== */
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.list-item .grip { color: #c9bb a4; color: #cbb99e; cursor: grab; font-size: 16px; }
.list-item .thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--bg); flex-shrink: 0; }
.list-item .ico { width: 40px; height: 40px; border-radius: 8px; background: #f0e8da; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.list-item .ico svg { width: 22px; height: 22px; color: var(--brown-700); }
.list-item .meta { flex: 1; min-width: 0; }
.list-item .meta b { display: block; font-size: 14px; }
.list-item .meta span { font-size: 12px; color: var(--muted); }
.list-item .acts { display: flex; gap: 6px; flex-wrap: wrap; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.pill.on { background: #e2f2e6; color: var(--ok); }
.pill.off { background: #fbe9e7; color: var(--danger); }
.tag { display: inline-block; background: #f0e8da; color: var(--brown-700); border-radius: 6px; padding: 2px 8px; font-size: 11px; margin-inline-end: 4px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

/* ===== تسجيل الدخول ===== */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100svh; padding: 20px; }
.login-card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); width: 380px; max-width: 100%; padding: 34px; border-top: 4px solid var(--gold); }
.login-card h1 { font-size: 20px; text-align: center; color: var(--brown-800); }
.login-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 6px 0 22px; }
.login-card .brand-mark {
  width: 62px; height: 62px; margin: 0 auto 14px;
  background: var(--brown-800); color: var(--gold-soft);
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 700;
}

/* ===== الإشعارات ===== */
#toasts { position: fixed; inset-block-start: 16px; inset-inline-end: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--brown-800); color: #fff;
  padding: 12px 18px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow); animation: slideIn .25s ease;
  max-width: 320px;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ===== النافذة المنبثقة ===== */
#modal { display: none; position: fixed; inset: 0; background: rgba(30,20,10,.55); z-index: 150; align-items: center; justify-content: center; padding: 16px; }
#modal.open { display: flex; }
.modal-card { background: var(--card); border-radius: 12px; width: 480px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal-card h3 { font-size: 16px; margin-bottom: 16px; }

/* ===== الرفع ===== */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: #fbf8f1;
}
.dropzone.drag { border-color: var(--gold); background: #f5eedd; }
.dropzone b { color: var(--brown-700); }

/* ===== التنقل للجوال ===== */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(30,20,10,.45);
  z-index: 45;
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; }
  .main { margin-inline-start: 0; }
  .burger { display: inline-flex; }
  .content { padding: 16px; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 10px; }
  .topbar .user { display: none; }
  .content { padding: 14px; }

  .list-item { flex-wrap: wrap; row-gap: 8px; }
  .list-item .meta { flex-basis: calc(100% - 68px); }
  .list-item .acts { width: 100%; justify-content: flex-end; }
  .acts button { flex: 1 1 0; padding: 10px 4px; min-height: 42px; }

  .modal-card { padding: 18px 14px; }
  .stat .num { font-size: 24px; }
  .dropzone { padding: 20px 14px; }
  #toasts { inset-inline: 12px; }
  .toast { max-width: none; }
}

[hidden] { display: none !important; }
.loading { text-align: center; color: var(--muted); padding: 30px; }