/* إصلاح مهم: يضمن أن أي عنصر عليه السمة hidden يختفي فعلياً بغض النظر عن قواعد display الأخرى */
[hidden] { display: none !important; }

:root {
  --gold: #8A6D2E;
  --gold-light: #C9A227;
  --black: #1A1A1A;
  --bg: #F5F3EE;
  --surface: #FFFFFF;
  --text: #1A1A1A;
  --text-muted: #6b6b6b;
  --border: #E0DCD0;
  --danger: #B03A2E;
  --success: #2E7D32;
  --warning: #B8860B;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #14140f;
  --surface: #1f1e17;
  --text: #EDE8DA;
  --text-muted: #a89f8a;
  --border: #33301f;
  --gold: #C9A227;
  --gold-light: #E0BE4D;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  direction: rtl;
}

body { font-size: 15px; transition: background .2s, color .2s; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

a { color: var(--gold); }

#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 40px; width: 100%; max-width: 380px; text-align: center; border-top: 4px solid var(--gold);
}
.login-card h1 { font-size: 20px; margin-bottom: 4px; color: var(--gold); }
.login-card p.subtitle { color: var(--text-muted); margin-top: 0; margin-bottom: 24px; font-size: 13px; }
.emblem { font-size: 42px; margin-bottom: 10px; }
.field { text-align: right; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--text-muted); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.btn {
  display: inline-block; padding: 10px 20px; border-radius: 8px; border: none;
  background: var(--gold); color: #fff; cursor: pointer; font-weight: bold;
}
.btn:hover { background: var(--gold-light); }
.btn.secondary { background: transparent; border: 1px solid var(--gold); color: var(--gold); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.error-msg { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

#app-screen { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; background: var(--black); color: #EDE8DA; flex-shrink: 0;
  padding: 18px 0; display: flex; flex-direction: column;
}
[data-theme="dark"] .sidebar { background: #0c0c09; }
.sidebar .brand { text-align: center; padding: 0 16px 18px; border-bottom: 1px solid #333; margin-bottom: 10px; }
.sidebar .brand .emblem { font-size: 34px; }
.sidebar .brand h2 { font-size: 15px; margin: 6px 0 2px; color: var(--gold-light); }
.sidebar .brand small { color: #999; font-size: 11px; }
.nav-item {
  padding: 12px 20px; cursor: pointer; color: #cfcabb; border-right: 3px solid transparent;
  display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.nav-item:hover { background: rgba(255,255,255,0.06); }
.nav-item.active { border-right-color: var(--gold-light); color: var(--gold-light); background: rgba(255,255,255,0.06); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .title { font-size: 17px; font-weight: bold; }
.topbar .user-box { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); display: inline-block; margin-left: 4px; }

.content { padding: 22px 26px; overflow-y: auto; flex: 1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card h3 { margin-top: 0; color: var(--gold); font-size: 16px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 20px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-box .num { font-size: 26px; font-weight: bold; color: var(--gold); }
.stat-box .label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: right; }
th { color: var(--text-muted); font-weight: 600; background: rgba(0,0,0,0.02); }
[data-theme="dark"] th { background: rgba(255,255,255,0.03); }
tr:hover td { background: rgba(0,0,0,0.02); }
[data-theme="dark"] tr:hover td { background: rgba(255,255,255,0.03); }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.toolbar input[type=search] { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); min-width: 220px; }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; display: inline-block; }
.badge.ok { background: rgba(46,125,50,0.15); color: var(--success); }
.badge.pending { background: rgba(184,134,11,0.15); color: var(--warning); }
.badge.reject { background: rgba(176,58,46,0.15); color: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal h3 { margin-top: 0; color: var(--gold); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

.switch { position: relative; display: inline-block; width: 42px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #999; border-radius: 22px; transition: .2s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; right: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s; }
input:checked + .slider { background: var(--gold); }
input:checked + .slider:before { transform: translateX(-20px); }

.loader { display: flex; align-items: center; justify-content: center; padding: 40px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--border); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 20px; left: 20px; background: var(--black); color: #fff;
  padding: 12px 18px; border-radius: 8px; box-shadow: var(--shadow); z-index: 100;
  border-right: 4px solid var(--gold-light);
}

.empty-state { text-align: center; padding: 40px; color: var(--text-muted); }
.config-warning { background: #B03A2E; color: #fff; padding: 10px 16px; text-align: center; font-size: 13px; }

@media (max-width: 800px) {
  #app-screen { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; padding: 10px; }
  .sidebar .brand { display: none; }
  .nav-item { white-space: nowrap; border-right: none; border-bottom: 3px solid transparent; }
  .nav-item.active { border-bottom-color: var(--gold-light); }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
