/* ============================================================
   Admin Panel V6 - Full Styles + Checkbox Filters Fix + Dark Mode
============================================================ */

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

body {
  font-family: 'Tajawal', sans-serif;
  background: #fbfbfb;
  color: #1a1a1a;
  min-height: 100vh;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ============ Login ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #f5faf7 0%, #fbfbfb 100%);
}

.login-box {
  background: #fff;
  width: 100%;
  max-width: 440px;
  border: 1px solid #ebebeb;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.04);
  overflow: hidden;
}

.login-header {
  background: #2d6a4f;
  color: #fff;
  padding: 32px 24px;
  text-align: center;
  border-bottom: 3px solid #c9a961;
}

.login-header h1 { font-size: 20px; font-weight: 700; margin-bottom: 5px; }
.login-header p { font-size: 13px; opacity: 0.85; }

.login-body { padding: 32px 28px; }

.login-body label {
  display: block;
  font-size: 13.5px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #1a1a1a;
}

.login-body input {
  width: 100%;
  padding: 13px 16px;
  border: 1.5px solid #ebebeb;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
  margin-bottom: 18px;
  background: #fbfbfb;
  color: #1a1a1a;
}

.login-body input#passwordInput {
  text-align: center;
  letter-spacing: 3px;
  font-size: 17px;
}

.login-body input:focus {
  border-color: #2d6a4f;
  background: #fff;
  box-shadow: 0 0 0 4px #e8f3ed;
}

.btn-login {
  width: 100%;
  padding: 14px;
  background: #2d6a4f;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn-login:hover { background: #1b4332; }
.btn-login:disabled { background: #ccc; cursor: not-allowed; }

.login-footer {
  padding: 16px 24px 20px;
  text-align: center;
  border-top: 1px solid #f5f5f5;
  font-size: 13px;
}

.login-footer a {
  color: #2d6a4f;
  text-decoration: none;
  font-weight: 600;
}

.login-footer a:hover { text-decoration: underline; }

/* ============ Messages ============ */
.message {
  margin-top: 15px;
  padding: 12px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 8px;
  text-align: center;
}

.message.error {
  background: #fdf2f0;
  color: #c0392b;
  border: 1px solid #f5d5d0;
}

.message.success {
  background: #e8f3ed;
  color: #2d6a4f;
  border: 1px solid #c8e0d3;
}

.system-message {
  max-width: 1200px;
  margin: 15px auto 0;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
}

.system-message.error {
  background: #fdf2f0;
  color: #c0392b;
  border-right: 4px solid #c0392b;
}

.system-message.success {
  background: #e8f3ed;
  color: #2d6a4f;
  border-right: 4px solid #2d6a4f;
}

/* ============ Panel Header ============ */
.panel-wrap {
  min-height: 100vh;
  background: #fbfbfb;
  padding-bottom: 40px;
}

.panel-header {
  background: #fff;
  border-bottom: 1px solid #ebebeb;
  padding: 18px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.panel-title { display: flex; align-items: center; gap: 12px; }

.panel-title h1 {
  font-size: 19px;
  color: #1a1a1a;
  font-weight: 700;
}

.badge {
  background: #e8f3ed;
  color: #2d6a4f;
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 700;
}

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

/* ============ Tabs ============ */
.admin-tabs {
  max-width: 1200px;
  margin: 20px auto 0;
  padding: 0 32px;
  display: flex;
  gap: 6px;
  border-bottom: 1px solid #ebebeb;
  overflow-x: auto;
}

.admin-tab {
  background: transparent;
  border: none;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #999;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  transition: all 0.2s;
  white-space: nowrap;
}

.admin-tab:hover { color: #2d6a4f; }

.admin-tab.active {
  color: #2d6a4f;
  border-bottom-color: #c9a961;
}

/* ============ Content ============ */
.panel-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 32px;
}

.tab-content { animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Cards ============ */
.card {
  background: #fff;
  border: 1px solid #ebebeb;
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}

.card-danger { border-color: #f5d5d0; }

.card-header {
  background: #fafafa;
  border-bottom: 1px solid #f0f0f0;
  padding: 14px 22px;
}

.card-danger .card-header { background: #fdf2f0; }

.card-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: #1a1a1a;
}

.card-danger .card-header h2 { color: #c0392b; }

.card-body { padding: 20px 22px; }
.card-body.no-padding { padding: 0; }

.hint {
  font-size: 13px;
  color: #666;
  margin-bottom: 15px;
  line-height: 1.7;
}

.sub-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
  color: #1a1a1a;
}

/* ============ Audit Checkbox Filters ============ */
.audit-filters-bar {
  background: #fafafa;
  border-bottom: 1px solid #ebebeb;
  padding: 14px 22px;
}

.audit-filters-bar .filters-title {
  font-size: 13px;
  font-weight: 700;
  color: #444;
  margin-bottom: 10px;
}

.audit-filters-group {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: #333;
}

.audit-filters-group label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 600;
}

.audit-filters-group input[type="checkbox"] {
  accent-color: #2d6a4f;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ============ Codes Table ============ */
.codes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: #fff;
}

.codes-table th {
  background: #fafafa;
  color: #666;
  padding: 12px 16px;
  text-align: right;
  font-weight: 700;
  font-size: 12.5px;
  border-bottom: 1px solid #ebebeb;
}

.codes-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #f5f5f5;
  vertical-align: middle;
  color: #1a1a1a;
}

.codes-table tr:hover td { background: #fafafa; }
.codes-table tr:last-child td { border-bottom: none; }

.code-value {
  font-family: 'Courier New', monospace;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #2d6a4f;
}

.status-sent { color: #2d6a4f; font-weight: 700; }
.status-available { color: #999; font-weight: 600; }

.loading-cell {
  text-align: center;
  padding: 40px;
  color: #999;
  font-style: italic;
}

/* ============ Search Bar ============ */
.search-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.search-bar input {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border: 1.5px solid #ebebeb;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
  background: #fbfbfb;
}

.search-bar input:focus {
  border-color: #2d6a4f;
  background: #fff;
  box-shadow: 0 0 0 3px #e8f3ed;
}

.search-bar select {
  padding: 12px 16px;
  border: 1.5px solid #ebebeb;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  cursor: pointer;
  outline: none;
}

/* ============ Archive Table ============ */
.archive-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: #fff;
}

.archive-table thead th {
  background: #f7f7f7;
  color: #555;
  padding: 14px 16px;
  text-align: right;
  font-weight: 700;
  font-size: 12.5px;
  border-bottom: 2px solid #ebebeb;
  letter-spacing: 0.3px;
}

.archive-table tbody td {
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  color: #1a1a1a;
}

.archive-table tbody tr:last-child td { border-bottom: none; }
.archive-table tbody tr:hover { background: #fafafa; }

.serial-cell { text-align: center; }

.serial-num {
  display: block;
  font-family: 'Courier New', monospace;
  font-size: 18px;
  font-weight: 700;
  color: #2d6a4f;
  line-height: 1.2;
}

.code-sub {
  display: block;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  color: #999;
  letter-spacing: 1px;
  margin-top: 3px;
}

.name-cell {
  font-weight: 600;
  color: #1a1a1a;
  font-size: 14px;
}

.date-cell {
  font-family: 'Courier New', monospace;
  color: #666;
  font-size: 13px;
  font-weight: 600;
}

.actions-cell { white-space: nowrap; }
.actions-cell .btn-action { margin-left: 4px; }

/* ============ Form Grid (Settings) ============ */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .field { min-width: 0; }

.form-grid label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #333;
}

.form-grid input,
.form-grid select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid #ebebeb;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fbfbfb;
  transition: all 0.2s;
  color: #1a1a1a;
}

.form-grid input:focus,
.form-grid select:focus {
  border-color: #2d6a4f;
  background: #fff;
  box-shadow: 0 0 0 3px #e8f3ed;
}

/* ============ Info Rows ============ */
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dotted #f0f0f0;
  font-size: 13.5px;
}

.info-row:last-child { border-bottom: none; }
.info-row strong { color: #666; font-weight: 600; }
.info-row span { color: #1a1a1a; font-weight: 700; }

/* ============ Buttons ============ */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-action {
  padding: 10px 18px;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-primary {
  background: #2d6a4f;
  color: #fff;
}

.btn-primary:hover {
  background: #1b4332;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(45,106,79,0.2);
}

.btn-secondary {
  background: #f5f5f5;
  color: #333;
  border: 1px solid #ebebeb;
}

.btn-secondary:hover { background: #ebebeb; }

.btn-danger {
  background: #c0392b;
  color: #fff;
}

.btn-danger:hover { background: #a52a20; }

.btn-action {
  background: #f5f5f5;
  color: #333;
  border: 1px solid #ebebeb;
  padding: 6px 14px;
  font-size: 12px;
}

.btn-action:hover {
  background: #e8f3ed;
  color: #2d6a4f;
  border-color: #c8e0d3;
}

.btn-action.danger {
  background: #fdf2f0;
  color: #c0392b;
  border-color: #f5d5d0;
}

.btn-action.danger:hover { background: #f5d5d0; }

.btn-action.gold {
  background: #fdf9ef;
  color: #8b6f1e;
  border-color: #e9d5a1;
}

.btn-action.gold:hover { background: #e9d5a1; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: #fff;
  width: 100%;
  max-width: 800px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal-header {
  background: #2d6a4f;
  color: #fff;
  padding: 16px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-close {
  background: transparent;
  color: #fff;
  border: none;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
  padding: 0 5px;
  opacity: 0.8;
}

.modal-close:hover { opacity: 1; }

.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid #f0f0f0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ============ Contract Preview ============ */
.contract-block {
  border: 1px solid #ebebeb;
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}

.contract-block-title {
  background: #fafafa;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 13.5px;
  color: #2d6a4f;
  border-bottom: 1px solid #f0f0f0;
}

.contract-block.gold .contract-block-title {
  background: #fdf9ef;
  color: #8b6f1e;
}

.contract-block-body { padding: 14px 16px; font-size: 13px; }

.contract-row {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px dotted #f5f5f5;
}

.contract-row:last-child { border-bottom: none; }

.contract-row strong {
  color: #666;
  min-width: 160px;
  flex-shrink: 0;
  font-weight: 600;
}

.contract-row span {
  flex: 1;
  word-break: break-word;
  color: #1a1a1a;
}

/* ============ Print ============ */
@media print {
  body * { visibility: hidden; }
  #modalContent, #modalContent * { visibility: visible; }
  #modalContent {
    position: absolute;
    inset: 0;
    padding: 20px;
  }
  .modal-header, .modal-footer { display: none !important; }
  .modal-box { box-shadow: none; max-width: 100%; border-radius: 0; }
  .modal-overlay { background: #fff; }
}

/* ============ Responsive & Icon Buttons ============ */
@media (max-width: 720px) {
  .panel-header { padding: 14px 18px; }
  .panel-title h1 { font-size: 16px; }
  .panel-content { padding: 16px; }
  .admin-tabs { padding: 0 16px; }
  .admin-tab { padding: 10px 14px; font-size: 13px; }

  .codes-table th,
  .codes-table td { padding: 8px; font-size: 12px; }
  .code-value { font-size: 13px; letter-spacing: 1px; }

  .archive-table th,
  .archive-table td { padding: 10px 8px; font-size: 12px; }
  .serial-num { font-size: 15px; }
  .name-cell { font-size: 12.5px; }
  .date-cell { font-size: 11.5px; }

  .actions-cell .btn-action { padding: 4px 8px; font-size: 11px; }

  .contract-row { flex-direction: column; gap: 2px; }
  .contract-row strong { min-width: auto; }

  .search-bar input { min-width: 100%; }

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

/* ============ Icon Buttons - Archive & Table ============ */
.action-icons {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid #ebebeb;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  padding: 0;
  color: #666;
  flex-shrink: 0;
}

.icon-btn svg {
  display: block;
}

/* معاينة - أخضر */
.icon-btn.view {
  color: #2d6a4f;
  border-color: #c8e0d3;
  background: #f5faf7;
}

.icon-btn.view:hover {
  background: #2d6a4f;
  color: #fff;
  border-color: #2d6a4f;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(45,106,79,0.25);
}

/* تعديل - ذهبي */
.icon-btn.edit {
  color: #8b6f1e;
  border-color: #e9d5a1;
  background: #fdf9ef;
}

.icon-btn.edit:hover {
  background: #c9a961;
  color: #fff;
  border-color: #c9a961;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(201,169,97,0.3);
}

/* حذف - أحمر */
.icon-btn.delete {
  color: #c0392b;
  border-color: #f5d5d0;
  background: #fdf2f0;
}

.icon-btn.delete:hover {
  background: #c0392b;
  color: #fff;
  border-color: #c0392b;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(192,57,43,0.25);
}

.codes-table td.action-icons,
.archive-table td.action-icons {
  padding-top: 10px;
  padding-bottom: 10px;
}

@media (max-width: 640px) {
  .icon-btn { width: 30px; height: 30px; }
  .action-icons { gap: 4px; }
}

/* ============================================================
   🌙 الوضع الليلي (Dark Mode Styles) - لوحة الإدارة
============================================================ */
body.dark-mode {
  background-color: #121212 !important;
  color: #e0e0e0 !important;
}

body.dark-mode .panel-wrap,
body.dark-mode .panel-header,
body.dark-mode .card,
body.dark-mode .login-box,
body.dark-mode .modal-box,
body.dark-mode .modal-header,
body.dark-mode .modal-body,
body.dark-mode .modal-footer,
body.dark-mode .contract-block,
body.dark-mode .contract-block-title,
body.dark-mode .card-header,
body.dark-mode .audit-filters-bar {
  background-color: #1e1e1e !important;
  border-color: #333 !important;
  color: #e0e0e0 !important;
}

body.dark-mode .codes-table,
body.dark-mode .archive-table,
body.dark-mode .codes-table th,
body.dark-mode .archive-table thead th,
body.dark-mode .codes-table td,
body.dark-mode .archive-table tbody td {
  background-color: #1e1e1e !important;
  color: #e0e0e0 !important;
  border-color: #333 !important;
}

body.dark-mode .codes-table tr:hover td,
body.dark-mode .archive-table tbody tr:hover {
  background-color: #252525 !important;
}

body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea {
  background-color: #2c2c2c !important;
  color: #ffffff !important;
  border: 1px solid #555 !important;
}

body.dark-mode .admin-tabs {
  background-color: #181818 !important;
  border-bottom: 1px solid #333 !important;
}

body.dark-mode .admin-tab {
  color: #aaa !important;
}

body.dark-mode .admin-tab.active {
  color: #2ecc71 !important;
  border-bottom-color: #2ecc71 !important;
}

body.dark-mode .icon-btn {
  background-color: #2c2c2c !important;
  border-color: #444 !important;
  color: #ccc !important;
}

body.dark-mode .badge {
  background-color: #2c2c2c !important;
  color: #2ecc71 !important;
}
