:root {
  --bg: #eef3f1;
  --bg-deep: #d9e6e1;
  --surface: #ffffff;
  --ink: #143028;
  --muted: #5a7269;
  --line: #c9d8d1;
  --brand: #0f6b5c;
  --brand-deep: #0a4d42;
  --brand-soft: #d8efe9;
  --accent: #c45c26;
  --accent-soft: #f7e6dc;
  --danger: #b42318;
  --success: #067647;
  --info: #175cd3;
  --shadow: 0 18px 40px rgba(20, 48, 40, 0.08);
  --radius: 18px;
  --font: "IBM Plex Sans Arabic", "Tajawal", sans-serif;
  --display: "Tajawal", "IBM Plex Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, rgba(15, 107, 92, 0.10), transparent 35%),
    radial-gradient(circle at 90% 0%, rgba(196, 92, 38, 0.08), transparent 30%),
    linear-gradient(160deg, var(--bg), var(--bg-deep));
  min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-deep); }

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #0f4f44 0%, #0a3a32 100%);
  color: #f4fffb;
  padding: 1.5rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; gap: 0.85rem; align-items: center; padding: 0.4rem 0.5rem; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #1aa891, #0f6b5c);
  font-family: var(--display);
  font-weight: 800; font-size: 1.4rem;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}
.brand-text { display: flex; flex-direction: column; gap: 0.15rem; }
.brand-text strong { font-size: 1.15rem; font-family: var(--display); }
.brand-text span { font-size: 0.78rem; opacity: 0.75; }

.nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.nav a {
  color: rgba(255,255,255,0.82);
  padding: 0.85rem 1rem;
  border-radius: 12px;
  transition: 0.2s ease;
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.12);
}
.user-chip {
  font-size: 0.85rem; opacity: 0.9;
  background: rgba(255,255,255,0.08);
  padding: 0.45rem 0.7rem; border-radius: 999px;
}

.main { padding: 1.5rem 1.75rem 2.5rem; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin-bottom: 1.25rem;
}
.page-title {
  margin: 0; font-family: var(--display); font-size: 1.85rem; font-weight: 800;
  letter-spacing: -0.02em;
}
.page-sub { margin: 0.35rem 0 0; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid rgba(201, 216, 209, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  animation: rise 0.45s ease both;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; gap: 1rem;
}
.panel-head h2 { margin: 0; font-size: 1.15rem; font-family: var(--display); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 0.5s ease both;
}
.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.1s; }
.stat:nth-child(4) { animation-delay: 0.15s; }
.stat span { color: var(--muted); font-size: 0.9rem; }
.stat strong {
  display: block; margin-top: 0.45rem;
  font-size: 1.8rem; font-family: var(--display); color: var(--brand-deep);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.25rem;
  align-items: start;
}
.stack-panels { display: flex; flex-direction: column; gap: 1.25rem; }

.form-control, input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  background: #fbfdfc;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 107, 92, 0.15);
}

.stack-form { display: flex; flex-direction: column; gap: 0.9rem; }
.stack-form label, .form-grid label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.92rem; color: var(--muted);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.9rem 1rem;
}
.form-grid .span-2 { grid-column: span 2; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem;
  border: none; cursor: pointer;
  border-radius: 12px;
  padding: 0.75rem 1.15rem;
  font: inherit; font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 107, 92, 0.28);
}
.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn-ghost {
  background: transparent;
  color: inherit;
  border: 1px solid rgba(255,255,255,0.25);
}
.sidebar .btn-ghost { color: #fff; }
.main .btn-ghost {
  border-color: var(--line);
  color: var(--muted);
  background: #fff;
}
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.btn-row, .composer-actions {
  display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 0.5rem;
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 0.75rem 0.65rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.data-table tfoot th { border-bottom: none; padding-top: 1rem; }
.grand-row th { color: var(--brand-deep); font-size: 1.05rem; }
.table-wrap { overflow-x: auto; }
.amount-input { max-width: 110px; text-align: center; direction: ltr; }
.mono { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: plaintext; }
.total-live { font-size: 1.1rem; color: var(--brand-deep); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem !important; }
.mini-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.badge {
  display: inline-flex; align-items: center;
  padding: 0.25rem 0.65rem; border-radius: 999px;
  font-size: 0.8rem; font-weight: 600;
  background: #eef2f0; color: var(--muted);
}
.badge-draft, .badge-ready { background: #eef4ff; color: var(--info); }
.badge-sent { background: #fff4e5; color: #b54708; }
.badge-accepted { background: #e8f8ef; color: var(--success); }
.badge-rejected { background: #fef3f2; color: var(--danger); }
.badge-returned { background: var(--accent-soft); color: var(--accent); }

.flash-stack { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.flash {
  padding: 0.85rem 1rem; border-radius: 12px;
  background: #eef4ff; color: var(--info); border: 1px solid #c6d7f5;
}
.flash-success, .flash-success.message { background: #e8f8ef; color: var(--success); border-color: #abefc6; }
.flash-error, .flash-error.message { background: #fef3f2; color: var(--danger); border-color: #fecdca; }
.flash-info, .flash-info.message { background: #eef4ff; color: var(--info); border-color: #c6d7f5; }
.flash-warning { background: #fff4e5; color: #b54708; border-color: #f9dbaf; }

.banner-warn {
  background: var(--accent-soft);
  color: #8a3d12;
  border: 1px solid #efc7ad;
  border-radius: 14px;
  padding: 0.95rem 1.1rem;
  margin-bottom: 1rem;
}
.banner-warn a { color: inherit; font-weight: 700; text-decoration: underline; }

.invoice-brand-strip {
  display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start;
  padding: 1.1rem 1.2rem;
  margin: -0.25rem -0.25rem 1.1rem;
  border-radius: 14px;
  background:
    linear-gradient(120deg, rgba(15,107,92,0.10), rgba(196,92,38,0.08)),
    #f7fbf9;
  border: 1px solid var(--line);
}
.invoice-brand-strip h2 { margin: 0.2rem 0 0; font-family: var(--display); }
.invoice-brand-strip.compact { margin-bottom: 1rem; }
.eyebrow {
  margin: 0; text-transform: none; letter-spacing: 0;
  color: var(--brand); font-weight: 600; font-size: 0.85rem;
}
.tax-chip {
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 0.7rem 0.9rem; min-width: 180px;
}
.tax-chip span { display: block; color: var(--muted); font-size: 0.8rem; }
.tax-chip strong { font-size: 1rem; }

.meta-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.85rem; margin: 0 0 1.25rem;
}
.meta-grid dt { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.2rem; }
.meta-grid dd { margin: 0; font-weight: 600; }
.section-label {
  margin: 1.25rem 0 0.6rem; font-size: 1rem; color: var(--brand-deep);
}
.filters { display: flex; gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters .form-control { max-width: 280px; }
.checklist { list-style: none; padding: 0; margin: 0 0 1rem; }
.checklist li {
  padding: 0.55rem 0.75rem; margin-bottom: 0.4rem;
  border-radius: 10px; background: #f4f7f6; color: var(--muted);
}
.checklist li.ok { background: #e8f8ef; color: var(--success); }
.checklist li.ok::before { content: "✓ "; }
.test-result {
  margin-top: 1rem; padding: 0.9rem 1rem; border-radius: 12px;
  background: #f4f7f6;
}
.test-result.ok { background: #e8f8ef; color: var(--success); }
.test-result.fail { background: #fef3f2; color: var(--danger); }
.qr-box {
  margin-top: 1rem; padding: 1rem; border: 1px dashed var(--line);
  border-radius: 12px; text-align: center;
}
.qr-box img { max-width: 180px; height: auto; }
.meta-line { margin-top: 1rem; color: var(--muted); }
.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.7rem 0; border-bottom: 1px solid var(--line);
}
.muted { color: var(--muted); }
.field-error { color: var(--danger); font-size: 0.82rem; font-style: normal; }
.link { font-weight: 600; }

/* Auth */
.auth-body { background: #0b2f29; }
.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
}
.auth-visual {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(10, 58, 50, 0.88), rgba(15, 107, 92, 0.72)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(160deg, #0a3a32, #146357);
  color: #f4fffb;
  display: flex; align-items: center;
  padding: 3rem;
}
.auth-visual-inner { max-width: 560px; animation: rise 0.7s ease both; }
.auth-visual h1 {
  font-family: var(--display);
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  line-height: 1.25;
  margin: 0.6rem 0 1rem;
  font-weight: 800;
}
.auth-visual .lede { font-size: 1.1rem; opacity: 0.9; max-width: 42ch; }
.auth-points {
  list-style: none; padding: 0; margin: 2rem 0 0;
  display: flex; flex-wrap: wrap; gap: 0.6rem;
}
.auth-points li {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.16);
  padding: 0.55rem 0.9rem; border-radius: 999px;
  font-size: 0.92rem;
}
.auth-panel {
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 80% 20%, rgba(196,92,38,0.08), transparent 40%),
    linear-gradient(180deg, #f4faf7, #e8f1ed);
  padding: 2rem;
}
.auth-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 24px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(201,216,209,0.8);
  animation: rise 0.55s ease 0.1s both;
}
.auth-logo {
  width: 56px; height: 56px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #1aa891, #0f6b5c);
  color: #fff; font-family: var(--display); font-weight: 800; font-size: 1.5rem;
  margin-bottom: 1rem;
}
.auth-card h2 { margin: 0 0 0.35rem; font-family: var(--display); }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative; height: auto;
    border-radius: 0 0 20px 20px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .auth-layout { grid-template-columns: 1fr; }
  .auth-visual { min-height: 42vh; padding: 2rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .meta-grid { grid-template-columns: 1fr; }
}
