/* Dashboard layout — builds on the tokens and components in styles.css */
body.admin { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; background: #eef5f5; }
.muted { color: var(--muted); margin: 0; }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--paper); border-inline-start: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 16px; gap: 28px; z-index: 55;
}
.sidebar .logo { padding: 0 8px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 0; border-radius: 12px;
  background: none; color: var(--ink); font-weight: 700; cursor: pointer; text-align: start; transition: .15s;
}
.nav-item span { width: 22px; text-align: center; }
.nav-item:hover { background: var(--cream); }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-count { margin-inline-start: auto; background: var(--accent); color: var(--brand-dark); border-radius: 999px; padding: 0 8px; font-size: 12px; }
.nav-count:empty { display: none; }
.store-link { color: var(--brand); border: 1px dashed var(--brand); }

/* Main */
.admin-main { padding: 22px 28px 48px; min-width: 0; }
.admin-top { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.admin-top h1 { margin: 0; font-size: 26px; color: var(--brand-dark); }
.admin-user { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; }
.admin-user small { display: block; color: var(--muted); font-size: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--brand-dark); display: grid; place-items: center; font-weight: 800; }
.menu-btn { display: none; font-size: 20px; }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h3 { margin: 0; font-size: 17px; color: var(--brand-dark); }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 700; cursor: pointer; }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; margin-top: 18px; align-items: start; }
.stack { display: grid; gap: 18px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 18px; position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; top: 14px; left: 14px; width: 10px; height: 10px; background: var(--accent); }
.kpi small { color: var(--muted); font-weight: 700; }
.kpi b { display: block; font-size: 26px; color: var(--brand-dark); margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi.highlight { background: var(--brand); border-color: var(--brand); }
.kpi.highlight small, .kpi.highlight span { color: #d6f1f1; }
.kpi.highlight b { color: #fff; }

/* Toolbar */
.admin-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.admin-toolbar input[type=search] { flex: 1; min-width: 200px; max-width: 360px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; outline: none; }
.admin-toolbar input[type=search]:focus { border-color: var(--brand); }
.spacer { flex: 1; }
.btn-sm { padding: 9px 16px; font-size: 14px; }
.btn-danger { background: var(--red); color: #fff; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: start; color: var(--muted); font-weight: 700; padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f7fbfb; }
.table .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td:first-child b, .table td:first-child .link-btn { white-space: nowrap; }
.table .empty-row td { text-align: center; color: var(--muted); padding: 36px; }
.book-cell { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.book-cell .cover { width: 40px; padding: 4px; font-size: 5px; flex-shrink: 0; }
.book-cell .cover .c-orn, .book-cell .cover .c-author { display: none; }
.book-cell small { display: block; color: var(--muted); }
.row-actions { display: flex; gap: 6px; }
.icon-action { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 13px; white-space: nowrap; }
.icon-action:hover { border-color: var(--brand); color: var(--brand); }
.icon-action.danger:hover { border-color: var(--red); color: var(--red); }

.stock-pill, .status-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.stock-ok { background: #e2f4ec; color: #1d7a4e; }
.stock-low { background: var(--accent-soft); color: #8a6200; }
.stock-out { background: #fbe4e1; color: var(--red); }
.status-new { background: #e1f1fb; color: #1b6a9c; }
.status-processing { background: var(--accent-soft); color: #8a6200; }
.status-shipped { background: #e3f4f4; color: var(--brand-2); }
.status-delivered { background: #e2f4ec; color: #1d7a4e; }
.status-cancelled { background: #f1f1f1; color: #777; }
select.status-select { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

.status-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.status-tab { border: 0; background: none; padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 700; color: var(--muted); }
.status-tab b { margin-inline-start: 4px; font-weight: 500; opacity: .8; }
.status-tab.active { background: var(--brand-dark); color: #fff; }

/* Lists */
.rank-list { margin: 0; padding: 0; list-style: none; counter-reset: r; }
.rank-list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); counter-increment: r; }
.rank-list li::before { content: counter(r); width: 26px; height: 26px; border-radius: 8px; background: var(--cream); color: var(--brand-dark); font-weight: 800; display: grid; place-items: center; font-size: 13px; }
.rank-list li span { flex: 1; }
.rank-list li small { color: var(--muted); }
.alert-list { margin: 0; padding: 0; list-style: none; }
.alert-list li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.list-empty { color: var(--muted); padding: 12px 0; }
li:last-child { border-bottom: 0 !important; }

/* Forms in modal */
.book-form { display: grid; grid-template-columns: 1fr 180px; gap: 24px; }
.book-form .form-grid { grid-template-columns: repeat(2, 1fr); }
.field textarea { min-height: 90px; resize: vertical; }
.field input[type=color] { padding: 4px; height: 44px; cursor: pointer; }
.check-field { flex-direction: row; align-items: center; gap: 8px; }
.preview-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.preview-col .cover { width: 170px; font-size: 13px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.modal-card h2 { margin: 0 0 18px; color: var(--brand-dark); }

/* Order details */
.order-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.info-box { background: var(--cream); border-radius: 12px; padding: 14px; }
.info-box h4 { margin: 0 0 8px; color: var(--brand-dark); }
.info-box p { margin: 4px 0; font-size: 14px; }
.order-detail .full { grid-column: 1 / -1; }

/* Order statuses (Algerian COD flow) */
.status-confirming { background: #fff1db; color: #9a5b00; }
.status-no_answer { background: #fbe4e1; color: #b03a2e; }
.status-confirmed { background: #e3f4f4; color: var(--brand-2); }
.status-preparing { background: var(--accent-soft); color: #8a6200; }
.status-returned { background: #efe6f7; color: #6b3fa0; }

.block-title { margin: 22px 0 10px; color: var(--brand-dark); font-size: 16px; }
.row-new td { background: #f5fbfb; }
.row-new td:first-child { box-shadow: inset -3px 0 0 var(--accent); }
.row-muted td { opacity: .55; }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; background: var(--accent-soft); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; }
.bulk-bar select, .bulk-form input, .bulk-form select, .mini-input, .admin-toolbar select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; font-size: 14px;
}
.bulk-form input[type=number] { width: 110px; }
.mini-input { width: 120px; }
.mini-input.wide { width: 100%; min-width: 160px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; flex-direction: row !important; }
.checks label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.upload-btn { cursor: pointer; align-self: flex-start; }
.img-list { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0; }
.img-item { position: relative; width: 84px; height: 112px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.img-item img { width: 100%; height: 100%; object-fit: cover; }
.img-item button { position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 12px; }
.book-form { grid-template-columns: 1fr 200px; }
.preview-col .cover { width: 180px; }
.form-grid.three { grid-template-columns: repeat(3, 1fr); }
.manage { border: 2px solid var(--brand); background: #f5fbfb; }
.customer-note { background: var(--accent-soft); border-radius: 8px; padding: 6px 10px; }
.danger-ghost { border-color: var(--red) !important; color: var(--red) !important; }
.totals { max-width: 360px; margin-inline-start: auto; margin-top: 10px; }
.timeline { list-style: none; margin: 0; padding: 0; border-inline-start: 2px solid var(--line); }
.timeline li { padding: 4px 16px 12px; position: relative; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -7px; top: 9px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); }
.timeline p { margin: 4px 0 0; color: var(--muted); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(circle at 80% 10%, #dff2f2, transparent 50%), var(--cream); }
.login-card { width: min(400px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 24px 0 4px; font-size: 24px; color: var(--brand-dark); }
.login-card form { display: grid; gap: 14px; margin-top: 22px; }
.form-error { color: var(--red); font-size: 14px; margin: 0; min-height: 1.4em; }
.back-link { display: block; text-align: center; margin-top: 18px; color: var(--muted); font-size: 14px; }
.back-link:hover { color: var(--brand); }
.side-foot { display: grid; gap: 6px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  body.admin { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 0 0 auto; width: 260px; transform: translateX(100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
  .menu-btn { display: block; }
  .admin-main { padding: 16px; }
  .admin-user div { display: none; }
  .book-form, .order-detail { grid-template-columns: 1fr; }
  .preview-col { order: -1; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi b { font-size: 20px; }
  .book-form .form-grid { grid-template-columns: 1fr; }
}
