:root {
  --bg: #f7fafc;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #68758a;
  --line: #dbe4ef;
  --accent: #ef6f61;
  --accent-2: #3aa7bd;
  --danger: #d83a3a;
  --shadow: 0 18px 50px rgba(26, 36, 54, .12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, textarea, select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: .62rem .9rem;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(.97);
}

button.danger {
  background: var(--danger);
}

code {
  background: #eef4fa;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .14rem .35rem;
}

.admin-nav {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.admin-nav strong {
  font-size: 1.1rem;
}

.admin-nav div {
  display: flex;
  gap: .7rem;
  color: var(--muted);
  font-weight: 700;
}

.admin-logout-form {
  margin: 0;
}

.admin-logout-form button {
  background: transparent;
  color: inherit;
  padding: 0;
  border-radius: 0;
}

.admin-logout-form button:hover {
  filter: none;
  color: var(--ink);
}

.admin-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 64px);
}

.admin-tabs {
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 1rem;
}

.admin-tabs button {
  width: 100%;
  text-align: left;
  margin-bottom: .45rem;
  background: transparent;
  color: var(--ink);
}

.admin-tabs button.active {
  background: #fff1ef;
  color: var(--accent);
}

.admin-main {
  padding: 1.25rem;
  min-width: 0;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head h2 {
  margin: 0;
}

.hint {
  color: var(--muted);
  margin-top: -.4rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.admin-table th, .admin-table td {
  padding: .8rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.admin-table th {
  background: #f0f5fa;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
}

.admin-table small {
  display: block;
  color: var(--muted);
  margin-top: .25rem;
}

.admin-table textarea, .admin-table input, .admin-table select, .upload-row input, .upload-row select, .redis-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .65rem;
  background: #fff;
  color: var(--ink);
}

.admin-table textarea {
  min-height: 72px;
  resize: vertical;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.admin-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.admin-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  background: #eef4fa;
}

.admin-card div, .admin-card p {
  padding: 0 .9rem;
}

.admin-card strong {
  display: block;
  margin-top: .85rem;
}

.admin-card p {
  color: var(--muted);
  min-height: 44px;
}

.row-actions {
  display: flex;
  gap: .5rem;
  padding: .8rem .9rem 1rem !important;
}

.thumb {
  width: 70px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: #eef4fa;
}

.truncate {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-cart-cell {
  max-width: 360px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #445;
}

.pay-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: uppercase;
  background: #eef4fa;
  color: #1f6feb;
}

.upload-row, .redis-box {
  display: grid;
  grid-template-columns: 1fr 160px auto;
  gap: .7rem;
  margin-bottom: 1rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .8rem;
}

.cache-list {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin-bottom: 1rem;
}

.redis-box {
  grid-template-columns: 1fr auto;
}

.redis-box pre {
  grid-column: 1 / -1;
  background: #162032;
  color: #dbeafe;
  border-radius: 8px;
  padding: 1rem;
  max-height: 360px;
  overflow: auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(12, 18, 30, .45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 20;
}

.modal.show {
  display: flex;
}

.modal-body {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: min(860px, 100%);
  max-height: 90vh;
  overflow: auto;
  padding: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.form-grid label {
  display: grid;
  gap: .25rem;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.form-grid input, .form-grid textarea, .form-grid select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .65rem;
}

.form-grid textarea {
  min-height: 84px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1rem;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  padding: .75rem 1rem;
  background: #123c2d;
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: .2s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e8f7fb, #fff1ef);
}

.login-card {
  width: min(420px, calc(100vw - 2rem));
  background: #fff;
  border-radius: 14px;
  padding: 1.4rem;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--accent);
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.login-card h1 {
  margin: .4rem 0;
}

.login-card p, .login-error {
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: .35rem;
  margin-top: .8rem;
  font-weight: 700;
}

.login-card input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .7rem;
}

.login-card button {
  width: 100%;
  margin-top: 1rem;
}

.login-error {
  color: var(--danger);
  margin-top: .7rem;
}

@media (max-width: 800px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-tabs {
    display: flex;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-tabs button {
    white-space: nowrap;
    width: auto;
  }

  .upload-row, .redis-box, .form-grid {
    grid-template-columns: 1fr;
  }

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

/* DMS Drive tab — image grid view */
.drive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.drive-tile {
  margin: 0;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.drive-tile img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: #eef4fa;
}

.drive-tile figcaption {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.drive-tile figcaption small {
  font-size: 11px;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drive-tile figcaption button {
  font-size: 11px;
  padding: 4px 8px;
}

/* Dashboard tab */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}

.kpi-card.kpi-warn {
  border-color: var(--danger);
  background: #fff6f5;
}

.kpi-label {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  font-weight: 700;
}

.kpi-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1.1;
}

.kpi-sub {
  font-size: .78rem;
  color: var(--muted);
}

.dash-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 22px;
}

.dash-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.dash-block h3 {
  margin: 0 0 12px;
  font-size: .95rem;
}

.status-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 34px;
  align-items: center;
  gap: 10px;
  font-size: .8rem;
}

.status-bar-label {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: .68rem;
}

.status-bar-track {
  background: #eef2f7;
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

.status-bar-fill {
  height: 100%;
  background: var(--accent-2);
  border-radius: 6px;
}

.status-bar-count {
  text-align: right;
  font-weight: 700;
}

/* Status badges (shared by dashboard, orders, quotes) */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
  background: #eef2f7;
  color: var(--ink);
  margin-right: 4px;
}

.badge-danger {
  background: #fdeceb;
  color: var(--danger);
}

.badge-accent {
  background: #eafaf7;
  color: #178a6f;
}

.badge-muted {
  background: #eef2f7;
  color: var(--muted);
}

.status-bar-fill.status-CANCELLED, .badge.status-CANCELLED {
  background: var(--danger);
  color: #fff;
}

.status-bar-fill.status-CLOSED, .badge.status-CLOSED, .status-bar-fill.status-DELIVERED, .badge.status-DELIVERED {
  background: #178a6f;
}

.status-bar-fill.status-SHIPPED, .badge.status-SHIPPED {
  background: var(--accent-2);
}

.status-bar-fill.status-IN_PRODUCTION, .badge.status-IN_PRODUCTION, .status-bar-fill.status-QUALITY_CHECK, .badge.status-QUALITY_CHECK {
  background: var(--accent);
}

/* Search boxes above tables/grids */
.table-search {
  width: 100%;
  max-width: 420px;
  margin-bottom: 14px;
  padding: .6rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: .9rem;
}

.admin-table-compact th, .admin-table-compact td {
  padding: 8px 10px;
  font-size: .82rem;
}

.tab-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: .68rem;
  margin-left: 5px;
}

/* Order timeline (in the order detail modal) */
.timeline {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timeline li {
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.timeline small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.timeline p {
  margin: 4px 0 0;
  font-size: .85rem;
}

/* Customer message replies */
.msg-reply {
  width: 100%;
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  margin-bottom: 6px;
}

.t-quote {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}
