@import url("https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap");

:root {
  --parchment: #f6ecd8;
  --ink: #2c1810;
  --ink-soft: #6b5a47;
  --wine: #5c1420;
  --wine-deep: #3d0e16;
  --gold: #b8862e;
  --gold-light: #d9ab52;
  --panel-bg: #fffaf0;
  --border: #d8c69f;
  --shadow: rgba(61, 14, 22, 0.12);
  --ok: #2e6b3f;
  --ok-bg: #e9f5ec;
  --err: #a33a2e;
  --err-bg: #fbebe8;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Cairo", "Tahoma", sans-serif;
  background: var(--parchment);
  background-image:
    radial-gradient(circle at 15% 20%, rgba(184, 134, 46, 0.05), transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(92, 20, 32, 0.05), transparent 45%);
  color: var(--ink);
  direction: rtl;
  overflow-x: hidden;
}

.app-shell {
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header — full-bleed across the viewport, like the homepage's
   .site-header, even though it sits inside the width-capped .app-shell.
   The vw-based negative margins stretch it edge-to-edge; the padding
   keeps its content aligned with .app-main's contained width. ──────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  width: 100vw;
  margin-inline-start: calc(50% - 50vw);
  padding: 1rem calc((100vw - min(100vw, 860px)) / 2 + 1.5rem);
  background: linear-gradient(180deg, var(--wine) 0%, var(--wine-deep) 100%);
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 4px 16px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--gold-light);
  letter-spacing: 0.02em;
}

.app-header .cross-ornament {
  width: 1.6em;
  height: 1.6em;
  display: inline-flex;
  flex-shrink: 0;
}

.app-header-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.app-header a {
  color: #f1e4c8;
  text-decoration: none;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.app-header a:hover {
  background: rgba(184, 134, 46, 0.25);
  color: var(--gold-light);
}

.app-header button.secondary {
  background: transparent;
  color: #f1e4c8;
  border: 1px solid rgba(241, 228, 200, 0.35);
  font-size: 0.95rem;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
}

.app-header button.secondary:hover {
  background: rgba(184, 134, 46, 0.25);
  border-color: var(--gold-light);
}

.app-main {
  padding: 1.75rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Panels — same elevation/border language as the homepage's .card ── */
.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold);
  border-radius: 10px;
  padding: 1.75rem 1.5rem;
  box-shadow: 0 6px 20px var(--shadow);
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  color: var(--wine);
  font-weight: 700;
}

.panel h3 {
  color: var(--wine);
  font-size: 1rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
  font-weight: 600;
}

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

select, input, textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(184, 134, 46, 0.18);
}

.muted {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

button {
  padding: 0.6rem 1.2rem;
  border-radius: 6px;
  border: 1px solid var(--wine);
  background: var(--wine);
  color: #f6ecd8;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}

button:hover {
  background: var(--wine-deep);
  box-shadow: 0 4px 14px rgba(61, 14, 22, 0.2);
}

button:active {
  transform: scale(0.98);
}

button.secondary {
  background: #fff;
  color: var(--wine);
  border-color: var(--border);
}

button.secondary:hover {
  background: #fdf6e8;
  box-shadow: 0 4px 12px var(--shadow);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.scan-controls {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

#reader {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
}

.result-box {
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.result-idle {
  background: #f1e8d3;
  color: var(--ink-soft);
}

.result-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.result-err {
  background: var(--err-bg);
  color: var(--err);
}

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
}

.log-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.log-list li:last-child {
  border-bottom: none;
}

/* ── Tabs — pill style matching the homepage's .nav-links treatment ── */
.tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding: 0.4rem;
  background: rgba(92, 20, 32, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.tabs button {
  background: transparent;
  color: var(--ink-soft);
  border: none;
  font-weight: 600;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  box-shadow: none;
}

.tabs button:hover {
  background: rgba(184, 134, 46, 0.18);
  color: var(--wine);
  box-shadow: none;
  transform: none;
}

.tabs button.active {
  background: var(--wine);
  color: #f6ecd8;
  box-shadow: 0 4px 12px rgba(61, 14, 22, 0.2);
}

.tabs button.active:hover {
  background: var(--wine-deep);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.row-actions button {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}

.row-actions select {
  width: auto;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}

/* ── Tables: horizontal scroll on narrow screens instead of squeezing ── */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}

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

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

th {
  color: var(--wine);
  font-weight: 700;
  border-bottom: 2px solid var(--gold);
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: rgba(184, 134, 46, 0.08);
}

/* ── Mobile scaling ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .app-header {
    padding: 0.85rem 1rem;
  }

  .app-header h1 {
    font-size: 1.05rem;
  }

  .app-header .cross-ornament {
    width: 1.4em;
    height: 1.4em;
  }

  .app-main {
    padding: 1.25rem 1rem 2rem;
    gap: 1rem;
  }

  .panel {
    padding: 1.15rem 1rem;
    border-radius: 8px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    gap: 0.4rem;
  }

  .tabs button {
    flex: 1 1 auto;
    padding: 0.5rem 0.6rem;
    font-size: 0.85rem;
  }

  button {
    padding: 0.6rem 1rem;
  }

  .scan-controls {
    flex-direction: column;
  }

  .scan-controls button {
    width: 100%;
  }

  th, td {
    padding: 0.5rem 0.5rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  .app-header-links {
    width: 100%;
    justify-content: space-between;
  }
}
