:root {
  --primary: #ab8358;
  --primary-dark: #8a6a42;
  --bg: #f1e9db;
  --card-bg: #ffffff;
  --text: #2b2118;
  --muted: #8c8171;
  --border: #e6dcc8;
  --success: #4f7d4f;
  --warning: #ab8358;
  --danger: #c0392b;
  --header-bg: #241a12;
  --radius: 12px;
  --font: 'Cairo', 'Segoe UI', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; font-family: inherit; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.container-wide { max-width: 1400px; }

/* Header */
.site-header {
  background: var(--header-bg);
  padding: 14px 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.brand { grid-column: 2; justify-self: center; display: flex; align-items: center; gap: 12px; }
.brand a { display: block; line-height: 0; cursor: pointer; }
.brand-logo { height: 32px; width: auto; display: block; }

.header-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-tagline { font-size: 14px; font-weight: 600; color: #b9ac97; }

.lang-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #e4e4e4;
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  min-width: 42px;
}
.lang-btn:hover { background: rgba(255, 255, 255, 0.12); }

/* Hamburger */
.hamburger {
  grid-column: 1;
  justify-self: start;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 8px;
  border-radius: 8px;
}
.hamburger:hover { background: rgba(255, 255, 255, 0.12); }
.hamburger span { display: block; height: 2px; background: #e4e4e4; border-radius: 2px; }

/* Sidebar drawer */
.sidebar {
  position: fixed;
  top: 0;
  inset-inline-start: 0;
  height: 100%;
  width: 260px;
  background: var(--header-bg);
  z-index: 1100;
  transform: translateX(-110%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 8px;
}
[dir="rtl"] .sidebar { transform: translateX(110%); }
[dir="ltr"] .sidebar.open,
[dir="rtl"] .sidebar.open { transform: translateX(0); }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sidebar-logo { height: 30px; width: auto; }
.sidebar-close {
  background: transparent; border: none; color: #e4e4e4;
  font-size: 26px; line-height: 1; cursor: pointer; padding: 0 6px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 6px; }
.sidebar-nav a {
  text-decoration: none;
  color: #e4e4e4;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
}
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.sidebar-nav a:not(.active):hover { background: rgba(255, 255, 255, 0.1); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.12); padding-top: 12px; }
.sidebar-user { color: #b9ac97; font-size: 12px; margin-bottom: 6px; padding: 0 14px; word-break: break-all; }
.logout-btn {
  width: 100%;
  text-align: start;
  background: transparent;
  border: none;
  color: #e4e4e4;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.1); }

/* Login page */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1100px 560px at 50% -12%, #3a2c1d 0%, var(--header-bg) 58%);
}
.login-wrap { width: 100%; max-width: 420px; }
.login-card {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 34px 30px 30px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: ''; position: absolute; top: 0; inset-inline: 0; height: 5px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-logo-circle {
  width: 84px; height: 84px; margin: 4px auto 12px; border-radius: 50%;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 0 0 1px var(--border);
}
.login-logo { height: 46px; width: auto; }
.login-name { font-size: 24px; font-weight: 800; color: var(--text); letter-spacing: .5px; }
.login-name span { color: var(--primary); }
.login-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--bg); border-radius: 12px; padding: 5px; margin-bottom: 22px;
}
.auth-tab {
  border: none; background: transparent; cursor: pointer; font-family: inherit;
  font-size: 15px; font-weight: 700; color: var(--muted);
  padding: 11px 8px; border-radius: 9px; transition: background .2s ease, color .2s ease;
}
.auth-tab.active { background: var(--primary); color: #fff; box-shadow: 0 3px 10px rgba(171, 131, 88, .35); }

.login-btn { width: 100%; margin-top: 8px; padding: 12px; font-size: 16px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.login-lang { position: absolute; top: 16px; inset-inline-start: 16px; color: var(--text); border-color: var(--border); z-index: 2; }
#loginForm .field { margin-bottom: 14px; }
#loginForm input { width: 100%; }
/* Export / import toolbar */
.data-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.data-tools .btn { padding: 7px 12px; font-size: 13px; }

/* Reports page */
.rep-filters { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.rep-filters .field { margin: 0; }
.rep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .rep-grid { grid-template-columns: 1fr; } }
.bar-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr 44px; align-items: center; gap: 10px; margin: 10px 0; }
.bar-label { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { background: var(--bg); border-radius: 6px; height: 22px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--primary); transition: width .3s ease; }
.bar-count { text-align: end; font-weight: 700; font-variant-numeric: tabular-nums; }
.month-chart { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding-top: 8px; }
.month-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; }
.month-bar { width: 72%; background: var(--primary); border-radius: 6px 6px 0 0; min-height: 2px; }
.month-val { font-size: 11px; font-weight: 700; color: var(--text); }
.month-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.form-status { min-height: 20px; margin: 6px 0 4px; font-size: 14px; font-weight: 700; }
.form-status.ok { color: var(--success); }
.form-status.err { color: var(--danger); }
.login-forgot { display: inline-block; font-size: 13px; color: var(--primary); text-decoration: none; margin-bottom: 8px; }
.login-forgot:hover { text-decoration: underline; }
.login-error.ok { color: var(--success); }
/* Signup-only fields + forgot link visibility, toggled by .signup-mode on the form.
   High specificity so the later generic `.field { display:flex }` can't override it. */
#loginForm .signup-only { display: none; }
#loginForm.signup-mode .signup-only { display: flex; }
#loginForm.signup-mode .login-forgot { display: none; }

/* Sidebar profile link (moved into the footer, above the user row) */
.sidebar-profile-link {
  display: block; text-decoration: none; color: #e4e4e4;
  padding: 12px 14px; border-radius: 8px; font-weight: 600; margin-bottom: 8px;
}
.sidebar-profile-link.active { background: var(--primary); color: #fff; }
.sidebar-profile-link:not(.active):hover { background: rgba(255, 255, 255, 0.1); }

/* Pending-account gate */
.pending-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--header-bg); padding: 20px; }
.pending-card { background: var(--card-bg); border-radius: var(--radius); padding: 36px 28px; max-width: 420px; width: 100%; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.pending-logo { height: 54px; margin-bottom: 18px; }
.pending-card h1 { font-size: 20px; margin: 0 0 10px; color: var(--text); }
.pending-card p { color: var(--muted); font-size: 15px; line-height: 1.7; margin: 0 0 22px; }

/* Profile page */
.avatar-block { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 20px; }
.avatar-img { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 3px solid var(--primary); display: none; }
.avatar-ph {
  width: 120px; height: 120px; border-radius: 50%;
  background: var(--bg); border: 3px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 46px; font-weight: 700;
}
.avatar-actions { display: flex; gap: 10px; align-items: center; }
.avatar-upload { position: relative; overflow: hidden; }
.avatar-upload input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
input:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.field-note { font-size: 11px; color: var(--muted); }

/* Sidebar user block */
.sidebar-user-row { display: flex; align-items: center; gap: 10px; padding: 0 14px 8px; }
.sidebar-avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--primary); display: none; flex: none;
}
.sidebar-user-name { color: #fff; font-weight: 700; font-size: 14px; }

/* Card */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.card-header h1, .card-header h2 { margin: 0; font-size: 18px; }

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }

.field label { font-size: 13px; font-weight: 600; color: var(--muted); }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; }

.form-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 22px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }

.btn-outline { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover:not(:disabled) { background: #f4ede1; }
.btn-outline:disabled { color: var(--muted); border-color: var(--border); cursor: not-allowed; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a5301f; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 26, 18, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: modal-fade 0.15s ease-out;
}

@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(36, 26, 18, 0.3);
  border-top: 4px solid var(--primary);
  animation: modal-pop 0.18s ease-out;
}

@keyframes modal-pop { from { transform: translateY(8px) scale(0.98); } to { transform: translateY(0) scale(1); } }

.modal-title { margin: 0 0 8px; font-size: 17px; color: var(--text); }
.modal-message { margin: 0 0 16px; font-size: 14px; color: var(--muted); }

.modal-input {
  width: 100%;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}

/* Image preview */
.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.thumb {
  position: relative;
  width: 90px;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb-remove {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(192, 57, 41, 0.9);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.field-hint {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  align-self: flex-start;
}

.field-hint:hover { text-decoration: underline; }

/* Documents */
.documents-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}

.doc-item span { flex: 1; }

/* Status select (themed dropdown) */
.status-select {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 8px center;
  padding-left: 26px;
}
[dir="rtl"] .status-select { background-position: left 8px center; padding-left: 26px; padding-right: 10px; }
[dir="ltr"] .status-select { background-position: right 8px center; padding-right: 26px; padding-left: 10px; }

.status-select.badge-new { background-color: #f1eadb; color: var(--warning); }
.status-select.badge-progress { background-color: #dcecf7; color: #1c5f8a; }
.status-select.badge-manufactured { background-color: #e6def5; color: #6a4fb0; }
.status-select.badge-shipped { background-color: #dcf3e4; color: var(--success); }

.order-link { color: var(--primary); font-weight: 700; text-decoration: none; }
.order-link:hover { text-decoration: underline; }

.tracking-value { font-weight: 600; }

/* Table */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: start;
  background: var(--bg);
  color: var(--muted);
  font-weight: 700;
  padding: 9px 10px;
  border-bottom: 2px solid var(--border);
}

tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

/* Orders table: fits on wide desktop; scrolls smoothly on small screens */
.orders-table { min-width: 1080px; }
.orders-table td, .orders-table th { white-space: nowrap; }
.col-date { white-space: nowrap; }

tbody tr:hover { background: #faf6ee; }

.empty { text-align: center; color: var(--muted); padding: 24px !important; }

.row-actions { display: flex; gap: 8px; align-items: center; }

.link-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

.icon-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.icon-btn svg { display: block; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-new { background: #f1eadb; color: var(--warning); }
.badge-progress { background: #dcecf7; color: #1c5f8a; }
.badge-manufactured { background: #e6def5; color: #6a4fb0; }
.badge-shipped { background: #dcf3e4; color: var(--success); }
.badge-cancelled { background: #f2dede; color: var(--danger); }
.status-select.badge-cancelled { background-color: #f2dede; color: var(--danger); }

.row-overdue { background: #fdf0ef; }
.overdue-tag {
  display: inline-block;
  margin-right: 6px;
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

/* Dashboard summary cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.summary-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  border-top: 4px solid var(--muted);
}

.summary-card.accent-blue { border-top-color: #1c5f8a; }
.summary-card.accent-purple { border-top-color: #6a4fb0; }
.summary-card.accent-green { border-top-color: var(--success); }
.summary-card.accent-gray { border-top-color: var(--muted); }
.summary-card.accent-red { border-top-color: var(--danger); }

.summary-value { font-size: 28px; font-weight: 800; }
.summary-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Filters bar */
.filters-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}

.filters-bar select, .filters-bar input { min-width: 160px; }

/* Print */
#print-area { display: none; }

body.printing > *:not(#print-area) { display: none !important; }
body.printing #print-area { display: block !important; }

#print-area .print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 3px solid var(--primary-dark);
  padding-bottom: 10px;
  margin-bottom: 18px;
}

#print-area .print-header h2 { margin: 0; color: var(--primary-dark); }
.print-logo { height: 36px; width: auto; display: block; margin-bottom: 4px; }

#print-area table { width: 100%; border-collapse: collapse; margin-bottom: 18px; }

#print-area th, #print-area td {
  border: 1px solid #333;
  padding: 8px 10px;
  text-align: start;
  font-size: 14px;
}

#print-area th { background: #f0f0f0; width: 22%; }
.print-meta { text-align: start; }

.print-images { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.print-images img { width: 150px; height: 150px; object-fit: cover; border: 1px solid #333; }

.print-footer {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 14px;
}

.pledge {
  margin-top: 18px;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.9;
}

.pledge p { margin: 6px 0 0; }

@media print {
  @page { margin: 15mm; }
}

@media (max-width: 720px) {
  .header-tagline { display: none; }
  .site-header { padding: 12px 14px; }
  .brand-logo { height: 26px; }
  .container { padding: 16px 10px 40px; }
  .card { padding: 16px 14px; }
  .card-header h1, .card-header h2 { font-size: 16px; }
  .summary-value { font-size: 24px; }
  .form-actions .btn { flex: 1; }
}

@media (max-width: 400px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
}
