:root {
  --bg: #0b1020;
  --surface: #121a2e;
  --surface-2: #17223a;
  --surface-3: #1d2944;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f6f8ff;
  --muted: #9ba8c7;
  --primary: #7c8cff;
  --primary-strong: #6374f4;
  --positive: #65d7a3;
  --warning: #ffca70;
  --danger: #ff7d8d;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(124, 140, 255, 0.16), transparent 33%),
    radial-gradient(circle at 100% 25%, rgba(101, 215, 163, 0.08), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

[hidden] { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: rgba(18, 26, 46, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  border-radius: 16px;
  background: linear-gradient(145deg, var(--primary), #b27cff);
  color: white;
  font-weight: 900;
  letter-spacing: -0.05em;
  box-shadow: 0 14px 34px rgba(124, 140, 255, 0.35);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(1.65rem, 3vw, 2.25rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 8px; font-size: clamp(1.4rem, 2vw, 1.85rem); letter-spacing: -0.03em; }
h3 { margin-bottom: 6px; }

.eyebrow {
  margin-bottom: 7px;
  color: var(--primary);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.muted { color: var(--muted); line-height: 1.6; }

.stack-form { display: grid; gap: 17px; margin-top: 28px; }

label {
  display: grid;
  gap: 8px;
  color: #c7d0e7;
  font-size: 0.86rem;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  min-height: 45px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background: rgba(5, 10, 23, 0.54);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: #697695; }
input:focus, select:focus, textarea:focus {
  border-color: rgba(124, 140, 255, 0.8);
  background: rgba(5, 10, 23, 0.72);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.14);
}

.button {
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: var(--text);
  font-weight: 800;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease, border-color 150ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: not-allowed; opacity: 0.55; transform: none; }
.button.primary { background: linear-gradient(135deg, var(--primary), var(--primary-strong)); }
.button.secondary { border-color: var(--line); background: var(--surface-3); }
.button.ghost { border-color: var(--line); background: transparent; }
.button.danger { border-color: rgba(255, 125, 141, 0.34); background: rgba(255, 125, 141, 0.1); color: #ffb6bf; }
.button.small { min-height: 34px; padding: 7px 10px; font-size: 0.78rem; }
.button.full { width: 100%; }

.form-error { margin: 0; color: var(--danger); font-size: 0.88rem; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px clamp(18px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 16, 32, 0.88);
  backdrop-filter: blur(16px);
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.topbar .eyebrow { margin-bottom: 3px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.user-chip {
  display: grid;
  min-width: 130px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}
.user-chip strong { font-size: 0.84rem; }
.user-chip span { color: var(--muted); font-size: 0.72rem; text-transform: capitalize; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 31px;
  padding: 6px 10px;
  border: 1px solid rgba(101, 215, 163, 0.25);
  border-radius: 999px;
  background: rgba(101, 215, 163, 0.1);
  color: #9de8c6;
  font-size: 0.75rem;
  font-weight: 800;
}

.main-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 16px clamp(18px, 4vw, 54px) 0;
  scrollbar-width: thin;
}
.nav-button {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.nav-button:hover { color: var(--text); background: rgba(255,255,255,0.035); }
.nav-button.active { border-color: var(--line); background: var(--surface-2); color: var(--text); }

.content { width: min(1500px, 100%); margin: 0 auto; padding: 34px clamp(18px, 4vw, 54px) 70px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.section-heading { margin-bottom: 20px; }
.split-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.reports-heading { margin-top: 38px; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(250px, 1.3fr) minmax(220px, 0.8fr) auto auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 22px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 26, 46, 0.72);
}
.filter-property-field { grid-column: span 1; }
.quick-date-filters {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding-bottom: 2px;
}
.quick-filter-button {
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(34, 46, 75, 0.72);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: 160ms ease;
}
.quick-filter-button:hover,
.quick-filter-button.active {
  border-color: rgba(131, 143, 255, 0.8);
  background: rgba(86, 99, 203, 0.3);
  box-shadow: 0 0 0 2px rgba(99, 112, 232, 0.1);
}
.custom-range-details {
  grid-column: 1 / -1;
  border-top: 1px solid rgba(255,255,255,0.07);
  padding-top: 10px;
}
.custom-range-details summary {
  width: fit-content;
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}
.custom-range-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.summary-card {
  min-height: 125px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(29, 41, 68, 0.9), rgba(18, 26, 46, 0.9));
}
.summary-card span { display: block; margin-bottom: 12px; color: var(--muted); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.summary-card strong { display: block; font-size: clamp(1.35rem, 2vw, 1.75rem); letter-spacing: -0.04em; }
.summary-card small { color: var(--muted); }
.summary-card.highlight { border-color: rgba(101, 215, 163, 0.25); background: linear-gradient(145deg, rgba(42, 87, 75, 0.58), rgba(18, 26, 46, 0.94)); }

.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.report-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 26, 46, 0.82);
  box-shadow: 0 16px 35px rgba(0,0,0,0.13);
}
.report-card-header { display: flex; justify-content: space-between; gap: 16px; padding: 18px 18px 13px; }
.report-card-header h3 { margin: 0; font-size: 1rem; }
.report-card-header p { margin: 4px 0 0; color: var(--muted); font-size: 0.79rem; }
.date-pill { flex: 0 0 auto; align-self: start; padding: 6px 9px; border-radius: 999px; background: var(--surface-3); color: #cdd5eb; font-size: 0.75rem; font-weight: 800; }

.screenshot-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #080d1a;
}
.screenshot-button img { display: block; width: 100%; aspect-ratio: 16 / 8.8; object-fit: cover; object-position: top; }
.screenshot-button.row-screenshot { background: #fff; }
.screenshot-button.row-screenshot img { aspect-ratio: 16 / 3; object-fit: contain; object-position: center; background: #fff; }
.screenshot-button:hover img { opacity: 0.9; }

.metrics-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); }
.metric { padding: 13px; background: var(--surface); }
.metric span { display: block; color: var(--muted); font-size: 0.7rem; font-weight: 800; text-transform: uppercase; }
.metric strong { display: block; margin-top: 5px; font-size: 0.96rem; }

.payout-breakdown { display: grid; gap: 9px; padding: 16px 18px 18px; }
.payout-row { display: flex; justify-content: space-between; gap: 16px; color: #dbe1f2; font-size: 0.84rem; }
.payout-row span:first-child { color: var(--muted); }
.payout-row.total { margin-top: 4px; padding-top: 11px; border-top: 1px solid var(--line); color: var(--positive); font-size: 0.97rem; font-weight: 900; }
.report-note { margin: 0 18px 18px; padding: 11px 12px; border-radius: 11px; background: rgba(255,255,255,0.035); color: #cbd3e8; font-size: 0.82rem; line-height: 1.5; }
.report-admin-actions { display: flex; justify-content: flex-end; padding: 0 18px 18px; }

.empty-state { padding: 45px 20px; border: 1px dashed rgba(255,255,255,0.15); border-radius: var(--radius); text-align: center; color: var(--muted); }
.empty-state h3 { color: var(--text); }

.panel {
  margin-bottom: 20px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(18, 26, 46, 0.78);
}
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.compact-form { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
.align-end { display: flex; align-items: end; }
.form-actions { display: flex; justify-content: flex-end; }
.field-help { color: var(--muted); font-size: 0.73rem; font-weight: 500; }
.calculation-box { display: grid; gap: 5px; padding: 15px; border: 1px solid rgba(124,140,255,0.2); border-radius: 12px; background: rgba(124,140,255,0.07); }
.calculation-box span { color: var(--muted); font-size: 0.84rem; }

.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 820px; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.05em; text-transform: uppercase; }
td { color: #dce3f4; font-size: 0.84rem; }
tbody tr:last-child td { border-bottom: 0; }
.table-primary { display: grid; gap: 3px; }
.table-primary strong { color: var(--text); }
.table-primary span { color: var(--muted); font-size: 0.74rem; }
.table-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.inline-select, .inline-input { min-width: 160px; min-height: 36px; padding: 7px 9px; font-size: 0.79rem; }
.status-dot { display: inline-flex; align-items: center; gap: 7px; }
.status-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--positive); }
.status-dot.inactive::before { background: var(--danger); }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 44px));
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #202b46;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(255,125,141,0.4); background: #43222e; }

.image-dialog {
  width: min(1200px, calc(100vw - 30px));
  max-height: calc(100vh - 30px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #070b15;
  box-shadow: var(--shadow);
}
.image-dialog::backdrop { background: rgba(0,0,0,0.82); backdrop-filter: blur(5px); }
.image-dialog img { display: block; width: 100%; max-height: calc(100vh - 32px); object-fit: contain; }
.dialog-close { position: fixed; top: 24px; right: 24px; z-index: 2; width: 42px; height: 42px; border: 1px solid rgba(255,255,255,0.2); border-radius: 50%; background: rgba(7,11,21,0.82); color: white; font-size: 1.45rem; }

@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .filter-bar { grid-template-columns: repeat(2, 1fr); }
  .compact-form { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .topbar { position: static; align-items: flex-start; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .user-chip { display: none; }
  .content { padding-top: 25px; }
  .filter-bar, .form-grid, .compact-form, .custom-range-fields { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .report-grid { grid-template-columns: 1fr; }
  .split-heading { align-items: start; }
}

@media (max-width: 480px) {
  .login-card { padding: 28px 22px; }
  .topbar { padding: 16px; }
  .main-nav { padding-left: 16px; padding-right: 16px; }
  .content { padding-left: 16px; padding-right: 16px; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-card { min-height: 105px; }
  .metrics-grid { grid-template-columns: 1fr; }
}

.ocr-status {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,0.035);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}
.ocr-status.loading { color: #c9d7ff; border-color: rgba(125, 156, 255, 0.28); background: rgba(83, 116, 218, 0.09); }
.ocr-status.success { color: #a9ebc9; border-color: rgba(101, 215, 163, 0.32); background: rgba(101, 215, 163, 0.08); }
.ocr-status.warning { color: #ffe0a6; border-color: rgba(255, 190, 92, 0.32); background: rgba(255, 190, 92, 0.08); }
.ocr-status.error { color: #ffb7bd; border-color: rgba(255, 104, 117, 0.32); background: rgba(255, 104, 117, 0.08); }
.screenshot-upload-field input[type="file"] { padding: 12px; border-style: dashed; }

/* Arabic / RTL layout */
html[dir="rtl"] body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}
html[dir="rtl"] h1,
html[dir="rtl"] h2,
html[dir="rtl"] h3 {
  letter-spacing: 0;
}
html[dir="rtl"] .eyebrow,
html[dir="rtl"] .summary-card span,
html[dir="rtl"] .metric span,
html[dir="rtl"] th {
  letter-spacing: 0;
  text-transform: none;
}
html[dir="rtl"] th,
html[dir="rtl"] td {
  text-align: right;
}
html[dir="rtl"] input,
html[dir="rtl"] select,
html[dir="rtl"] textarea {
  text-align: right;
}
html[dir="rtl"] [dir="ltr"] {
  text-align: left;
  unicode-bidi: isolate;
}
input[readonly] {
  cursor: default;
  background: rgba(101, 215, 163, 0.08);
  border-color: rgba(101, 215, 163, 0.25);
  font-weight: 900;
}
.card-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 7px;
}
.currency-badge {
  min-height: auto;
  padding: 6px 9px;
  border-color: rgba(124, 140, 255, 0.3);
  background: rgba(124, 140, 255, 0.1);
  color: #cbd3ff;
}
html[dir="rtl"] .toast {
  right: auto;
  left: 22px;
}
html[dir="rtl"] .dialog-close {
  right: auto;
  left: 24px;
}
@media (max-width: 760px) {
  html[dir="rtl"] .topbar-actions { justify-content: flex-start; }
}

.bulk-preview-wrap { margin-top: 16px; }
.bulk-preview-table input, .bulk-preview-table select { min-width: 120px; }
.bulk-preview-table .site-cell { min-width: 220px; direction:ltr; text-align:left; }
.bulk-preview-table tr.unmatched { background: rgba(255, 184, 77, .08); }
.bulk-import-actions { display:flex; gap:10px; align-items:center; margin-top:14px; flex-wrap:wrap; }

/* V16 monthly reports */
.report-type-badge {
  min-height: auto;
  padding: 6px 9px;
  border-color: rgba(101, 215, 163, 0.35);
  background: rgba(101, 215, 163, 0.12);
  color: #aef0cf;
}

.heading-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.writer-visible[hidden] {
  display: inline-flex !important;
}

/* V18 account and simplified site management */
.password-input-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}
.password-input-wrap input { min-width: 0; }
.password-toggle {
  min-width: 72px;
  padding-inline: 12px;
}

.payment-details summary {
  width: fit-content;
  color: #cbd3ff;
  font-weight: 800;
  cursor: pointer;
}
.payment-info-preview {
  width: min(360px, 70vw);
  max-height: 180px;
  overflow: auto;
  margin-top: 9px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(5, 10, 23, 0.65);
  color: #dce3f4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}

@media (max-width: 480px) {
  .password-input-wrap { grid-template-columns: 1fr; }
  .password-toggle { width: 100%; }
}

/* V19 clipboard images, CPC and payment-photo support */
.file-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
  margin-top: 7px;
}
.file-input-row input[type="file"] { min-width: 0; width: 100%; }
.paste-image-button { white-space: nowrap; min-width: 150px; }

.metrics-grid.three-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.payment-example {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(116, 125, 255, 0.07);
}
.payment-example strong { display: block; margin-bottom: 8px; color: #eef0ff; }
.payment-example pre {
  margin: 0;
  color: #cfd6ee;
  font: inherit;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.selected-file-list {
  padding: 11px 13px;
  border: 1px dashed rgba(132, 145, 255, .42);
  border-radius: 11px;
  color: #cfd6ee;
  background: rgba(5, 10, 23, .38);
}
.payment-photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.payment-photo-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(5, 10, 23, .55);
}
.payment-photo-preview,
.payment-thumb-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}
.payment-photo-preview { display: block; width: 100%; aspect-ratio: 16 / 10; }
.payment-photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.payment-photo-card > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px;
}
.payment-photo-card > div span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #cfd6ee;
}
.payment-admin-thumbs { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.payment-thumb-button {
  width: 58px;
  height: 44px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.payment-thumb-button img { width: 100%; height: 100%; object-fit: cover; display: block; }

@media (max-width: 760px) {
  .file-input-row { grid-template-columns: 1fr; }
  .paste-image-button { width: 100%; }
  .metrics-grid.three-metrics { grid-template-columns: 1fr; }
}
