/* ============================================================
   sp-tickets — modern design system (marketing + app).
   Arabic-first, RTL-aware, responsive 360px+, reduced-motion aware.
   ============================================================ */
:root {
  /* Brand palette — refined indigo→violet with a teal accent */
  --brand-1: #6d5efc;
  --brand-2: #8b5cf6;
  --brand-3: #22d3ee;
  --primary: #6d5efc;
  --primary-700: #5b4bd6;
  --primary-ink: #ffffff;
  --accent: #14b8a6;

  --ink: #0b1020;
  --ink-2: #1e2742;
  --muted: #6b7493;
  --line: #e9ebf3;
  --line-2: #eef0f7;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbff;

  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;

  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 9px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 64, .06);
  --shadow-sm: 0 4px 14px rgba(16, 24, 64, .07);
  --shadow: 0 16px 40px rgba(16, 24, 64, .12);
  --shadow-lg: 0 30px 70px rgba(16, 24, 64, .18);
  --ring: 0 0 0 4px rgba(109, 94, 252, .18);

  --grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --grad-soft: linear-gradient(135deg, rgba(109,94,252,.12), rgba(34,211,238,.10));

  --dur: 200ms;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --font-ar: "IBM Plex Sans Arabic", "Inter", system-ui, sans-serif;
  --font-lt: "Inter", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font: var(--font-ar);
}
html[lang="en"], html[lang="en"] body { --font: var(--font-lt); }

* { box-sizing: border-box; }
svg { vertical-align: middle; flex-shrink: 0; }
.sidebar a svg, .nav-links a svg, .btn svg { flex-shrink: 0; }
[dir="rtl"] .icon-flip svg { transform: scaleX(-1); }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font-family: var(--font); color: var(--ink);
  background: var(--bg); line-height: 1.65; font-size: 16px;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow-x: hidden; /* safety net against accidental horizontal scroll (NFR-4) */
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-700); }
img { max-width: 100%; height: auto; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; font-weight: 700; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.container { max-width: 1160px; margin: 0 auto; padding: 0 22px; }
.muted { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
  background: var(--grad); color: var(--primary-ink); border: 0;
  padding: .72rem 1.3rem; border-radius: 999px; font-weight: 600; font-size: .95rem;
  font-family: inherit; cursor: pointer; min-height: 46px; white-space: nowrap;
  box-shadow: 0 8px 20px rgba(109, 94, 252, .28);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(109, 94, 252, .36); color: #fff; }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-xs); }
.btn.secondary:hover { border-color: var(--primary); color: var(--primary-700); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: none; }
.btn.ghost:hover { background: var(--surface-2); box-shadow: none; }
.btn.danger { background: linear-gradient(135deg, #f87171, #ef4444); box-shadow: 0 8px 20px rgba(239,68,68,.28); }
.btn.ok { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: 0 8px 20px rgba(16,185,129,.28); }
.btn.sm { padding: .42rem .85rem; min-height: 38px; font-size: .84rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; margin: 1rem 0 .4rem; font-size: .88rem; color: var(--ink-2); }
input, select, textarea {
  width: 100%; padding: .7rem .9rem; border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); font: inherit; color: var(--ink); min-height: 46px;
  transition: border-color var(--dur), box-shadow var(--dur);
}
input::placeholder, textarea::placeholder { color: #aab0c6; }
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input[type="color"] { padding: .2rem; }
.hint { color: var(--muted); font-size: .82rem; margin-top: .35rem; }
.field-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.field-row > div { flex: 1 1 220px; }

/* ---------- Cards & layout ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.4rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.grid { display: grid; gap: 1.1rem; }
/* Let grid/flex children shrink below their content's intrinsic width so inner
   scroll containers (.table-wrap) take over instead of overflowing the page. */
.grid > *, .shell, .content, .panel, .card { min-width: 0; }
.ticket-grid > *, .field-grid > *, .sub-grid > * { min-width: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-xs); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .85rem 1rem; text-align: start; border-bottom: 1px solid var(--line-2); font-size: .92rem; }
th { color: var(--muted); font-weight: 600; background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--dur); }
tbody tr:hover td { background: var(--surface-2); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .22rem .65rem; border-radius: 999px; font-size: .76rem; font-weight: 600; background: rgba(109,94,252,.1); color: var(--primary-700); }
.badge.gray { background: #f0f2f8; color: var(--muted); }
.badge.ok { background: rgba(16,185,129,.12); color: #0f766e; }
.badge.warn { background: rgba(245,158,11,.14); color: #b45309; }
.badge.danger { background: rgba(239,68,68,.12); color: #b91c1c; }

/* ---------- Flash ---------- */
.flash { padding: .85rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .92rem; border: 1px solid transparent; }
.flash.ok { background: rgba(16,185,129,.1); color: #0f766e; border-color: rgba(16,185,129,.25); }
.flash.err { background: rgba(239,68,68,.08); color: #b91c1c; border-color: rgba(239,68,68,.22); }
.flash.info { background: rgba(109,94,252,.08); color: var(--primary-700); border-color: rgba(109,94,252,.22); }

/* ---------- Top navigation ---------- */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(255,255,255,.75); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--line); }
.topbar .inner { display: flex; align-items: center; gap: 1rem; min-height: 68px; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; color: var(--ink); font-size: 1.12rem; letter-spacing: -.02em; }
.brand:hover { color: var(--ink); }
.brand .logo { width: 38px; height: 38px; border-radius: 11px; background: var(--grad); display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 900; font-size: .95rem; box-shadow: 0 6px 16px rgba(109,94,252,.4); }
.spacer { flex: 1; }
.nav-links { display: flex; gap: .25rem; align-items: center; flex-wrap: wrap; }
.nav-links a { padding: .5rem .8rem; border-radius: 999px; color: var(--ink-2); font-weight: 600; font-size: .9rem; transition: background var(--dur), color var(--dur); }
.nav-links a:hover { background: var(--surface-2); color: var(--ink); }
.nav-links a.active { background: var(--grad-soft); color: var(--primary-700); }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 264px 1fr; min-height: calc(100vh - 68px); }
.sidebar { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 1.2rem .8rem; }
.sidebar a { display: flex; align-items: center; gap: .7rem; padding: .66rem .9rem; border-radius: 12px; color: var(--ink-2); font-weight: 600; font-size: .92rem; margin-bottom: .18rem; transition: background var(--dur), color var(--dur); }
.sidebar a:hover { background: var(--surface-2); color: var(--ink); }
.sidebar a.active { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(109,94,252,.3); }
.content { padding: 2rem; min-width: 0; background: var(--bg); }
.page-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 1.6rem; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.1rem; margin-bottom: 1.6rem; }
.stat { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem 1.3rem 1.2rem; box-shadow: var(--shadow-sm); overflow: hidden; }
.stat::before { content: ""; position: absolute; inset-inline-start: 0; top: 0; bottom: 0; width: 4px; background: var(--grad); }
.stat .n { font-size: 2.1rem; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.stat .l { color: var(--muted); font-size: .85rem; margin-top: .4rem; }

/* ---------- Marketing ---------- */
.hero { position: relative; overflow: hidden; color: #fff; padding: 7rem 0 7.5rem; background:
    radial-gradient(900px 500px at 85% -5%, rgba(34,211,238,.35), transparent 60%),
    radial-gradient(800px 500px at 10% 10%, rgba(139,92,246,.45), transparent 55%),
    linear-gradient(160deg, #130f2e 0%, #1b1446 45%, #0e0b24 100%); }
.hero::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px); background-size: 42px 42px; mask-image: radial-gradient(900px 500px at 50% 0, #000, transparent 75%); pointer-events: none; }
.hero .container { position: relative; z-index: 1; }
.hero .eyebrow { display: inline-flex; align-items: center; gap: .5rem; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); padding: .4rem .9rem; border-radius: 999px; font-size: .82rem; font-weight: 600; color: #e9e6ff; margin-bottom: 1.4rem; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.6rem); font-weight: 800; letter-spacing: -.03em; max-width: 16ch; }
.hero p { color: #c9cce6; font-size: 1.16rem; max-width: 60ch; margin-top: 1rem; }
.hero .cta { display: flex; gap: .8rem; margin-top: 2rem; flex-wrap: wrap; }
.hero .btn.secondary { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.22); box-shadow: none; }
.hero .btn.secondary:hover { background: rgba(255,255,255,.18); color: #fff; }
.hero-preview { margin-top: 3.5rem; position: relative; z-index: 1; max-width: 100%; }
.hero-preview img { width: 100%; border-radius: var(--radius); border: 1px solid rgba(255,255,255,.14); box-shadow: var(--shadow-lg); }

.section { padding: 5rem 0; }
.section-head { text-align: center; max-width: 60ch; margin: 0 auto 3rem; }
.section-head .eyebrow { display: inline-block; color: var(--primary-700); background: var(--grad-soft); padding: .35rem .9rem; border-radius: 999px; font-size: .8rem; font-weight: 700; margin-bottom: 1rem; }
.section-head h2 { font-size: clamp(1.7rem, 3.5vw, 2.5rem); }
.section-head p { color: var(--muted); font-size: 1.05rem; }

.feature { display: grid; grid-template-columns: 1fr 1.15fr; gap: 2.5rem; align-items: center; margin-bottom: 2rem; background: var(--surface); border: 1px solid var(--line); border-radius: calc(var(--radius) + 6px); padding: 2rem; box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.feature:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.feature:nth-child(even) > div:first-child { order: 2; }
.feature .shot { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #0e0b24; }
.feature .shot img { width: 100%; }
.feature .tag { display: inline-flex; font-size: .72rem; font-weight: 700; color: var(--primary-700); background: var(--grad-soft); padding: .25rem .7rem; border-radius: 999px; margin-bottom: .9rem; letter-spacing: .02em; }
.feature h3 { font-size: 1.45rem; }
.feature p { color: var(--muted); font-size: 1.02rem; margin: 0; }

.pricing { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.3rem; }
.plan { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.8rem 1.5rem; text-align: center; box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.plan:hover { transform: translateY(-5px); box-shadow: var(--shadow); }
.plan.featured { border-color: transparent; background: var(--grad); color: #fff; box-shadow: var(--shadow-lg); position: relative; }
.plan.featured .price, .plan.featured h3 { color: #fff; }
.plan.featured .price small, .plan.featured p { color: rgba(255,255,255,.85); }
.plan.featured .btn { background: #fff; color: var(--primary-700); box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.plan .ribbon { position: absolute; top: 1rem; inset-inline-end: 1rem; background: rgba(255,255,255,.22); padding: .2rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.plan h3 { font-size: 1.15rem; }
.plan .price { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; margin: .4rem 0; }
.plan .price small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.plan p { color: var(--muted); margin: 0 0 1.2rem; }

footer.site { background: #0e0b24; color: #c9cce6; padding: 3rem 0; }
footer.site .inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
footer.site a { color: #a9b0ff; }
footer.site .fine { opacity: .6; font-size: .85rem; margin-top: .4rem; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; position: relative; overflow: hidden; background:
    radial-gradient(700px 400px at 20% 10%, rgba(139,92,246,.4), transparent 60%),
    radial-gradient(700px 400px at 85% 90%, rgba(34,211,238,.28), transparent 60%),
    linear-gradient(160deg, #130f2e, #0e0b24); }
.auth-card { width: 100%; max-width: 440px; background: var(--surface); border-radius: calc(var(--radius) + 4px); padding: 2.4rem; box-shadow: var(--shadow-lg); position: relative; z-index: 1; }

/* ---------- Comments / timeline ---------- */
.comment { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 1rem 1.1rem; margin-bottom: .85rem; background: var(--surface); box-shadow: var(--shadow-xs); }
.comment.internal { background: linear-gradient(0deg, rgba(245,158,11,.06), rgba(245,158,11,.06)), var(--surface); border-color: rgba(245,158,11,.4); }
.comment .meta { color: var(--muted); font-size: .8rem; margin-bottom: .4rem; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .55rem 0; border-bottom: 1px dashed var(--line); font-size: .85rem; color: var(--muted); }
.timeline li:last-child { border-bottom: 0; }

.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem .9rem; }
.checks label { display: flex; gap: .55rem; font-weight: 500; margin: 0; align-items: center; color: var(--ink); }
.checks input { width: auto; min-height: auto; }
.inline-form { display: inline; }

/* Code & docs */
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; background: #f1f2f8; color: #3a2fb0; padding: .12em .4em; border-radius: 6px; }
pre { background: #0e0b24; color: #e6e7f2; padding: 1rem 1.1rem; border-radius: var(--radius-sm); overflow-x: auto; font-size: .85rem; line-height: 1.5; }
pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.docs { max-width: 900px; }
.docs h2 { margin-top: 2.2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.docs table td code { white-space: nowrap; }
.endpoint { display: flex; align-items: center; gap: .6rem; margin: .4rem 0; flex-wrap: wrap; }
.method { font-weight: 700; font-size: .78rem; padding: .18rem .55rem; border-radius: 6px; color: #fff; }
.method.get { background: #16a34a; } .method.post { background: #2563eb; } .method.patch { background: #d97706; } .method.del { background: #dc2626; }
.toc { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1rem 0 2rem; }
.toc a { background: var(--surface-2); border: 1px solid var(--line); padding: .35rem .8rem; border-radius: 999px; font-size: .85rem; font-weight: 600; }

/* ---------- Responsive layout helpers ---------- */
.ticket-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.1rem; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; align-items: end; }
.sub-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: .6rem; align-items: center; }
.days-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem .9rem; }

/* Mobile nav drawer */
.nav-toggle { display: none; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; cursor: pointer; color: var(--ink); padding: 0; }
.nav-scrim { display: none; position: fixed; inset: 0; background: rgba(11, 16, 32, .45); z-index: 55; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .nav-toggle { display: inline-flex; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: 272px; max-width: 82vw;
    z-index: 60; transform: translateX(-110%); transition: transform var(--dur) var(--ease);
    overflow-y: auto; border-inline-end: 1px solid var(--line); border-bottom: 0;
    box-shadow: var(--shadow-lg); padding: 1rem .8rem; display: block;
  }
  [dir="rtl"] .sidebar { transform: translateX(110%); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-scrim { display: block; }
  .sidebar a { margin-bottom: .2rem; }
  .ticket-grid, .sub-grid { grid-template-columns: 1fr; }
  .feature { grid-template-columns: 1fr; gap: 1.5rem; }
  .feature:nth-child(even) > div:first-child { order: 0; }
  .stats, .pricing, .grid.cols-4, .grid.cols-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .stats, .pricing, .grid.cols-4, .grid.cols-3, .grid.cols-2, .days-grid, .field-grid { grid-template-columns: 1fr; }
  .days-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 1rem; }
  .hero { padding: 4.5rem 0 5rem; }
  .section { padding: 3.25rem 0; }
  .page-head h1 { font-size: 1.3rem; }
  .nav-links .hide-sm { display: none; }
  .topbar .inner { gap: .5rem; min-height: 60px; flex-wrap: wrap; }
  .nav-links { gap: .2rem; }
  .nav-links a { padding: .45rem .6rem; font-size: .85rem; }
  .brand { font-size: 1rem; }
  .brand .logo { width: 32px; height: 32px; }
  footer.site .inner { flex-direction: column; text-align: center; }
  footer.site [style*="text-align:end"] { text-align: center !important; }
}

/* Card-stacking tables on small screens (NFR-4) */
@media (max-width: 700px) {
  .rtable thead { display: none; }
  .rtable, .rtable tbody, .rtable tr, .rtable td { display: block; width: 100%; }
  .rtable tr { border: 1px solid var(--line); border-radius: 12px; margin: .6rem; padding: .25rem 0; background: var(--surface); }
  .rtable tbody tr:hover td { background: transparent; }
  .rtable td { border: 0; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; padding: .5rem .9rem; text-align: end; }
  .rtable td::before { content: attr(data-label); color: var(--muted); font-weight: 600; font-size: .78rem; text-align: start; text-transform: uppercase; letter-spacing: .03em; flex: 0 0 auto; }
  .rtable td > form, .rtable td > .row-actions { margin-inline-start: auto; }
  .rtable td:not([data-label]) { justify-content: flex-end; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
