/* ==========================================================================
   AL'S AUTO REPAIR SHOP — ADMIN CRM STYLES
   ========================================================================== */

:root {
  --crm-bg: #f1f5f9;
  --crm-surface: #ffffff;
  --crm-sidebar: #0b0f14;
  --crm-sidebar-hover: rgba(255, 255, 255, 0.08);
  --crm-ink: #0f172a;
  --crm-muted: #64748b;
  --crm-border: #e2e8f0;
  --crm-crimson: #d9232e;
  --crm-crimson-dark: #b91c1c;
  --crm-emerald: #10b981;
  --crm-amber: #f59e0b;
  --crm-blue: #3b82f6;
}

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

html, body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--crm-bg);
  color: var(--crm-ink);
  overflow-x: hidden;
  max-width: 100%;
  min-height: 100vh;
}

/* Login Gate */
.crm-login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: radial-gradient(circle at top, #1e293b 0%, #0b0f14 70%);
}

.crm-login-card {
  width: 100%;
  max-width: 400px;
  background: #ffffff;
  border-radius: 18px;
  padding: 2rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.crm-login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 0.85rem;
}

.crm-login-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.75rem;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.crm-login-sub {
  font-size: 0.84rem;
  color: var(--crm-muted);
  margin-bottom: 1.35rem;
}

.crm-field {
  text-align: left;
  margin-bottom: 0.9rem;
}

.crm-field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
  color: var(--crm-ink);
}

.crm-login-input,
.crm-input,
.crm-select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--crm-border);
  border-radius: 8px;
  font-size: 0.86rem;
  font-family: inherit;
  outline: none;
  background: #ffffff;
}

.crm-login-input:focus,
.crm-input:focus,
.crm-select:focus {
  border-color: var(--crm-crimson);
}

.crm-error {
  display: none;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.9rem;
}

.crm-error.visible {
  display: block;
}

.crm-demo-box {
  margin-top: 1.15rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--crm-border);
  font-size: 0.76rem;
  color: var(--crm-muted);
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* CRM Shell */
.crm-app {
  display: none;
  min-height: 100vh;
}

.crm-app.active {
  display: grid;
  grid-template-columns: 250px 1fr;
}

.crm-sidebar {
  background: var(--crm-sidebar);
  color: #e2e8f0;
  padding: 1.35rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.crm-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 0.4rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 1rem;
}

.crm-brand img {
  width: 38px;
  height: 38px;
}

.crm-brand-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #ffffff;
  line-height: 1.05;
}

.crm-brand-sub {
  font-size: 0.66rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.crm-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.crm-nav-btn {
  width: 100%;
  border: none;
  background: transparent;
  color: #cbd5e1;
  padding: 0.68rem 0.85rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s ease, color 0.2s ease;
  text-decoration: none;
}

.crm-nav-btn:hover {
  background: var(--crm-sidebar-hover);
  color: #ffffff;
}

.crm-nav-btn.active {
  background: var(--crm-crimson);
  color: #ffffff;
}

.crm-sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Main Workspace */
.crm-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.crm-topbar {
  background: var(--crm-surface);
  border-bottom: 1px solid var(--crm-border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.crm-page-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.55rem;
  font-weight: 800;
  text-transform: uppercase;
}

.crm-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.crm-content {
  padding: 1.5rem;
  flex: 1;
}

.crm-tab-panel {
  display: none;
}

.crm-tab-panel.active {
  display: block;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: 14px;
  padding: 1.15rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

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

.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: rgba(217, 35, 46, 0.1);
  color: var(--crm-crimson);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-value {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.05;
  margin-bottom: 0.2rem;
}

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

/* Cards & Tables */
.crm-panel-card {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  margin-bottom: 1.25rem;
}

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

.crm-panel-title {
  font-size: 1rem;
  font-weight: 800;
}

.crm-search {
  max-width: 280px;
}

.crm-table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.crm-table th {
  text-align: left;
  padding: 0.7rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--crm-muted);
  border-bottom: 1px solid var(--crm-border);
  white-space: nowrap;
}

.crm-table td {
  padding: 0.78rem 0.75rem;
  border-bottom: 1px solid var(--crm-border);
  vertical-align: middle;
}

.crm-table tr:last-child td {
  border-bottom: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pending { background: #fef3c7; color: #92400e; }
.status-in-bay { background: #dbeafe; color: #1e40af; }
.status-waiting { background: #fce7f3; color: #9d174d; }
.status-completed { background: #d1fae5; color: #065f46; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.58rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
}

.btn-primary {
  background: var(--crm-crimson);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--crm-crimson-dark);
}

.btn-outline {
  background: #ffffff;
  color: var(--crm-ink);
  border-color: var(--crm-border);
}

.btn-outline:hover {
  background: #f8fafc;
}

.btn-sm {
  padding: 0.32rem 0.6rem;
  font-size: 0.75rem;
}

/* Modal */
.crm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 20, 0.68);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.crm-modal-backdrop.open {
  display: flex;
}

.crm-modal-card {
  width: 100%;
  max-width: 460px;
  background: #ffffff;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
}

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

/* Inventory Photo Upload & Auto-Cutout Preview */
.crm-upload-box {
  border: 2px dashed var(--crm-border);
  border-radius: 10px;
  padding: 0.85rem;
  text-align: center;
  cursor: pointer;
  background: #f8fafc;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.crm-upload-box:hover {
  border-color: var(--crm-crimson);
  background: #fff5f5;
}

.crm-upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--crm-muted);
}

.crm-upload-placeholder i {
  font-size: 1.25rem;
  color: var(--crm-crimson);
}

.crm-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
}

.crm-preview-wrap img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 8px;
  background-image:
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  border: 1px solid var(--crm-border);
}

.crm-cutout-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: #065f46;
  background: #d1fae5;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
}

.crm-item-thumb {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: contain;
  background: #f8fafc;
  border: 1px solid var(--crm-border);
  padding: 2px;
}

.crm-item-thumb-fallback {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: rgba(217, 35, 46, 0.08);
  color: var(--crm-crimson);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.crm-mobile-bar {
  display: none;
}

@media (max-width: 960px) {
  .crm-app.active {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100%;
    overflow-x: hidden;
  }

  .crm-main {
    padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }

  .crm-sidebar {
    padding: 0.75rem 1rem;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .crm-brand {
    border-bottom: none;
    padding: 0;
    margin-bottom: 0;
  }

  .crm-nav {
    display: none;
  }

  .crm-sidebar-footer {
    border-top: none;
    padding-top: 0;
    flex-direction: row;
    gap: 0.35rem;
  }

  .crm-sidebar-footer .crm-nav-btn {
    padding: 0.45rem 0.65rem;
    font-size: 0.75rem;
  }

  .crm-mobile-bar {
    display: none;
  }

  .crm-app.active ~ .crm-mobile-bar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(11, 15, 20, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.14);
    z-index: 180;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
  }

  .crm-mobile-item {
    border: none;
    background: transparent;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 0.64rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    min-width: 0;
    padding: 0.25rem 0.15rem;
  }

  .crm-mobile-item i {
    font-size: 1.05rem;
  }

  .crm-mobile-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }

  .crm-mobile-item.active {
    color: #ffffff;
  }

  .crm-mobile-item.active i {
    color: var(--crm-crimson);
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .kpi-grid,
  .crm-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .crm-content,
  .crm-topbar {
    padding: 0.9rem;
    max-width: 100%;
  }

  .crm-panel-card {
    padding: 0.95rem;
    max-width: 100%;
    overflow: hidden;
  }

  .crm-search {
    max-width: 100%;
    width: 100%;
  }

  .crm-topbar-actions {
    width: 100%;
  }

  .crm-topbar-actions .btn {
    flex: 1;
    justify-content: center;
  }
}
