/* =============================================================================
   ISSCA Admin Panel — Dark Theme Design System
   Based on OPA Ref, adapted for ISSCA Brand (#0d6e4e)
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  /* Brand Colors */
  --primary: #41b0f0;
  --primary-rgb: 65, 176, 240;
  --secondary: #073b4c;
  --tertiary: #118ab2;
  --danger: #9d282d;
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;
  
  /* Neutral Colors */
  --bg-base: #071f2b;
  --bg-surface: #0e3347;
  --bg-elevated: #143d54;
  --bg-hover: #1a4d6a;
  
  --text: #f0f8ff;
  --text-secondary: #c5dff0;
  --text-muted: #7db5d4;
  --text-inverse: #071f2b;
  
  --border: rgba(65, 176, 240, 0.18);
  --border-hover: rgba(65, 176, 240, 0.35);
  --border-focus: rgba(65, 176, 240, 0.6);
  
  /* Typography */
  --font: "Outfit", sans-serif;
  
  /* Spacing & Layout */
  --header-height: 70px;
  --sidebar-width: 260px;
  
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 100px;
  
  /* Transitions */
  --transition: all 0.2s ease;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4), 0 0 0 1px rgba(65,176,240,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.45), 0 0 0 1px rgba(65,176,240,0.08);
}

/* =============================================================================
   RESET & BASE
   ============================================================================= */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background-color: var(--bg-base);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  filter: brightness(1.2);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 0.5em;
  line-height: 1.2;
}

ul {
  list-style: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* =============================================================================
   LAYOUT
   ============================================================================= */

.admin-wrapper {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Sidebar */
.admin-sidebar {
  width: var(--sidebar-width);
  background-color: var(--secondary);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  overflow-y: auto;
  z-index: 1000;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-brand {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 24px 24px;
  border-bottom: 1px solid var(--border-hover);
}

.sidebar-brand-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  width: 100%;
}

.sidebar-brand-logo {
  height: 38px;
  width: auto;
  flex-shrink: 0;
}

.sidebar-brand-subtitle {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1;
}

.sidebar-brand a {
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-nav {
  padding: 20px 0;
}

.sidebar-nav ul li a {
  display: flex;
  align-items: center;
  padding: 10px 24px;
  color: var(--text-secondary);
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: var(--transition);
}

.sidebar-nav ul li a:hover {
  background-color: var(--bg-surface);
  color: var(--text);
}

.sidebar-nav ul li a.active,
.sidebar-nav ul li.active a,
.nav-item.active {
  background-color: rgba(65, 176, 240, 0.1);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

.sidebar-nav ul li a i,
.sidebar-nav ul li a svg,
.nav-item svg {
  margin-right: 12px;
  font-size: 1.1em;
  width: 20px;
  height: 20px;
  opacity: 0.8;
}

/* Legacy nav-item support */
.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: var(--transition);
  gap: 13px;
}

.nav-item:hover {
  background-color: var(--bg-surface);
  color: var(--text);
  filter: none;
}

.nav-item.active {
  background-color: rgba(65, 176, 240, 0.1);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}

/* Main Content Area */
.admin-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  border-top: 5px solid var(--primary);
  box-shadow: inset 4px 0 20px rgba(65,176,240,0.04);
}

/* Page Title */
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}

/* Header */
.admin-header {
  height: var(--header-height);
  background-color: var(--secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-info {
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
}

.btn-logout {
  padding: 6px 16px;
  background-color: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  transition: var(--transition);
}

.btn-logout:hover {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: var(--danger);
}

.admin-content {
  padding: 30px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* =============================================================================
   PAGE COMPONENTS
   ============================================================================= */

/* Cards */
.card {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-top: 2px solid rgba(65, 176, 240, 0.25);
  box-shadow: var(--shadow-sm);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(65,176,240,0.16);
  border-color: var(--border-hover);
  border-top-color: rgba(65, 176, 240, 0.5);
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(65, 176, 240, 0.2);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: linear-gradient(135deg, var(--bg-surface) 0%, rgba(65,176,240,0.08) 100%);
  border: 1px solid var(--border);
  border-top: 2px solid rgba(65, 176, 240, 0.3);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-hover);
  border-top-color: var(--primary);
  box-shadow: 0 10px 28px rgba(65, 176, 240, 0.18);
}

.stat-number {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 8px;
  text-shadow: 0 0 20px rgba(65, 176, 240, 0.4);
}

.stat-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Dashboard Recent */
.dashboard-recent {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.quick-labels {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
}

.quick-label-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
}

.quick-label-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background-color: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.quick-label-link:hover {
  color: var(--text);
  border-color: var(--primary);
  background-color: rgba(65, 176, 240, 0.15);
}

/* Forms */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="url"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group select,
.form-group textarea,
.search-input {
  width: 100%;
  padding: 10px 16px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(65, 176, 240, 0.15);
  background-color: var(--bg-hover);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 24px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  line-height: 1.2;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--text-inverse);
  font-weight: 600;
}

.btn-primary:hover {
  background-color: var(--tertiary);
  box-shadow: 0 4px 12px rgba(65, 176, 240, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background-color: var(--bg-hover);
}

/* Active state for segment toggle buttons */
.btn-secondary.active {
  background-color: rgba(65, 176, 240, 0.15);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 0 1px rgba(65, 176, 240, 0.3);
}

.btn-secondary.active:hover {
  background-color: rgba(65, 176, 240, 0.25);
}

/* Hide checkbox inputs inside segment buttons */
.stats-grid .btn input[type="checkbox"] {
  display: none;
}

.btn-success {
  background-color: var(--success);
  color: #fff;
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover {
  background-color: var(--danger);
  color: white;
}

.btn-sm {
  padding: 6px 16px;
  font-size: 0.8rem;
}

.btn-full {
  width: 100%;
}

/* Flash Messages */
.flash, .alert {
  padding: 16px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  font-size: 0.95rem;
  border-left: 4px solid transparent;
  display: flex;
  align-items: center;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
}

.flash-success, .alert.success, .message.success {
  background-color: rgba(16, 185, 129, 0.1);
  color: #34d399;
  border-left-color: #34d399;
}

.flash-error, .alert.error, .message.error {
  background-color: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border-left-color: #f87171;
}

.flash-warning {
  background-color: rgba(245, 158, 11, 0.1);
  color: #fbbf24;
  border-left-color: #fbbf24;
}

.flash-info {
  background-color: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
  border-left-color: #60a5fa;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-active, .status-pill.active {
  background-color: rgba(16, 185, 129, 0.18);
  color: #4ade80;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.badge-inactive, .status-pill.inactive {
  background-color: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-draft {
  background-color: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Pagination */
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 24px;
}

.pagination a, .pagination span {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: var(--transition);
}

.pagination a:hover {
  background-color: var(--bg-elevated);
  color: var(--text);
}

.pagination .current {
  background-color: var(--primary);
  border-color: var(--primary);
  color: var(--text);
  font-weight: 600;
}

/* Login Page */
.login-body {
  background: radial-gradient(circle at 12% 20%, rgba(65, 176, 240, 0.12), transparent 48%),
              var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 28px;
}

.login-container {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(360px, 400px);
  gap: 20px;
  align-items: stretch;
}

.login-hero {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(150deg, rgba(255,255,255,0.02), rgba(65, 176, 240, 0.08));
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px;
}

.login-card {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 24px 22px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 460px;
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo {
  width: 64px;
  height: auto;
  margin: 0 auto 12px;
}

/* =============================================================================
   LIST PAGES - COMPATIBILITY LAYER
   Preserves existing structure while applying Dark Theme
   ============================================================================= */

/* List Toolbar */
.list-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 10px;
  flex-wrap: wrap;
}

.list-toolbar h2 {
  margin: 0;
  color: var(--text);
}

.list-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Filter Panel */
.filter-panel {
  background: var(--bg-surface);
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 24px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  flex: 1;
}

.filter-field label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.filter-field input,
.filter-field select {
  width: 100%;
  padding: 10px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.filter-actions {
  display: flex;
  gap: 8px;
}

/* Table Shell */
.table-shell {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 24px;
}

.list-table {
  width: 100%;
  border-collapse: collapse;
}

.list-table thead {
  background: var(--bg-elevated);
  border-bottom: 2px solid rgba(65, 176, 240, 0.25);
}

.list-table th {
  padding: 14px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

.list-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s;
}

.list-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.list-table td {
  padding: 14px 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  vertical-align: middle;
}

.list-table td.strong {
  color: var(--text);
  font-weight: 500;
}

.list-table td.center {
  text-align: center;
}

.list-table td.mono {
  font-family: monospace;
  font-size: 0.85em;
  color: var(--text-muted);
}

.action-group {
  display: flex;
  gap: 8px;
  justify-content: flex-start;
}

/* Status Pills (Mapped to Badge Styles) */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* Pagination Shell */
.pagination-shell {
  margin-top: 20px;
  padding: 12px 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

.pagination-shell .page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  min-width: 84px;
  height: 34px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
  box-sizing: border-box;
}

.pagination-shell .page-link:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--primary);
}

.pagination-shell .page-current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  height: 34px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.83rem;
  white-space: nowrap;
}

.pagination-shell .page-link.disabled {
  opacity: 0.4;
  pointer-events: none;
  background: transparent;
}

.empty-state {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
}

.empty-state-icon {
  display: block;
  margin: 0 auto 16px;
  opacity: 0.3;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 24px 24px;
  border-top: 1px solid var(--border-hover);
  margin-top: auto;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
}

.user-badge-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--tertiary));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
  border: 2px solid var(--border-hover);
}

.user-badge-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.sidebar-meta {
  opacity: 0.5;
  font-size: 0.7rem;
  margin-top: 10px;
  color: var(--text-muted);
}

/* Admin Footer */
.admin-footer {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 16px 32px;
  margin-top: auto;
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.footer-separator {
  margin: 0 8px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* Utilities */
.w-10 { width: 10%; }
.w-20 { width: 20%; }
.w-30 { width: 30%; }
.w-40 { width: 40%; }
.text-right { text-align: right; }

/* Header Toggle Button */
.header-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  padding: 0;
}

.header-toggle:hover {
  background-color: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-hover);
}

.header-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.header-toggle .icon-menu {
  display: block;
  pointer-events: none; /* ensure clicks always hit the button, not SVG internals */
}

/* Sidebar overlay (mobile only) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 999; /* just below sidebar z-index: 1000 */
  opacity: 0;
  transition: opacity 0.3s ease;
}

@media (max-width: 768px) {
  .header-toggle {
    display: flex;
  }

  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }

  .admin-sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  
  .admin-sidebar.open {
    transform: translateX(0);
  }
  
  .admin-main {
    margin-left: 0;
  }
  
  .admin-content {
    padding: 16px;
  }
  
  .login-container {
    grid-template-columns: 1fr;
  }
  
  .login-hero {
    display: none;
  }
  
  .dashboard-recent, .stats-grid {
    grid-template-columns: 1fr;
  }
}

.img-gallery-count {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 5px;
}

/* Inline subtitle next to .card-title text */
.card-title-sub {
  font-size: 0.82rem;
  font-weight: 400;
  margin-left: 8px;
  vertical-align: middle;
}

/* =============================================================================
   IMAGENS GALLERY — Preview grid for Gestão de Imagens
   ============================================================================= */

.img-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.img-gallery-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
  transition: var(--transition);
}

.img-gallery-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.img-gallery-thumb {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background-color: var(--bg-surface);
}

.img-gallery-thumb-empty {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.img-gallery-meta {
  padding: 8px 10px 10px;
}

.img-gallery-name {
  font-size: 0.78rem;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.img-gallery-edit.btn {
  font-size: 0.72rem;
  padding: 4px 10px;
  width: 100%;
  justify-content: center;
}

/* =============================================================================
   UPLOAD AREA — Image upload UX in form
   ============================================================================= */

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  text-align: center;
  background-color: var(--bg-elevated);
  transition: var(--transition);
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background-color: rgba(65, 176, 240, 0.06);
}

.upload-zone-icon {
  margin: 0 auto 8px;
  opacity: 0.45;
  display: block;
}

.upload-zone-cta {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  display: block;
  margin-bottom: 4px;
}

.upload-zone-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.upload-file-feedback {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background-color: rgba(65, 176, 240, 0.08);
  border: 1px solid rgba(65, 176, 240, 0.25);
  font-size: 0.83rem;
  color: var(--text-secondary);
}

.upload-file-feedback.visible {
  display: flex;
}

.upload-file-preview {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.upload-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  color: var(--text);
}

.upload-file-size {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.upload-send-btn {
  flex-shrink: 0;
}

/* product image grid in form */
.product-img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.product-img-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elevated);
  text-align: center;
  transition: var(--transition);
}

.product-img-card:hover {
  border-color: var(--border-hover);
}

.product-img-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
  background-color: var(--bg-surface);
}

.product-img-actions {
  padding: 6px 8px;
  display: flex;
  gap: 4px;
}

.product-img-order {
  font-size: 0.7rem;
  color: var(--text-muted);
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

/* =============================================================================
   PRODUCT IMAGE — Principal panel & badge
   ============================================================================= */

.principal-img-panel {
  display: none;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(var(--primary-rgb), 0.4);
  background: rgba(var(--primary-rgb), 0.06);
}

.principal-img-preview-wrap {
  position: relative;
  flex-shrink: 0;
}

.principal-img-preview {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 2px solid var(--primary);
  display: block;
}

.principal-img-badge {
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.principal-img-info {
  flex: 1;
  min-width: 0;
}

.principal-img-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0 0 4px;
}

.principal-img-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.principal-img-empty {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: var(--bg-elevated);
}

.principal-img-empty-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* =============================================================================
   PRODUCT IMAGE CARDS — Principal state & drag-and-drop
   ============================================================================= */

.product-img-card--principal {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(var(--primary-rgb), 0.3);
}

.product-img-card--dragging {
  opacity: 0.45;
}

.product-img-card--dragover {
  border-color: var(--primary);
  background: rgba(var(--primary-rgb), 0.08);
  transform: scale(1.03);
}

.product-img-drag-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px 0;
  cursor: grab;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

.product-img-drag-handle:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.product-img-drag-handle svg {
  pointer-events: none;
}

.product-img-badge-principal {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  padding: 2px 0;
  background: var(--primary);
  color: var(--text-inverse);
  letter-spacing: 0.04em;
}

.product-img-set-principal {
  flex: 1;
  font-size: 0.68rem;
  padding: 3px 6px;
}

.product-img-principal-indicator {
  flex: 1;
  font-size: 0.78rem;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.product-img-drag-hint {
  margin-bottom: 8px;
}

/* =============================================================================
   FABRICANTES — Logo thumbnail in list and form preview panel
   ============================================================================= */

/* Thumbnail in the list table */
.fab-logo-thumb {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  display: block;
}

.fab-logo-missing {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Logo preview panel in form (mirrors .principal-img-panel) */
.logo-preview-panel {
  display: none;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  margin-bottom: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(var(--primary-rgb), 0.4);
  background: rgba(var(--primary-rgb), 0.06);
}

.logo-preview-wrap {
  flex-shrink: 0;
}

.logo-preview-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 2px solid var(--primary);
  background: var(--bg-surface);
  display: block;
}

.logo-preview-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.logo-preview-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0;
}

/* =============================================================================
   FORM LAYOUT UTILITIES — Multi-column, dense editing
   ============================================================================= */

/* Two-column form layout: main content + side panel */
.form-layout-2col {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
  align-items: start;
}

.form-col-main {
  min-width: 0;
}

.form-col-side {
  min-width: 0;
}

/* Responsive: stack on smaller screens */
@media (max-width: 1100px) {
  .form-layout-2col {
    grid-template-columns: 1fr;
  }
}

/* Inline row of form fields — distribute short fields side by side */
.form-row {
  display: grid;
  gap: 16px;
  margin-bottom: 0;
}

.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-auto { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* Tighter form-group in dense layouts */
.form-group--compact {
  margin-bottom: 14px;
}

/* Compact form-group label */
.form-group--compact label {
  margin-bottom: 5px;
}

/* Inline checkbox row — multiple checks side by side */
.form-checks-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 10px 0 4px;
}

/* Side panel card variant (sticky) */
.card--side {
  position: sticky;
  top: calc(var(--header-height) + 16px);
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.card--side .card-title {
  font-size: 1rem;
  margin-bottom: 14px;
  padding-bottom: 10px;
}

/* Product image grid in side column — tighter */
.product-img-grid--side {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.product-img-grid--side .product-img-thumb {
  height: 80px;
}

/* Principal badge on first card in side column */
.product-img-card--first-principal {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(var(--primary-rgb), 0.3);
}

/* Upload zone compact for side column */
.upload-zone--compact {
  padding: 14px 12px;
}

.upload-zone--compact .upload-zone-icon {
  width: 26px;
  height: 26px;
  margin-bottom: 6px;
}

.upload-zone--compact .upload-zone-cta {
  font-size: 0.82rem;
}

.upload-zone--compact .upload-zone-hint {
  font-size: 0.72rem;
}

/* =============================================================================
    TABELA EDITOR — Table Builder UI (Grid Editor + Preview)
    ============================================================================= */

.tabela-editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tabela-editor__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background-color: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tabela-editor__tabs {
  display: flex;
  gap: 2px;
  list-style: none;
  border-radius: var(--radius-md);
  background-color: var(--bg-base);
  border: 1px solid var(--border-hover);
  padding: 3px;
  align-items: center;
}

.tabela-editor__tabs li {
  display: flex;
  align-items: center;
}

.tabela-editor__tabs button,
.tabela-editor__tab {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tabela-editor__tabs button:hover,
.tabela-editor__tab:hover {
  background-color: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border-hover);
}

.tabela-editor__tabs button.active,
.tabela-editor__tab.active {
  background-color: var(--primary);
  color: white;
  font-weight: 600;
  border-color: transparent;
  box-shadow: 0 1px 4px rgba(65, 176, 240, 0.3);
}

.tabela-editor__tabs .remove-btn {
  padding: 2px 6px;
  margin-left: 2px;
  font-size: 0.8rem;
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  line-height: 1.4;
}

.tabela-editor__tabs .remove-btn:hover {
  background-color: var(--danger);
  color: white;
  border-color: var(--danger);
  transform: scale(1.1);
}

.tabela-editor__add-btn {
  padding: 5px 12px;
  background-color: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: var(--success);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.tabela-editor__add-btn:hover {
  background-color: var(--success);
  color: white;
  border-color: var(--success);
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);
  transform: translateY(-1px);
}

.tabela-editor__toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.tabela-editor__toggle:hover {
  background-color: var(--bg-hover);
  color: var(--text);
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(65, 176, 240, 0.15);
}

.tabela-editor__toggle.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(65, 176, 240, 0.3);
}

.tabela-editor__content {
  display: flex;
  flex: 1;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.tabela-editor__visual {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  overflow: auto;
}

.tabela-editor__grid-container {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
}

.tabela-editor__grid {
  display: table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 1px;
  background-color: var(--border);
}

.tabela-editor__grid-row {
  display: table-row;
}

/* ── Actual rendered grid table (created by renderGrid()) ── */
.tabela-editor__grid-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 2px;
  background-color: var(--bg-base);
  margin-bottom: 4px;
}

.tabela-editor__grid-table td {
  border: 1px solid var(--border-hover);
  background-color: var(--bg-elevated);
  padding: 0;
  height: 42px;
  min-width: 100px;
  position: relative;
  vertical-align: middle;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tabela-editor__grid-table td:hover {
  border-color: rgba(65, 176, 240, 0.5);
  background-color: rgba(65, 176, 240, 0.04);
}

.tabela-editor__grid-table tr.tabela-editor__header-row td {
  background-color: rgba(65, 176, 240, 0.1);
  border-color: rgba(65, 176, 240, 0.3);
}

.tabela-editor__grid-table tr.tabela-editor__header-row td:hover {
  border-color: var(--primary);
  background-color: rgba(65, 176, 240, 0.18);
}

.tabela-editor__cell-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
  box-sizing: border-box;
  display: block;
}

.tabela-editor__cell-input:focus {
  background-color: rgba(65, 176, 240, 0.12);
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  color: var(--text);
}

.tabela-editor__header-row .tabela-editor__cell-input {
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.01em;
}

.tabela-editor__grid-cell {
  display: table-cell;
  border: 1px solid var(--border-hover);
  background-color: var(--bg-elevated);
  padding: 0;
  height: 42px;
  min-width: 100px;
  position: relative;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tabela-editor__grid-cell:hover {
  border-color: var(--primary);
  background-color: rgba(65, 176, 240, 0.04);
}

.tabela-editor__grid-cell input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
  box-sizing: border-box;
}

.tabela-editor__grid-cell input:focus {
  background-color: rgba(65, 176, 240, 0.12);
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  color: var(--text);
}

.tabela-editor__grid-cell.header input {
  font-weight: 600;
  color: var(--primary);
}

.tabela-editor__grid-controls {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  flex-wrap: wrap;
  background-color: var(--bg-base);
  border-top: 1px solid var(--border);
  align-items: center;
}

.tabela-editor__grid-controls .btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  border-radius: var(--radius-md);
  flex: 1;
  min-width: 90px;
  justify-content: center;
}

.tabela-editor__grid-controls .btn-secondary {
  border-color: var(--border-hover);
}

.tabela-editor__grid-controls .btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tabela-editor__grid-controls .btn-danger {
  flex: 1;
  min-width: 90px;
  justify-content: center;
}

.tabela-editor__code {
  flex: 1;
  display: none;
  flex-direction: column;
  background-color: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  overflow: hidden;
}

.tabela-editor__code.visible {
  display: flex;
}

.tabela-editor__code-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.tabela-editor__code-textarea {
  flex: 1;
  width: 100%;
  font-family: 'Courier New', monospace;
  font-size: 0.75rem;
  color: var(--text);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  resize: none;
  overflow: auto;
  line-height: 1.4;
  tab-size: 2;
}

.tabela-editor__code-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(65, 176, 240, 0.15);
}

.tabela-editor__code-error {
  margin-top: 8px;
  padding: 8px 12px;
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  color: #f87171;
  font-size: 0.75rem;
  line-height: 1.4;
  display: none;
}

.tabela-editor__code-error.visible {
  display: block;
}

.tabela-editor__preview {
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  overflow: auto;
  margin-top: 12px;
}

.tabela-editor__preview-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.product-table-wrapper {
  flex: 1;
  overflow: auto;
}

.product-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  table-layout: auto;
}

.product-table thead {
  background-color: var(--primary);
}

.product-table thead tr {
  border: none;
}

.product-table thead th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-weight: 600;
  color: white;
  white-space: normal;
  min-width: 80px;
  max-width: 200px;
  border: none;
  line-height: 1.3;
}

.product-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s ease;
}

.product-table tbody tr:hover {
  background-color: rgba(65, 176, 240, 0.05);
}

.product-table tbody tr:last-child {
  border-bottom: none;
}

.product-table tbody tr:nth-child(even) {
  background-color: rgba(65, 176, 240, 0.02);
}

.product-table tbody td {
  padding: 0.75rem 1rem;
  color: var(--text);
  border: none;
  white-space: normal;
  word-break: break-word;
  min-width: 60px;
  max-width: 180px;
  line-height: 1.4;
}

.product-table tbody td:first-child {
  font-weight: 600;
  color: var(--primary);
  min-width: 100px;
}

.tabela-editor__merged-cell {
  background-color: rgba(65, 176, 240, 0.12);
  border: 1px solid rgba(65, 176, 240, 0.25) !important;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 10px;
  vertical-align: middle;
  pointer-events: none;
  position: relative;
  line-height: 1.3;
}

.tabela-editor__merged-cell::after {
  content: '\229E';
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 0.65rem;
  color: var(--primary);
  opacity: 0.7;
  line-height: 1;
}

.tabela-editor__merged-cell input {
  cursor: not-allowed;
  opacity: 0.5;
}

.tabela-editor__merged-cell input:focus {
  background-color: transparent;
  outline: none;
}

.tabela-editor__header-row td {
  background-color: rgba(65, 176, 240, 0.1);
  border-color: rgba(65, 176, 240, 0.3) !important;
}

.tabela-editor__header-row input {
  font-weight: 700;
  color: var(--primary);
  background-color: transparent;
  letter-spacing: 0.01em;
}

/* Responsive: Stack visual and code on mobile */
@media (max-width: 1024px) {
  .tabela-editor__content {
    flex-direction: column;
  }

  .tabela-editor__visual,
  .tabela-editor__code {
    flex: 1;
    min-height: 300px;
  }

  .tabela-editor__code.visible {
    display: flex;
  }

  .tabela-editor__grid-cell {
    height: 36px;
    min-width: 60px;
  }

  .tabela-editor__grid-table td {
    height: 36px;
    min-width: 70px;
  }
}

@media (max-width: 768px) {
  .tabela-editor__toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .tabela-editor__tabs {
    width: 100%;
    overflow-x: auto;
  }

  .tabela-editor__toggle {
    width: 100%;
    justify-content: center;
  }

  .tabela-editor__content {
    padding: 8px;
    gap: 8px;
  }

  .tabela-editor__visual,
  .tabela-editor__code {
    padding: 8px;
  }

  .tabela-editor__grid-controls {
    flex-direction: column;
  }

  .tabela-editor__grid-controls .btn {
    width: 100%;
  }

  .product-table {
    font-size: 0.75rem;
  }

  .product-table thead th,
  .product-table tbody td {
    padding: 0.5rem 0.75rem;
  }
}
