:root {
  --ink: #171c31;
  --muted: #697086;
  --line: #dde1ec;
  --soft: #f5f6fa;
  --surface: #ffffff;
  --green: #29304e;
  --green-dark: #171c31;
  --gold: #e8b94f;
  --red: #c53b3b;
  --orange: #b66a19;
  --shadow: 0 10px 30px rgba(23, 58, 51, .08);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #fff; font-family: "Tajawal", sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f8fbfa; }
.login-panel { width: min(430px, 100%); padding: 34px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 8px; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; color: var(--green-dark); border: 2px solid var(--gold); background: var(--gold); border-radius: 14px; font-size: 29px; font-weight: 800; }
.brand-mark svg { width: 29px; height: 29px; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 11px; font-size: 22px; }
.brand-mark.small svg { width: 23px; height: 23px; }
.eyebrow { margin: 24px 0 4px; color: var(--green); font-weight: 700; }
.login-panel h1 { margin: 0; font-size: 34px; }
.login-panel form { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 7px; color: #34423f; font-size: 14px; font-weight: 600; }
.input-wrap, .search-box { min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid var(--line); background: #fff; border-radius: 7px; }
.input-wrap:focus-within, .search-box:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23, 107, 93, .1); }
.input-wrap svg, .search-box svg { width: 19px; color: var(--green); }
input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
textarea, select { width: 100%; padding: 12px 13px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 7px; outline: none; resize: vertical; }
textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(41, 48, 78, .1); }

.button { min-height: 42px; display: inline-flex; justify-content: center; align-items: center; gap: 8px; padding: 0 15px; border: 1px solid transparent; border-radius: 7px; font-weight: 700; }
.button svg { width: 18px; }
.button.primary { color: #fff; background: var(--green); }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { color: var(--green); background: #fff; border-color: var(--line); }
.button.danger { color: #fff; background: var(--red); }
.button.compact { min-height: 34px; padding: 0 11px; font-size: 12px; }
.button:disabled { opacity: .55; cursor: wait; }
.form-error { margin: 0; padding: 10px; color: var(--red); background: #fff1f1; border: 1px solid #f3caca; border-radius: 6px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px 1fr; direction: rtl; }
.sidebar, .workspace { direction: rtl; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; color: #fff; background: var(--green-dark); }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; border-bottom: 1px solid rgba(255,255,255,.13); }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 20px; }
.sidebar-brand span { margin-top: 2px; color: #b9cbc7; font-size: 12px; }
.sidebar nav { display: grid; gap: 5px; margin-top: 20px; }
.nav-item { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 11px; padding: 0 12px; color: #d7e3e0; background: transparent; border: 0; border-radius: 6px; text-align: right; }
.nav-item svg { width: 19px; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.11); }
.nav-item .badge { margin-right: auto; min-width: 22px; height: 22px; display: grid; place-items: center; padding: 0 6px; color: #fff; background: var(--red); border-radius: 50%; font-size: 11px; }
.nav-item.logout { margin-top: auto; color: #ffc9c9; }

.workspace { min-width: 0; }
.topbar { height: 78px; display: flex; align-items: center; gap: 16px; padding: 0 28px; border-bottom: 1px solid var(--line); background: #fff; }
.topbar h2, .topbar p { margin: 0; }
.topbar h2 { font-size: 22px; }
.topbar p { margin-top: 3px; color: var(--muted); font-size: 13px; }
.admin-chip { margin-right: auto; display: flex; align-items: center; gap: 10px; }
.admin-chip > span { width: 38px; height: 38px; display: grid; place-items: center; color: #fff; background: var(--green); border-radius: 50%; font-weight: 800; }
.admin-chip strong, .admin-chip small { display: block; }
.admin-chip small { color: var(--muted); }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; color: var(--green); background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.icon-button svg { width: 19px; }
#menuButton { display: none; }
.content { padding: 26px 28px 50px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { min-height: 120px; padding: 16px; border: 1px solid var(--line); border-top: 3px solid var(--green); border-radius: 7px; background: #fff; }
.stat .stat-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.stat svg { width: 20px; color: var(--green); }
.stat strong { display: block; margin-top: 18px; font-size: 29px; }
.stat.warning { border-top-color: var(--orange); }
.stat.danger { border-top-color: var(--red); }
.stat.gold { border-top-color: var(--gold); }

.section-heading, .toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 28px 0 12px; }
.section-heading h3, .section-heading p { margin: 0; }
.section-heading h3 { font-size: 19px; }
.section-heading p { margin-top: 3px; color: var(--muted); font-size: 13px; }
.overview-columns { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 18px; }
.toolbar { margin-top: 0; }
.toolbar-tools { flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.search-box { width: min(520px, 100%); }
.segmented { display: inline-flex; padding: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 7px; }
.segmented button { min-height: 36px; padding: 0 16px; color: var(--muted); background: transparent; border: 0; border-radius: 5px; }
.segmented button.active { color: #fff; background: var(--green); }

.table-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.settings-panel { display: grid; gap: 18px; padding: 0 0 24px; }
.settings-panel.is-loading { opacity: .65; pointer-events: none; }
.settings-heading { margin-top: 0; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.price-grid { padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.field-input { min-height: 46px; padding: 0 13px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.field-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(41, 48, 78, .1); }
.payment-method-panel { padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.method-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.method-heading h4, .method-heading p { margin: 0; }
.method-heading h4 { font-size: 17px; }
.method-heading p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.toggle-label { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; white-space: nowrap; }
.toggle-label input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.switch-track { position: relative; display: inline-flex; width: 46px; height: 26px; flex: 0 0 46px; align-items: center; border: 1px solid #cbd4d1; border-radius: 999px; background: #dfe5e3; transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease; }
.switch-track > span { position: absolute; right: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(27, 35, 33, .22); transition: transform .2s ease; }
.toggle-label input:checked + .switch-track { border-color: var(--green); background: var(--green); }
.toggle-label input:checked + .switch-track > span { transform: translateX(-20px); }
.toggle-label input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(41, 48, 78, .16); }
.toggle-status { min-width: 46px; color: var(--muted); font-size: 12px; font-weight: 700; }
.toggle-status::before { content: attr(data-disabled); }
.toggle-label input:checked ~ .toggle-status { color: var(--green); }
.toggle-label input:checked ~ .toggle-status::before { content: attr(data-enabled); }
.settings-meta { margin: 0; color: var(--muted); font-size: 12px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: right; font-size: 13px; }
th { color: #4d5b58; background: var(--soft); font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfdfc; }
.project-cell strong, .project-cell span { display: block; }
.project-cell span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.pending, .status.trial, .status.ending-soon { color: var(--orange); background: #fff5e8; }
.status.approved, .status.active, .status.paid, .status.resolved { color: #16704f; background: #eaf6f2; }
.status.rejected, .status.expired, .status.suspended { color: var(--red); background: #fff0f0; }
.status.new, .status.in_progress { color: var(--orange); background: #fff5e8; }
.status.closed, .status.canceled { color: var(--muted); background: var(--soft); }
.count-pill { display: inline-flex; padding: 4px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.count-pill.warning { color: var(--orange); background: #fff5e8; }
.email-cell { direction: ltr; text-align: right; }
.message-preview { max-width: 290px; overflow: hidden; text-overflow: ellipsis; }
.status.visitor { background: #eeeaff; color: #6447db; vertical-align: middle; }
.result-count { margin: -4px 2px 10px; color: var(--muted); font-size: 13px; }
.table-actions { display: flex; align-items: center; gap: 6px; }
.table-actions .icon-button { width: 34px; height: 34px; }
.table-actions .approve { color: var(--green); }
.table-actions .reject { color: var(--red); }
.table-actions .archive { color: var(--orange); }
.table-actions .reactivate { color: var(--green); }
.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty-state svg { width: 34px; margin-bottom: 8px; color: var(--green); }
.loading { padding: 35px; text-align: center; color: var(--muted); }

dialog { width: min(760px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(14, 34, 30, .45); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h3, .dialog-head p { margin: 0; }
.dialog-head p { margin-top: 4px; color: var(--muted); }
.receipt-body { min-height: 260px; display: grid; place-items: center; padding: 18px; background: var(--soft); }
.receipt-body img { max-width: 100%; max-height: 68vh; object-fit: contain; background: #fff; border: 1px solid var(--line); }
.message-body { min-height: 150px; max-height: 42vh; overflow-y: auto; padding: 22px 20px; color: var(--ink); background: var(--soft); font-size: 16px; line-height: 1.9; white-space: pre-wrap; }
.dialog-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px; }
.dialog-form.single { grid-template-columns: 1fr; }
.dialog-form label small { color: var(--muted); font-weight: 400; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 20px; }
.toast { position: fixed; left: 24px; bottom: 24px; z-index: 20; max-width: 360px; padding: 12px 16px; color: #fff; background: var(--green-dark); border-radius: 7px; box-shadow: var(--shadow); }
.toast[data-tone="error"] { background: var(--red); }
.support-content { background: var(--soft); }
.detail-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; padding: 0 20px 20px; }
.detail-list div { min-width: 0; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 7px; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 4px 0 0; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .overview-columns { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; right: 0; z-index: 10; width: 250px; transform: translateX(105%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  #menuButton { display: grid; }
  .topbar { padding: 0 15px; }
  .admin-chip div { display: none; }
  .content { padding: 18px 14px 40px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .section-heading, .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-tools { width: 100%; }
  .toolbar .icon-button, .section-heading .icon-button { align-self: flex-end; }
  .dialog-form { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-heading .button { align-self: stretch; }
  .detail-list { grid-template-columns: 1fr; }
  .workspaces-toolbar { align-items: stretch; }
  .segmented.scrollable { max-width: 100%; overflow-x: auto; }
}
@media (max-width: 470px) {
  .stats-grid { grid-template-columns: 1fr; }
  .login-panel { padding: 25px 20px; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 0 8px; }
}
