/* ===== UNIFIED APP SHELL - AdOps Tracker ===== */
/* Right Sidebar + Shared Layout System */

:root {
  /* Colors */
  --c-ink: #12303a;
  --c-ink-2: #1d4652;
  --c-surface: #fff;
  --c-paper: #f5f7f6;
  --c-border: #dde3e1;
  --c-border-light: #e7edef;
  --c-muted: #6b7c82;
  --c-primary: #1f7a5c;
  --c-danger: #b03a2e;
  --c-warning: #c98a1e;

  /* Typography */
  --font-ar: "SF Arabic", "Geeza Pro", "Noto Naskh Arabic", "Segoe UI", Tahoma, sans-serif;
  --font-mono: "SF Mono", "IBM Plex Mono", Menlo, "DejaVu Sans Mono", monospace;
  --text-xs: 10px;
  --text-sm: 11px;
  --text-base: 12px;
  --text-md: 13px;
  --text-lg: 14px;
  --text-xl: 17px;

  /* Layout */
  --sidebar-width: 200px;
  --header-height: 64px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 6px;
  --space-md: 8px;
  --space-lg: 12px;
  --space-xl: 16px;
  --space-2xl: 20px;

  /* Radius */
  --radius-sm: 3px;
  --radius-md: 5px;
  --radius-lg: 8px;
  --radius-full: 999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(18, 48, 58, 0.08);
  --shadow-md: 0 4px 16px rgba(18, 48, 58, 0.1);
  --shadow-focus: 0 0 0 3px rgba(84, 202, 166, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--c-paper);
  color: var(--c-ink);
  font-family: var(--font-ar);
  font-size: var(--text-lg);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ===== RIGHT SIDEBAR NAVIGATION ===== */
header {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--c-ink);
  color: #eef3f1;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

header::after {
  content: "";
  position: fixed;
  top: 0;
  right: var(--sidebar-width);
  width: 1px;
  height: 100vh;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

header h1 {
  padding: 20px 16px;
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

header h1 small {
  display: block;
  font-size: 9px;
  font-weight: 400;
  opacity: 0.65;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  font-family: var(--font-mono);
  margin-top: 3px;
}

header nav {
  flex: 1;
  padding: 68px 10px var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

header nav::before {
  content: "≡";
  position: absolute;
  top: 20px;
  right: 16px;
  font-size: 16px;
  opacity: 0.4;
  font-weight: 300;
  pointer-events: none;
}

.nav-group {
  margin-bottom: 10px;
}

.nav-group-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  opacity: 0.5;
  padding: var(--space-md) var(--space-lg);
  margin-bottom: 2px;
}

header nav a {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 var(--space-lg);
  gap: 10px;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-size: var(--text-md);
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: var(--transition-fast);
}

header nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

header nav a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: inset 3px 0 0 #54caa6;
}

header nav a .icon {
  opacity: 0.7;
  font-size: var(--text-md);
}

header .controls {
  padding: var(--space-lg) 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: var(--space-sm);
}

header .controls label {
  color: rgba(255, 255, 255, 0.58);
  font-size: var(--text-xs);
  font-weight: 700;
}

header .controls input,
header .controls select {
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.18);
  color: #eef3f1;
  font-family: var(--font-ar);
  font-size: var(--text-sm);
}

header .controls input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

header .controls button {
  width: 100%;
}

/* ===== MAIN CONTENT AREA ===== */
main {
  margin-right: var(--sidebar-width);
  min-height: 100vh;
  padding: 22px;
}

/* ===== HEADER CONTROLS (for pages that need top controls) ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--c-border);
}

.page-header h2 {
  font-size: var(--text-xl);
  font-weight: 800;
  margin: 0;
  color: var(--c-ink);
}

.page-header .actions {
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

/* ===== CARDS ===== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card > h2,
.card > h3 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 800;
  padding: 13px 16px;
  background: #f7fafb;
  border-bottom: 1px solid var(--c-border);
  color: var(--c-ink);
}

.card .body {
  padding: var(--space-xl);
}

/* ===== FORMS ===== */
.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: #74868d;
  font-size: var(--text-xs);
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #dce6e8;
  border-radius: var(--radius-md);
  background: #fbfcfc;
  color: var(--c-ink);
  font-family: var(--font-ar);
  font-size: var(--text-md);
  transition: var(--transition-base);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  background: #fff;
  border-color: #54caa6;
  box-shadow: var(--shadow-focus);
}

.field .hint {
  font-size: var(--text-xs);
  color: var(--c-muted);
  margin-top: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.loading-state {
  min-height: 72px;
  display: grid;
  place-items: center;
}

/* ===== BUTTONS ===== */
button,
.btn {
  font-family: var(--font-ar);
  font-size: var(--text-sm);
  font-weight: 700;
  padding: 0 14px;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  text-decoration: none;
}

button:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #59d7af, #42b990);
  color: #08241b;
  font-weight: 900;
  box-shadow: 0 3px 12px rgba(67, 188, 149, 0.15);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 16px rgba(67, 188, 149, 0.2);
}

.btn-secondary {
  background: #fff;
  border: 1px solid var(--c-border);
  color: var(--c-ink);
}

.btn-secondary:hover:not(:disabled) {
  background: #f9fafb;
}

.btn-danger {
  background: #fff5f3;
  color: #b64a40;
  border: 1px solid #edcfca;
}

.btn-danger:hover:not(:disabled) {
  background: #ffebe8;
}

/* ===== TABLES ===== */
.table-wrap {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}

thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 38px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #f1f6f6 0%, #e9f0f1 100%);
  color: #2d4a52;
  border-bottom: 2px solid #d5e0e2;
  font-size: var(--text-xs);
  font-weight: 800;
  white-space: nowrap;
  text-align: right;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

tbody td {
  padding: 10px;
  border-bottom: 1px solid #eef3f4;
  vertical-align: middle;
  text-align: right;
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover {
  background: #f9fcfc;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr[aria-selected="true"] {
  background: #e7f4ed;
  box-shadow: inset 3px 0 0 var(--c-primary);
}

/* ===== BADGES & CHIPS ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
  background: #e7ece9;
  color: var(--c-ink);
}

.badge-primary {
  background: #e3f0ea;
  color: var(--c-primary);
  border: 1px solid #c8e6d8;
}

.badge-danger {
  background: #f7e6e3;
  color: var(--c-danger);
  border: 1px solid #f5d5d1;
}

.badge-warning {
  background: #faf0dc;
  color: #8a5f10;
  border: 1px solid #f2deb8;
}

/* ===== UTILITIES ===== */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  display: inline-block;
  unicode-bidi: embed;
}

.text-muted {
  color: var(--c-muted);
}

.text-primary {
  color: var(--c-primary);
}

.text-danger {
  color: var(--c-danger);
}

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-xs); }
.mb-2 { margin-bottom: var(--space-sm); }
.mb-3 { margin-bottom: var(--space-md); }
.mb-4 { margin-bottom: var(--space-lg); }
.mb-5 { margin-bottom: var(--space-xl); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-xs); }
.mt-2 { margin-top: var(--space-sm); }
.mt-3 { margin-top: var(--space-md); }
.mt-4 { margin-top: var(--space-lg); }
.mt-5 { margin-top: var(--space-xl); }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  header {
    position: static;
    width: 100%;
    height: auto;
  }

  header::after {
    display: none;
  }

  header nav {
    padding: 10px 12px 12px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  header .controls {
    border-top: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  header nav::before {
    display: none;
  }

  .nav-group {
    width: auto;
    min-width: min(100%, 168px);
    flex: 1 1 168px;
    margin: 0;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.025);
  }

  .nav-group-title {
    padding: 4px 8px 6px;
    margin: 0;
  }

  header nav a {
    min-height: 38px;
    padding-inline: 9px;
    font-size: var(--text-base);
  }

  main {
    margin-right: 0;
    padding: 16px;
  }
}

@media (max-width: 520px) {
  main {
    padding: 12px;
  }

  header nav {
    gap: 6px;
  }

  .nav-group {
    min-width: 100%;
    flex-basis: 100%;
  }

  .nav-group-title {
    padding-inline: 6px;
  }

  header nav a {
    min-height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
