/* ============================================================
   Jamesons Sales Portal — Mobile-First Styles
   ============================================================ */

:root {
  --color-primary: #3C4981;
  --color-primary-dark: #2D3666;
  --color-primary-light: #5A6A9E;
  --color-secondary: #000000;
  --color-secondary-light: #1A1A1A;

  --color-bg: #F5F7FA;
  --color-surface: #FFFFFF;
  --color-surface-hover: #F0F4F8;
  --color-border: #E2E8F0;
  --color-border-light: #EDF2F7;

  --color-text: #1A202C;
  --color-text-secondary: #4A5568;
  --color-text-muted: #A0AEC0;

  --color-success: #38A169;
  --color-warning: #FFCE2E;
  --color-error: #E53E3E;

  --color-brand-yellow: #FFCE2E;
  --color-brand-green: #4A783C;
  --color-brand-grey: #707372;
  --color-brand-purple: #514163;
  --color-brand-pink: #D74388;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  --font-sans: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;

  --header-height: 56px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- Reset ---- */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ---- Layout ---- */

#app-wrapper {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  padding-top: var(--safe-area-top);
  background: var(--color-secondary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  box-shadow: var(--shadow-md);
  border-bottom: 3px solid var(--color-brand-yellow);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  height: 32px;
  flex-shrink: 0;
}

.header-logo img {
  height: 100%;
  width: auto;
  display: block;
}

.header-titles {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}

.header-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-brand-yellow);
  white-space: nowrap;
}

.header-subtitle:empty { display: none; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ---- Connection Status ---- */

.status-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  transition: all 0.3s ease;
}

.status-online {
  background: rgba(56, 161, 105, 0.2);
  color: #9AE6B4;
}

.status-offline {
  background: rgba(229, 62, 62, 0.2);
  color: #FEB2B2;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-online .status-dot { background: var(--color-success); }
.status-offline .status-dot { background: var(--color-error); }

/* ---- User Menu ---- */

.user-menu-btn {
  padding: 2px;
  border-radius: 50%;
  transition: opacity 0.2s;
}
.user-menu-btn:hover { opacity: 0.8; }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}

.user-dropdown {
  position: fixed;
  top: calc(var(--header-height) + var(--safe-area-top) + 4px);
  right: 12px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  z-index: 200;
  overflow: hidden;
  animation: dropdown-in 0.15s ease;
}

@keyframes dropdown-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-user-info {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dropdown-name { font-weight: 600; font-size: 15px; }
.dropdown-email { font-size: 13px; color: var(--color-text-secondary); }

.dropdown-role-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: fit-content;
}

.role-admin { background: #FEF3C7; color: #92400E; }
.role-user { background: #DBEAFE; color: #1E40AF; }

.dropdown-divider {
  border: none;
  border-top: 1px solid var(--color-border-light);
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  font-size: 14px;
  color: var(--color-text);
  transition: background 0.15s;
}
.dropdown-item:hover { background: var(--color-surface-hover); }

/* ---- App Content ---- */

.app-content {
  flex: 1;
  padding: 20px 16px;
  padding-bottom: calc(20px + var(--safe-area-bottom));
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ---- Login Page ---- */

.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 40px);
  text-align: center;
  padding: 24px;
}

.login-brand {
  margin-bottom: 32px;
}

.login-logo {
  width: 160px;
  margin: 0 auto 16px;
}

.login-logo img {
  width: 100%;
  height: auto;
  display: block;
}

.login-brand h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-secondary);
}

.login-brand p {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

.login-brand .login-strapline {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-brand-yellow);
  background: var(--color-secondary);
  display: inline-block;
  padding: 3px 12px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 8px;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--color-brand-yellow);
  color: var(--color-secondary);
  font-size: 16px;
  font-weight: 700;
  padding: 14px 28px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: background 0.2s, transform 0.1s;
}
.login-btn:hover { background: #e6b800; }
.login-btn:active { transform: scale(0.98); }

.login-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* ---- Page Header (back + title) ---- */

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.back-btn {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary);
  padding: 4px 0;
}

/* ---- Home / Dashboard ---- */

.home-greeting {
  margin-bottom: 24px;
}

.home-greeting h2 {
  font-size: 22px;
  font-weight: 700;
}

.home-greeting p {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.nav-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.nav-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  text-align: left;
  transition: box-shadow 0.2s, border-color 0.2s;
  width: 100%;
}
.nav-card:hover {
  border-color: var(--color-brand-yellow);
  box-shadow: var(--shadow-md);
}

.nav-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.nav-card-icon.products { background: #DBEAFE; color: #2563EB; }
.nav-card-icon.admin { background: #FEF3C7; color: #B45309; }
.nav-card-icon.disabled { background: var(--color-border-light); color: var(--color-text-muted); }

.nav-card-text h3 {
  font-size: 15px;
  font-weight: 600;
}

.nav-card-text p {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-top: 1px;
}

.nav-card .coming-soon {
  margin-left: auto;
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ---- Denied Page ---- */

.denied-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - var(--header-height) - 40px);
  text-align: center;
  padding: 24px;
}

.denied-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #FEE2E2;
  color: var(--color-error);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 16px;
}

.denied-page h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
}

.denied-page p {
  font-size: 14px;
  color: var(--color-text-secondary);
  max-width: 320px;
  line-height: 1.6;
}

.denied-page .back-btn {
  margin-top: 20px;
  padding: 10px 20px;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
}

/* ---- Loading ---- */

.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 40px);
  color: var(--color-text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Toast Notifications ---- */

.toast-container {
  position: fixed;
  bottom: calc(16px + var(--safe-area-bottom));
  left: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
  max-width: 400px;
  margin: 0 auto;
}

.toast {
  background: var(--color-secondary);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 0.25s ease;
}

.toast.toast-success { border-left: 4px solid var(--color-success); }
.toast.toast-error { border-left: 4px solid var(--color-error); }
.toast.toast-info { border-left: 4px solid var(--color-primary); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast-exit {
  animation: toast-out 0.2s ease forwards;
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(12px); }
}

/* ---- Responsive: Tablet / Desktop ---- */

@media (min-width: 600px) {
  .app-content {
    max-width: 640px;
    padding: 28px 24px;
  }

  .nav-cards {
    grid-template-columns: 1fr 1fr;
  }

  .login-logo {
    width: 200px;
  }
}

@media (min-width: 1024px) {
  .app-content {
    max-width: 720px;
    padding: 36px 32px;
  }
}

/* ============================================================
   Product List Page
   ============================================================ */

.products-page {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-height) - 40px);
}

.product-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

@media (min-width: 600px) {
  .products-page {
    height: calc(100dvh - var(--header-height) - 56px);
  }
}

@media (min-width: 1024px) {
  .products-page {
    height: calc(100dvh - var(--header-height) - 72px);
  }
}

.search-bar {
  position: relative;
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 12px 40px 12px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: 15px;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(60, 73, 129, 0.12);
}

.search-input::placeholder { color: var(--color-text-muted); }

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.search-clear:hover { background: var(--color-surface-hover); }

.products-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.product-count {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.select-toggle-btn {
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  transition: all 0.15s;
}
.select-toggle-btn:hover { background: rgba(60, 73, 129, 0.06); }
.select-toggle-btn.active {
  background: var(--color-primary);
  color: #fff;
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 14px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.product-card:hover {
  border-color: var(--color-primary-light);
  box-shadow: var(--shadow-sm);
}
.product-card.selected {
  border-color: var(--color-primary);
  background: rgba(60, 73, 129, 0.04);
}

.product-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--color-primary);
  flex-shrink: 0;
  pointer-events: none;
}

.product-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-code {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
}

.product-desc {
  font-size: 13px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-arrow {
  font-size: 20px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  font-weight: 300;
}

/* Selection Bar */

.selection-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-secondary);
  color: #fff;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-area-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 150;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
  border-top: 3px solid var(--color-brand-yellow);
  animation: slide-up 0.2s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

#selection-count {
  font-size: 14px;
  font-weight: 500;
}

/* Shared Buttons */

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--color-surface-hover); }

.btn-sm { padding: 10px 18px; font-size: 14px; }

/* Empty State */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  color: var(--color-text-muted);
  text-align: center;
}

.empty-icon { font-size: 40px; margin-bottom: 8px; }

/* Cache Badge */

.cache-badge {
  position: fixed;
  top: calc(var(--header-height) + var(--safe-area-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-warning);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  z-index: 110;
  animation: toast-in 0.25s ease;
}

/* ============================================================
   Product Detail Page
   ============================================================ */

.product-detail-page {
  padding-bottom: 80px;
}

.detail-header {
  margin-bottom: 20px;
}

.detail-code {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  background: rgba(60, 73, 129, 0.08);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  margin-bottom: 6px;
}

.detail-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-secondary);
  line-height: 1.3;
}

.detail-sections {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.label-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.section-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-brand-yellow);
}

.section-content {
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
}

.section-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.section-list li {
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-text);
  padding: 2px 0 2px 16px;
  position: relative;
}

.section-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--color-primary);
  font-weight: 700;
}

/* Detail Action Bar */

.detail-action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-area-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 150;
}

.detail-action-group {
  display: flex;
  gap: 10px;
}

/* Shared: Outline button */

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  font-weight: 600;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.btn-outline:hover { background: rgba(60, 73, 129, 0.06); }
.btn-outline:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-outline-light {
  background: transparent;
  color: #fff;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-md);
  transition: background 0.15s;
}
.btn-outline-light:hover { background: rgba(255, 255, 255, 0.1); }

.btn-xs { padding: 6px 12px; font-size: 13px; }

/* ============================================================
   Admin Panel
   ============================================================ */

.admin-page { padding-bottom: 20px; }

.admin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-back {
  font-size: 14px;
  color: var(--color-primary);
  font-weight: 600;
  padding: 4px 0;
}

.admin-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
  padding-bottom: 2px;
}

.admin-tab {
  flex-shrink: 0;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  transition: all 0.15s;
}
.admin-tab:hover { border-color: var(--color-primary-light); }
.admin-tab.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  border-bottom: 2px solid var(--color-brand-yellow);
}

.admin-content { min-height: 200px; }

/* Admin Tables */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.admin-table tbody tr:hover { background: var(--color-surface-hover); }

.td-nowrap { white-space: nowrap; }

.table-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 32px 12px !important;
}

/* Badges */

.action-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.action-VIEW { background: #DBEAFE; color: #1E40AF; }
.action-GENERATE_PDF { background: #D1FAE5; color: #065F46; }
.action-EMAIL { background: #FEF3C7; color: #92400E; }
.action-DOWNLOAD { background: #E0E7FF; color: #3730A3; }

.sync-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}

.sync-SUCCESS { background: #D1FAE5; color: #065F46; }
.sync-FAILED { background: #FEE2E2; color: #991B1B; }
.sync-PARTIAL { background: #FEF3C7; color: #92400E; }

/* Pagination */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.page-info {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* Audit Filters */

.audit-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.form-select {
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--color-surface);
  color: var(--color-text);
}

/* Form elements */

.form-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.form-card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

.form-hint {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 16px;
  line-height: 1.6;
}

.form-hint code {
  background: var(--color-bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
  margin-top: 12px;
}

.form-label:first-of-type { margin-top: 0; }

.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-surface);
}
.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(60, 73, 129, 0.12);
}

.form-input-sm { flex: 1; }

.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  resize: vertical;
  min-height: 100px;
}
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(60, 73, 129, 0.12);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-row input[type="color"] {
  width: 40px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: none;
}

/* Decode Tool */

.decode-result-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.decode-field {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--color-border-light);
}
.decode-field:last-child { border-bottom: none; }

.decode-label {
  font-weight: 600;
  color: var(--color-text-secondary);
  font-size: 13px;
}

.error-text {
  color: var(--color-error);
  font-size: 14px;
  text-align: center;
  padding: 16px;
}

/* ============================================================
   Email Compose
   ============================================================ */

.email-compose-page { padding-bottom: 20px; }

.email-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.email-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.email-form-area {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.email-products { margin-bottom: 16px; }

.product-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.product-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--color-text-secondary);
}

.email-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

/* ============================================================
   Security Group Management
   ============================================================ */

.sg-search-section { margin-bottom: 16px; }

.sg-search-row {
  display: flex;
  gap: 8px;
}

.sg-search-row .form-input { flex: 1; }

.sg-groups-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sg-group-card { padding: 20px; }

.sg-group-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-border-light);
}

.sg-member-count {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.sg-member-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sg-member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.sg-member-row:hover { background: var(--color-surface-hover); }

.sg-member-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.sg-member-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.sg-member-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sg-member-email {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sg-remove-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all 0.15s;
}

.sg-remove-btn:hover {
  background: #FEE2E2;
  color: var(--color-error);
}

.sg-empty {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
  padding: 20px 0;
}

/* Search results */

.sg-search-results-list {
  margin-top: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow-y: auto;
}

.sg-search-result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-light);
}

.sg-search-result-row:last-child { border-bottom: none; }
.sg-search-result-row:hover { background: var(--color-surface-hover); }

.sg-add-actions {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
  align-items: center;
}

.sg-add-btn { white-space: nowrap; }

.sg-already-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: #D1FAE5;
  color: #065F46;
  white-space: nowrap;
}

.sg-added-btn {
  background: #D1FAE5 !important;
  color: #065F46 !important;
  border-color: #D1FAE5 !important;
  cursor: default;
}

.sg-search-hint {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
  padding: 16px 0;
}

.sg-search-loading {
  display: flex;
  justify-content: center;
  padding: 16px 0;
}

.spinner-sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

@media (max-width: 600px) {
  .sg-search-result-row {
    flex-wrap: wrap;
  }

  .sg-add-actions {
    width: 100%;
    padding-left: 46px;
    margin-top: 4px;
  }
}
