:root {
  --ink: #14201c;
  --muted: #5a6b63;
  --line: rgba(20, 32, 28, 0.12);
  --panel: rgba(255, 252, 247, 0.94);
  --teal: #0f6b5c;
  --teal-deep: #0a4a40;
  --sand: #d4a574;
  --danger: #9b2c2c;
  --ok: #1b6b3a;
  --rail: #0d2f29;
  --shadow: 0 14px 40px rgba(15, 40, 32, 0.1);
  --radius: 16px;
  --font: "DM Sans", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 85% -10%, rgba(212, 165, 116, 0.22), transparent 55%),
    linear-gradient(165deg, #eef5f1 0%, #e2ece7 50%, #f4efe8 100%);
  background-attachment: fixed;
}

.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  background: linear-gradient(180deg, #0f3a33 0%, var(--rail) 100%);
  color: #e8f2ee;
  padding: 1.4rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-brand .brand-mark {
  margin: 0;
  font-family: var(--display);
  font-size: 2rem;
  line-height: 1;
  color: #fff;
}

.rail-brand span {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(232, 242, 238, 0.65);
}

.rail-nav {
  display: grid;
  gap: 0.35rem;
}

.rail-nav a {
  color: rgba(232, 242, 238, 0.82);
  text-decoration: none;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.95rem;
}

.rail-nav a em {
  font-style: normal;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.12);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.rail-nav a:hover,
.rail-nav a.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.rail-meta {
  margin-top: auto;
  display: grid;
  gap: 0.55rem;
  font-size: 0.85rem;
}

.rail-meta div {
  display: flex;
  justify-content: space-between;
  color: rgba(232, 242, 238, 0.7);
}

.rail-meta strong { color: #fff; }

.rail-db {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  color: rgba(232, 242, 238, 0.45);
  word-break: break-all;
}

.main {
  padding: 1.75rem 1.75rem 3rem;
  width: min(100%, 1080px);
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  margin-bottom: 1.25rem;
}

.page-head h1 {
  margin: 0.15rem 0 0.4rem;
  font-size: clamp(1.55rem, 2.6vw, 2rem);
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.lede {
  margin: 0;
  max-width: 40rem;
  color: var(--muted);
  line-height: 1.5;
}

.lede a { color: var(--teal-deep); font-weight: 600; }

.row-between {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: end;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.25rem 1.3rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.panel-head h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.panel-head + .row-form,
.panel-head + .form-grid,
.panel-head + .quota-grid {
  margin-top: 1rem;
}

.row-form,
.form-grid,
.search-form,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.form-grid .span-2 { grid-column: span 2; }

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.84rem;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[type="file"],
input[type="search"],
select {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem 0.75rem;
  min-width: 0;
  width: 100%;
}

.quota-input { width: 5.5rem; }

.quota-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.quota-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.quota-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.65);
}

a.quota-card {
  text-decoration: none;
  color: inherit;
  display: block;
}

.quota-card-top {
  display: grid;
  gap: 0.15rem;
  margin-bottom: 0.65rem;
}

.quota-card-top span {
  font-size: 0.78rem;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.65rem 1.05rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 107, 92, 0.25);
}

.btn-primary:hover { background: var(--teal-deep); }

.btn-secondary {
  background: #fff;
  color: var(--teal-deep);
  border-color: rgba(15, 107, 92, 0.28);
}

.btn-danger {
  background: #fff5f5;
  color: var(--danger);
  border-color: rgba(155, 44, 44, 0.28);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.actions { margin-top: 1rem; }
.actions.wrap { margin-top: 1rem; }
.inline-danger { margin-top: 0.75rem; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--ink);
  grid-template-columns: none;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 0.85rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  background: rgba(15, 107, 92, 0.06);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

tr:last-child td { border-bottom: none; }
tr.is-editing { background: rgba(15, 107, 92, 0.05); }

.row-actions {
  display: flex;
  gap: 0.65rem;
}

.row-actions a,
.linkish {
  background: none;
  border: none;
  padding: 0;
  color: var(--teal-deep);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
}

.tag {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(15, 107, 92, 0.1);
  color: var(--teal-deep);
}

.tag-manual, .tag-edited { background: rgba(212, 165, 116, 0.28); color: #7a4e1e; }
.tag-reshuffle { background: rgba(55, 90, 140, 0.14); color: #2c4a78; }

.empty {
  padding: 1.1rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  margin-top: 0.85rem;
}

.flash-stack {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.flash {
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.flash-success {
  background: #eaf7ef;
  border-color: rgba(27, 107, 58, 0.25);
  color: var(--ok);
}

.flash-error {
  background: #fdf0f0;
  border-color: rgba(155, 44, 44, 0.25);
  color: var(--danger);
}

.meta-line {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.map-grid div {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.6);
  display: grid;
  gap: 0.35rem;
}

.map-grid span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.map-grid code {
  direction: auto;
  unicode-bidi: plaintext;
}

.config-panel .quota-input {
  width: 6rem;
}

/* Arabic names read naturally in tables */
td code[dir="auto"],
td[dir="rtl"] {
  font-family: inherit;
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .rail-nav {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }
  .rail-meta { width: 100%; margin-top: 0; grid-template-columns: 1fr 1fr; }
  .main { padding: 1.2rem 1rem 2.5rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
}
