:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --dark: #0f172a;
  --slate: #475569;
  --light-bg: #f8fafc;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Cairo", "Tajawal", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--light-bg);
  color: #1e293b;
  direction: rtl;
  text-align: right;
  line-height: 1.6;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

.sidebar {
  width: 260px;
  background-color: #0f172a;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 18px;
  font-size: 1.15rem;
  font-weight: 700;
  border-bottom: 1px solid #1e293b;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #60a5fa;
  white-space: nowrap;
}

.sidebar-brand .brand-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  transition: opacity 0.2s ease;
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.25rem;
  cursor: pointer;
  margin-right: auto;
  padding: 4px 8px;
  border-radius: 6px;
}
.sidebar-close-btn:hover {
  color: #fff;
  background: #1e293b;
}

.sidebar-menu {
  list-style: none;
  padding: 12px 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.sidebar-menu li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  color: #94a3b8;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.sidebar-menu li a .menu-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.sidebar-menu li a .menu-text {
  transition: opacity 0.2s ease;
}

.sidebar-menu li a:hover,
.sidebar-menu li.active a {
  background-color: #1e293b;
  color: #ffffff;
  border-right: 4px solid var(--primary);
}

/* Collapsed Desktop Sidebar */
body.sidebar-collapsed .sidebar {
  width: 72px;
}

body.sidebar-collapsed .sidebar .brand-text,
body.sidebar-collapsed .sidebar .menu-text {
  display: none;
}

body.sidebar-collapsed .sidebar .sidebar-brand {
  justify-content: center;
  padding: 20px 0;
}

body.sidebar-collapsed .sidebar-menu li a {
  justify-content: center;
  padding: 13px 0;
}

body.sidebar-collapsed .sidebar-menu li a .menu-icon {
  font-size: 1.35rem;
  width: auto;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  min-width: 0;
  background-color: var(--light-bg);
}

.top-navbar {
  background: var(--card-bg);
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}

.sidebar-toggle-btn {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 1.1rem;
  cursor: pointer;
  color: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
  background: #e2e8f0;
  color: var(--primary);
}

.page-body {
  padding: 25px;
  flex: 1;
}

/* Cards & Containers */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  margin-bottom: 24px;
}

.card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
}

.card-body {
  padding: 24px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.stat-val {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin-top: 8px;
}

.stat-label {
  color: var(--slate);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
}

.table th, .table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.table th {
  background-color: #f8fafc;
  color: #475569;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
}

.table tr:hover {
  background-color: #f1f5f9;
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #334155;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: #fff;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  font-family: inherit;
}

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

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border-color: #cbd5e1;
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #e0f2fe; color: #075985; }

/* Alerts */
.alert {
  padding: 14px 20px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-weight: 500;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

/* Canvas Designer */
.designer-container {
  display: flex;
  gap: 20px;
  background: #f1f5f9;
  padding: 20px;
  border-radius: 12px;
  min-height: 600px;
}

.designer-sidebar {
  width: 280px;
  background: #fff;
  border-radius: 10px;
  padding: 15px;
  border: 1px solid var(--border);
}

.designer-canvas-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  padding: 30px;
  background: #cbd5e1;
  border-radius: 10px;
  min-height: 550px;
}

.certificate-canvas {
  position: relative !important;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  transform-origin: center center;
  direction: ltr !important;
  text-align: left !important;
  flex-shrink: 0 !important;
  margin: auto !important;
  box-sizing: border-box !important;
}

.canvas-element {
  position: absolute !important;
  cursor: move;
  border: 1px dashed rgba(37, 99, 235, 0.5);
  user-select: none;
  box-sizing: border-box !important;
  transform-origin: top left;
}

.canvas-element:hover {
  border-color: var(--primary);
}

.canvas-element.selected {
  border: 2px solid #2563eb !important;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
  z-index: 100 !important;
}

.resize-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background-color: #2563eb;
  border: 2px solid #ffffff;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 101;
}

.resize-handle.handle-se {
  right: -6px;
  bottom: -6px;
  cursor: se-resize;
}
.resize-handle.handle-sw {
  left: -6px;
  bottom: -6px;
  cursor: sw-resize;
}
.resize-handle.handle-ne {
  right: -6px;
  top: -6px;
  cursor: ne-resize;
}
.resize-handle.handle-nw {
  left: -6px;
  top: -6px;
  cursor: nw-resize;
}
.resize-handle.handle-e {
  right: -6px;
  top: calc(50% - 5px);
  cursor: e-resize;
}
.resize-handle.handle-w {
  left: -6px;
  top: calc(50% - 5px);
  cursor: w-resize;
}
.resize-handle.handle-s {
  bottom: -6px;
  left: calc(50% - 5px);
  cursor: s-resize;
}
.resize-handle.handle-n {
  top: -6px;
  left: calc(50% - 5px);
  cursor: n-resize;
}

.dimension-badge {
  position: absolute;
  bottom: -22px;
  right: 0;
  background: #0f172a;
  color: #ffffff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  font-family: monospace;
  opacity: 0.95;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* =========================================================
   Responsive Public Portal & QR Verification Styles
   ========================================================= */

.verify-details-table {
  width: 100%;
  border-collapse: collapse;
}

.verify-details-table tr {
  border-bottom: 1px solid #e2e8f0;
}
.verify-details-table tr:last-child {
  border-bottom: none;
}

.verify-details-table td {
  padding: 12px 6px;
  vertical-align: middle;
}

.verify-details-table td.label-cell {
  color: #64748b;
  font-weight: 600;
  width: 32%;
  font-size: 0.9rem;
}

.verify-details-table td.value-cell {
  color: #0f172a;
  font-weight: 700;
  font-size: 0.95rem;
  word-break: break-word;
}

.verify-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.verify-actions .btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 0.95rem;
}

.cert-result-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  padding: 18px 20px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
  gap: 15px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cert-result-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}

.cert-result-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Backdrop for Mobile Sidebar */
.sidebar-backdrop {
  display: none;
}

/* =========================================================
   Media Queries & Mobile Optimization
   ========================================================= */

@media (max-width: 992px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    width: 270px;
    z-index: 1050;
    transform: translateX(100%);
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.25);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(3px);
    z-index: 1040;
  }

  body.sidebar-open .sidebar-backdrop {
    display: block;
  }

  .sidebar-close-btn {
    display: block;
  }

  .top-navbar {
    padding: 12px 18px;
  }

  .page-body {
    padding: 18px;
  }

  .designer-container {
    flex-direction: column;
  }
  
  .designer-sidebar {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .top-navbar {
    padding: 10px 14px;
  }

  .top-navbar .navbar-title {
    font-size: 0.95rem !important;
  }

  .top-navbar .admin-badge {
    font-size: 0.72rem;
    padding: 3px 7px;
  }

  .top-navbar .portal-btn-text {
    display: none;
  }

  .page-body {
    padding: 14px;
  }

  .card-header {
    padding: 14px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .card-body {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stat-val {
    font-size: 1.6rem;
  }

  /* Public Search & Verification Mobile Adjustments */
  .verify-actions {
    flex-direction: column;
    gap: 10px;
  }

  .verify-actions .btn {
    width: 100%;
    padding: 12px;
    font-size: 0.95rem;
  }

  .verify-details-table tr {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
  }

  .verify-details-table td {
    padding: 2px 0 !important;
  }

  .verify-details-table td.label-cell {
    width: 100% !important;
    font-size: 0.8rem;
    color: #64748b;
  }

  .verify-details-table td.value-cell {
    width: 100% !important;
    font-size: 0.95rem;
  }

  .cert-result-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  .cert-result-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .cert-result-actions .btn {
    width: 100%;
    padding: 10px 8px;
    font-size: 0.85rem;
    text-align: center;
    justify-content: center;
  }
}
