:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --primary: #0d6e4f;
  --primary-hover: #0a5a40;
  --border: #d8dee6;
  --accent: #c9a227;
  --success: #198754;
  --error: #c0392b;
  --shadow: 0 2px 12px rgba(26, 35, 50, 0.08);
  --radius: 10px;
  --font: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.brand-banner {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.75rem;
}

.brand-banner-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.brand-logo {
  width: 72px;
  height: auto;
  max-height: 52px;
  object-fit: contain;
  border: none;
  background: transparent;
  flex-shrink: 0;
}

.brand-logo-missing {
  opacity: 0.35;
}

.brand-welcome-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 0.1rem;
}

.brand-welcome-msg {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.header {
  background: linear-gradient(135deg, #0d6e4f 0%, #145a42 50%, #1a2332 100%);
  color: #fff;
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

.subtitle {
  opacity: 0.9;
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.card-head h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e8ecf0;
  color: var(--text);
}

.btn-secondary:hover {
  background: #dde3ea;
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: #f0f4f2;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.status {
  font-size: 0.9rem;
  min-height: 1.4em;
}

.status.ok {
  color: var(--success);
}

.status.err {
  color: var(--error);
}

/* جدول شبيه Excel */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.excel-like .config-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.config-table th,
.config-table td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: right;
  vertical-align: middle;
}

.config-table thead th {
  background: #e8f0ec;
  font-weight: 700;
  color: var(--primary);
}

.config-table tr:nth-child(even) td {
  background: #fafbfc;
}

.config-table .label {
  font-weight: 600;
  width: 22%;
  background: #f4f7f5;
  white-space: nowrap;
}

.config-table .note {
  font-size: 0.8rem;
  color: var(--muted);
  width: 28%;
}

.config-table input {
  width: 100%;
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: #fff;
}

.config-table input:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

/* تقارير */
.reports-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.report-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem 1rem;
  padding: 1rem;
  background: #f4f7f5;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.report-filters.hidden {
  display: none !important;
}

.filter-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.filter-field input {
  width: 100%;
  font-family: var(--font);
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}

.filter-field input:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

/* منتقي التاريخ بأسهم (من / إلى) */
.filter-field-date {
  min-width: 280px;
}

.date-stepper {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  direction: rtl;
}

.date-stepper-label {
  background: linear-gradient(180deg, #5a5a5a 0%, #3d3d3d 100%);
  color: #f5e6a8;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.45rem 0.65rem;
  border-radius: 4px;
  border: 1px solid #2a2a2a;
  box-shadow: 2px 2px 0 #1a1a1a;
  white-space: nowrap;
  min-width: 4.5rem;
  text-align: center;
  flex-shrink: 0;
  pointer-events: none;
}

.date-stepper-arrows {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.date-arrow {
  width: 32px;
  height: 26px;
  padding: 0;
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
  background: linear-gradient(180deg, #f8f8f8 0%, #d8d8d8 100%);
  border: 1px solid #888;
  box-shadow: 1px 1px 0 #333;
  color: #0d6e4f;
  font-weight: 700;
  border-radius: 2px;
}

.date-arrow:hover {
  background: #fff;
}

.date-arrow:active {
  box-shadow: inset 1px 1px 2px #666;
  transform: translate(1px, 1px);
}

.date-stepper-value {
  background: linear-gradient(180deg, #5a5a5a 0%, #3d3d3d 100%);
  color: #f5e6a8;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: 1px solid #2a2a2a;
  box-shadow: 2px 2px 0 #1a1a1a;
  min-width: 6.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  direction: ltr;
  display: inline-block;
}

.report-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #e8f5ef;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.report-summary-bar strong {
  color: var(--primary);
}

.select {
  font-family: var(--font);
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 200px;
}

.report-meta {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

body[data-page="report"] #report-page-desc,
body[data-page="report"] #report-meta,
body[data-page="item"] .header .subtitle,
body[data-page="item"] #movement-meta {
  display: none !important;
}

.report-meta.hidden,
.report-table-wrap.hidden,
.hidden {
  display: none !important;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: right;
  white-space: nowrap;
}

.data-table thead th {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  position: sticky;
  top: 0;
}

.data-table tbody tr:nth-child(even) {
  background: #f8faf9;
}

.data-table tbody tr:hover {
  background: #eef5f1;
}

.report-table-wrap {
  max-height: 480px;
  overflow: auto;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
  font-size: 0.95rem;
}

.collapsed-section details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.collapsed-section textarea {
  width: 100%;
  font-family: Consolas, monospace;
  font-size: 0.85rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
  resize: vertical;
}

.server-offline-banner {
  background: #fde8e8;
  border: 1px solid #e8a0a0;
  color: #8b1a1a;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.server-offline-banner ol {
  margin: 0.5rem 1.25rem 0 0;
}

.server-offline-banner a {
  color: var(--primary);
  font-weight: 700;
}

.badge-locked {
  font-size: 0.75rem;
  font-weight: 700;
  background: #fff3cd;
  color: #856404;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}

.card-compact {
  padding: 0.5rem 0.75rem;
}

.connection-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  min-height: 0;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.35rem 0.75rem;
  font-weight: 600;
}

.connection-locked {
  text-align: center;
  padding: 1rem 0.5rem;
}

.connection-locked-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.75rem;
}

.pin-setup-guide {
  text-align: right;
  background: #fff8e6;
  border: 1px solid #e6d9a8;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-size: 0.85rem;
}

.pin-setup-guide ol {
  margin: 0.5rem 1.25rem 0 0;
  padding: 0;
}

.pin-setup-guide li {
  margin: 0.35rem 0;
}

.connection-summary {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.75rem 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.hidden {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 35, 50, 0.5);
}

.modal-box {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-box h3 {
  margin-bottom: 0.5rem;
  color: var(--primary);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

#pin-modal-error.hidden {
  display: none;
}

.reports-nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.75rem;
}

.report-card {
  display: block;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafcfb;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}

.report-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(13, 110, 79, 0.12);
}

.report-card-title {
  display: block;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.report-card-desc {
  display: none !important;
}

.report-card-arrow {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--primary);
  font-weight: 700;
}

.top-nav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-home {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.nav-home:hover {
  text-decoration: underline;
}

.nav-sep {
  color: var(--muted);
}

.nav-current {
  color: var(--muted);
}

.header-compact {
  padding: 1rem 1.5rem;
}

.header-compact h1 {
  font-size: 1.25rem;
}

.connection-warn {
  background: #fff3cd;
  border: 1px solid #e6d9a8;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.connection-warn a {
  color: var(--primary);
  font-weight: 700;
}

.item-search-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.filter-field-scan {
  grid-column: 1 / -1;
}

.input-with-scan {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.input-with-scan input {
  flex: 1;
  min-width: 0;
}

.btn-scan-barcode {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.4rem 0.65rem;
  min-width: 3.5rem;
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(13, 110, 79, 0.35);
}

.btn-scan-barcode:hover {
  background: var(--primary-hover);
}

.btn-scan-icon {
  font-size: 1.25rem;
  line-height: 1;
}

.modal-box-scan {
  max-width: 400px;
  width: 100%;
}

.barcode-reader {
  width: 100%;
  min-height: 220px;
  margin: 0.75rem 0;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
}

.barcode-reader video {
  width: 100% !important;
  border-radius: 8px;
}

.barcode-status {
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

.barcode-status.err {
  color: var(--error);
}

.item-summary {
  margin-top: 1.25rem;
  padding: 1.25rem;
  background: #e8f5ef;
  border-radius: 10px;
  border: 1px solid #b8dcc8;
}

.item-summary-title {
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
  font-size: 1.05rem;
}

.item-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.item-stat {
  background: #fff;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  text-align: center;
}

.item-stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.item-stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
}

.item-movement-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.movement-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--border);
}

.movement-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.item-pick-list {
  margin-top: 1rem;
  max-height: min(50vh, 320px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  background: #fafcfa;
}

.item-pick-btn {
  display: block;
  width: 100%;
  text-align: right;
  margin: 0.35rem 0;
  padding: 0.75rem 0.85rem;
  min-height: 44px;
  font-family: var(--font);
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

.item-pick-btn:hover {
  border-color: var(--primary);
  background: #f0f8f4;
}

#search-error.hidden {
  display: none;
}

.table-scroll-hint {
  display: none;
  margin: 0.5rem 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.movement-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.movement-data-table thead th {
  white-space: normal;
  line-height: 1.25;
  font-size: 0.75rem;
  padding: 0.35rem 0.3rem;
  max-width: 5rem;
  vertical-align: middle;
  word-break: break-word;
}

.movement-data-table td:first-child,
.movement-data-table th:first-child {
  max-width: 5.5rem;
}

@media (max-width: 768px) {
  .table-scroll-hint {
    display: block;
  }

  .movement-table-scroll .data-table,
  .movement-table-scroll .movement-data-table {
    font-size: 0.72rem;
    min-width: 0;
    width: max-content;
    max-width: 100%;
  }

  .movement-table-scroll .data-table td {
    padding: 0.35rem 0.4rem;
    white-space: nowrap;
    font-size: 0.72rem;
  }

  .movement-table-scroll .data-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: normal;
    line-height: 1.2;
    font-size: 0.62rem;
    font-weight: 600;
    padding: 0.3rem 0.28rem;
    max-width: 3.6rem;
    min-width: 2.4rem;
    vertical-align: middle;
    word-break: break-word;
    hyphens: auto;
  }

  .movement-table-scroll .data-table thead th:first-child {
    max-width: 4.2rem;
    min-width: 4rem;
  }

  .item-search-bar {
    grid-template-columns: 1fr;
  }

  .item-summary {
    margin-top: 0.65rem;
    padding: 0.6rem 0.7rem;
  }

  .item-summary-title {
    margin-bottom: 0.45rem;
    font-size: 0.92rem;
    line-height: 1.35;
  }

  .item-summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.45rem;
    margin-bottom: 0.55rem;
  }

  .item-stat {
    padding: 0.4rem 0.35rem;
  }

  .item-stat-label {
    font-size: 0.68rem;
    margin-bottom: 0.1rem;
    line-height: 1.2;
  }

  .item-stat-value {
    font-size: 1rem;
    line-height: 1.2;
  }

  .item-movement-actions .btn {
    padding: 0.45rem 0.85rem;
    font-size: 0.88rem;
  }
}

.footer {
  text-align: center;
  padding: 1.25rem 1rem 1.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  background: #fff;
  margin-top: 1rem;
}

.footer-credit {
  margin: 0 0 0.35rem;
  line-height: 1.5;
}

.footer-phones,
.footer-phone {
  margin: 0.15rem 0 0;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  justify-content: center;
  align-items: center;
}

.footer-phones a,
.footer-phone a {
  color: var(--primary);
  text-decoration: none;
  direction: ltr;
  unicode-bidi: embed;
}

.footer-phones a:hover,
.footer-phone a:hover {
  text-decoration: underline;
}

.footer-phone-sep {
  color: var(--muted);
  font-weight: 400;
  user-select: none;
}

@media (max-width: 768px) {
  .footer-phones {
    flex-direction: column;
    gap: 0.2rem;
  }

  .footer-phone-sep {
    display: none;
  }
}

.footer-partner-logo {
  display: block;
  max-width: 180px;
  width: auto;
  height: auto;
  max-height: 48px;
  margin: 0 auto 0.5rem;
  object-fit: contain;
}

@media (max-width: 768px) {
  .brand-banner {
    padding: 0.35rem 0.55rem;
  }

  .brand-logo {
    width: 56px;
    max-height: 40px;
  }

  .brand-welcome-title {
    font-size: 0.85rem;
  }

  .brand-welcome-msg {
    font-size: 0.72rem;
  }

  .footer-partner-logo {
    max-width: 130px;
    max-height: 36px;
    margin-bottom: 0.4rem;
  }
}

@media (max-width: 640px) {
  .config-table .note {
    display: none;
  }
}
