/* --- ROOT & THEME VARIABLES --- */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;

  --accent-black: #0f172a;
  --accent-hover: #334155;
  --accent-light: #e2e8f0;

  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --input-focus: #0f172a;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

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

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

[data-theme="dark"] {
  --bg-primary: #090d16;
  --bg-secondary: #131b2e;
  --bg-tertiary: #1e293b;
  --bg-card: #131b2e;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border-color: #1e293b;
  --border-hover: #334155;

  --accent-black: #f8fafc;
  --accent-hover: #e2e8f0;
  --accent-light: #1e293b;

  --input-bg: #0f172a;
  --input-border: #334155;
  --input-focus: #f8fafc;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* --- RESET & BASE STYLES --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color var(--transition-normal), color var(--transition-normal);
  -webkit-text-size-adjust: 100%;
}

/* --- HEADER & NAVIGATION --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(12px);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.header-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-primary);
  flex-shrink: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background-color: var(--accent-black);
  color: var(--bg-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  white-space: nowrap;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-tabs {
  display: flex;
  background-color: var(--bg-tertiary);
  padding: 3px;
  border-radius: var(--radius-md);
  gap: 3px;
}

.nav-tab {
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background-color: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.theme-toggle-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.theme-toggle-btn:hover {
  background: var(--border-hover);
  transform: scale(1.05);
}

/* --- MAIN CONTAINER --- */
.main-content {
  max-width: 1280px;
  margin: 1.25rem auto;
  padding: 0 1rem;
}

.page-tab {
  display: none;
  animation: fadeIn 0.3s ease;
}

.page-tab.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- CARD CONTAINERS --- */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
}

/* --- GRID LAYOUTS & RESPONSIVE FIXES --- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

@media (max-width: 768px) {
  .grid-2, .grid-4 {
    grid-template-columns: 1fr !important;
  }
  
  .header-container {
    padding: 0.6rem 0.75rem;
  }
  .brand-title {
    font-size: 0.95rem;
  }
  .nav-tab {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
  }
  .card {
    padding: 1rem;
    border-radius: var(--radius-md);
  }
}

/* --- FORM CONTROLS & AUTOCOMPLETE (PREVENT MOBILE AUTO-ZOOM WITH FONT-SIZE 16PX) --- */
.form-group {
  position: relative;
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-primary);
}

/* Key fix: font-size 16px prevents iOS Safari auto-zooming on focus */
.form-control {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 16px !important;
  font-family: inherit;
  background-color: var(--input-bg);
  color: var(--text-primary);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
  box-sizing: border-box;
}

.form-control:focus {
  border-color: var(--input-focus);
  box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.15);
}

[data-theme="dark"] .form-control:focus {
  box-shadow: 0 0 0 3px rgba(248, 250, 252, 0.2);
}

.char-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  float: right;
  margin-top: 0.25rem;
}

/* --- AUTOCOMPLETE DROPDOWN SUGGESTIONS --- */
.autocomplete-wrapper {
  position: relative;
  width: 100%;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 99;
  max-height: 200px;
  overflow-y: auto;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  margin-top: 4px;
  display: none;
  -webkit-overflow-scrolling: touch;
}

.autocomplete-dropdown.show {
  display: block;
}

.autocomplete-item {
  padding: 0.75rem 0.85rem;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--transition-fast);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover, .autocomplete-item.active {
  background-color: var(--bg-tertiary);
  font-weight: 600;
}

/* --- UPLOAD DROP ZONE --- */
.drop-zone {
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  cursor: pointer;
  background-color: var(--bg-tertiary);
  transition: all var(--transition-fast);
}

.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--accent-black);
  background-color: var(--border-hover);
}

.drop-zone-icon {
  font-size: 1.5rem;
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
}

.drop-zone-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.drop-zone-input {
  display: none;
}

/* --- BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  user-select: none;
}

.btn-primary {
  background-color: var(--accent-black);
  color: var(--bg-primary);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--border-hover);
}

.btn-danger {
  background-color: #ef4444;
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* --- FONT STYLE TOGGLE BUTTONS --- */
.style-toggle-btn {
  background-color: var(--input-bg);
  color: var(--text-secondary);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.style-toggle-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.style-toggle-btn.active {
  background-color: var(--accent-black) !important;
  color: var(--bg-primary) !important;
  border-color: var(--accent-black) !important;
  box-shadow: var(--shadow-sm);
}

/* --- CERTIFICATE PREVIEW & CANVAS CONTAINER --- */
.canvas-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.canvas-preview-container {
  width: 100%;
  max-width: 1000px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-color);
  background-color: #000000;
  position: relative;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* --- ADMIN VISUAL EDITOR OVERLAY --- */
.editor-overlay-container {
  position: relative;
  width: 100%;
}

.visual-handle {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 2px dashed #00e676;
  background: rgba(0, 230, 118, 0.2);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  font-weight: 700;
  font-size: 0.75rem;
  user-select: none;
  touch-action: none;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  z-index: 10;
  border-radius: 4px;
  padding: 4px;
}

.visual-handle.circle-handle {
  border-radius: 50%;
}

.handle-resize-dot {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background-color: #00e676;
  border: 2px solid #000;
  border-radius: 50%;
  cursor: nwse-resize;
  z-index: 15;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.handle-resize-dot:hover {
  transform: scale(1.2);
}

.visual-handle-label {
  background: #00e676;
  color: #000;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}

/* --- ADMIN PASSWORD MODAL --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  padding: 1.75rem;
  box-shadow: var(--shadow-xl);
}

/* --- TABLES --- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
  white-space: nowrap;
}

th {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
}

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

tr.selected-row td {
  background-color: var(--bg-tertiary);
  font-weight: 600;
}

tr:hover td {
  background-color: var(--bg-tertiary);
}

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: calc(100vw - 3rem);
}

.toast {
  background-color: var(--accent-black);
  color: var(--bg-primary);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast-error {
  background-color: #ef4444;
  color: #ffffff;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- BADGES & TAGS --- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.badge-dark {
  background-color: var(--accent-black);
  color: var(--bg-primary);
}
