/* ==========================================================================
   Certificate Management & Generation Web Portal
   Commercial Modern Design System & UI Architecture
   ========================================================================== */

:root {
  /* Brand Color Palette */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-focus: rgba(37, 99, 235, 0.2);

  --secondary: #475569;
  --secondary-hover: #334155;
  --secondary-light: #f1f5f9;

  --success: #10b981;
  --success-hover: #059669;
  --success-light: #ecfdf5;
  --success-text: #065f46;

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fef2f2;
  --danger-text: #991b1b;

  --warning: #f59e0b;
  --warning-hover: #d97706;
  --warning-light: #fffbeb;
  --warning-text: #92400e;

  --info: #06b6d4;
  --info-light: #ecfeff;
  --info-text: #155e75;

  /* Neutrals & Surfaces */
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --border-focus: #93c5fd;

  /* Typography Scale */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Dimensions & Spacing */
  --sidebar-width: 260px;
  --topbar-height: 68px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease-in-out;
}
a:hover {
  color: var(--primary-hover);
}

/* ==========================================================================
   Application Master Layout
   ========================================================================== */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar Styles */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: transform 0.25s ease-in-out;
}

.sidebar-brand {
  height: var(--topbar-height);
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}

.sidebar-brand-text {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-menu {
  flex: 1;
  overflow-y: auto;
  padding: 18px 12px;
  list-style: none;
}

.menu-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #64748b;
  padding: 12px 14px 6px;
  margin-top: 6px;
}

.menu-item {
  margin-bottom: 3px;
}

.menu-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--sidebar-text);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s ease;
}

.menu-link:hover {
  background-color: var(--bg-sidebar-hover);
  color: #ffffff;
}

.menu-link.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.menu-link svg {
  flex-shrink: 0;
}

/* Sidebar Footer User Info */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 12px;
  background-color: rgba(0, 0, 0, 0.2);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.15);
}

.user-info-text {
  flex: 1;
  min-width: 0;
}

.user-info-name {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-info-role {
  font-size: 11px;
  color: #94a3b8;
  text-transform: capitalize;
}

/* Main Content Area */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

/* Topbar Header */
.app-topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Main Content Body */
.app-content {
  padding: 32px;
  flex: 1;
}

/* ==========================================================================
   Cards & Surfaces
   ========================================================================== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #ffffff;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body {
  padding: 24px;
}

.card-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background-color: #fafbfc;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Stats Metrics Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow-sm);
}

.stat-icon-wrapper {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon-primary { background: var(--primary-light); color: var(--primary); }
.stat-icon-success { background: var(--success-light); color: var(--success); }
.stat-icon-warning { background: var(--warning-light); color: var(--warning); }
.stat-icon-danger { background: var(--danger-light); color: var(--danger); }
.stat-icon-info { background: var(--info-light); color: var(--info); }

.stat-content {
  flex: 1;
}

.stat-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
}

.stat-hint {
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
  background-color: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background-color: #f1f5f9;
  color: var(--text-primary);
  border-color: #cbd5e1;
}

.btn-success {
  background-color: var(--success);
  color: #ffffff;
}
.btn-success:hover {
  background-color: var(--success-hover);
  color: #ffffff;
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: var(--danger-hover);
  color: #ffffff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  border-radius: var(--radius-md);
}

/* CRUD Action Buttons (Specification: Eye, Pencil, Trash Can, Shield) */
.action-buttons-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-action {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-secondary);
}

/* Eye Icon (View) */
.btn-action-view:hover {
  background-color: var(--info-light);
  border-color: var(--info);
  color: var(--info);
}

/* Pencil Icon (Edit) */
.btn-action-edit:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* Trash Can Icon (Delete) */
.btn-action-delete:hover {
  background-color: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

/* Shield Icon (Module-level CRUD Permissions) */
.btn-action-shield {
  color: #8b5cf6;
}
.btn-action-shield:hover {
  background-color: #f5f3ff;
  border-color: #8b5cf6;
  color: #7c3aed;
}

/* ==========================================================================
   Form Controls & Inputs
   ========================================================================== */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label .required {
  color: var(--danger);
}

.form-control, .form-select {
  width: 100%;
  padding: 9px 13px;
  font-size: 13.5px;
  color: var(--text-primary);
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-focus);
}

textarea.form-control {
  min-height: 90px;
  resize: vertical;
}

.form-text {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

.search-box-wrapper {
  position: relative;
  min-width: 260px;
}

.search-box-wrapper input {
  padding-left: 36px;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Form Grid */
.row {
  display: flex;
  flex-wrap: wrap;
  margin: -10px;
}
.col-12 { width: 100%; padding: 10px; }
.col-6  { width: 50%; padding: 10px; }
.col-4  { width: 33.333%; padding: 10px; }
.col-3  { width: 25%; padding: 10px; }
.col-8  { width: 66.666%; padding: 10px; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th {
  background-color: #f8fafc;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  font-size: 13.5px;
}

.table tbody tr:hover {
  background-color: #f8fafc;
}

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

.nowrap {
  white-space: nowrap !important;
}

.student-code-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  letter-spacing: 0.3px;
  background: var(--primary-light);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  display: inline-block;
  font-size: 12.5px;
  border: 1px solid rgba(37, 99, 235, 0.15);
}

.course-info-cell {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 180px;
}

.course-title-text {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* ==========================================================================
   Badges & Status Tags
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
  line-height: 1.2;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-success { background: var(--success-light); color: var(--success-text); }
.badge-warning { background: var(--warning-light); color: var(--warning-text); }
.badge-danger  { background: var(--danger-light); color: var(--danger-text); }
.badge-secondary { background: var(--secondary-light); color: var(--secondary); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ==========================================================================
   Alerts & Notifications
   ========================================================================== */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  font-size: 13.5px;
  border: 1px solid transparent;
}

.alert-success { background: var(--success-light); color: var(--success-text); border-color: #a7f3d0; }
.alert-danger  { background: var(--danger-light); color: var(--danger-text); border-color: #fecaca; }
.alert-warning { background: var(--warning-light); color: var(--warning-text); border-color: #fde68a; }
.alert-info    { background: var(--info-light); color: var(--info-text); border-color: #a5f3fc; }

.btn-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: currentColor;
  opacity: 0.6;
}
.btn-close:hover { opacity: 1; }

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 600px;
  overflow: hidden;
  transform: translateY(-20px);
  transition: transform 0.2s ease;
}

.modal-backdrop.show .modal-dialog {
  transform: translateY(0);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 24px;
  max-height: 70vh;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  background: #fafbfc;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================================
   Template Drag-and-Drop Visual Studio
   ========================================================================== */
.template-studio-wrapper {
  display: flex;
  gap: 24px;
}
.template-canvas-area {
  flex: 1;
  min-width: 0;
  background: #cbd5e1;
  padding: 24px;
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
  min-height: 520px;
}
.canvas-container {
  position: relative;
  background: #ffffff;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.25);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
}
.canvas-bg-img {
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.editor-element {
  position: absolute;
  cursor: move;
  border: 2px dashed rgba(37, 99, 235, 0.4);
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  line-height: 1;
  z-index: 10;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.editor-element:hover {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.08);
}
.editor-element.active {
  border: 2px solid var(--primary);
  background: rgba(37, 99, 235, 0.12);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
  z-index: 20;
}
.qr-element-box {
  background: rgba(255, 255, 255, 0.85);
  border: 2px dashed #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  color: #475569;
  gap: 4px;
}
.template-inspector-panel {
  width: 320px;
  flex-shrink: 0;
}
.element-selector-pill {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}
.btn-element-select {
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  background: #f8fafc;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
}
.btn-element-select:hover {
  background: #e2e8f0;
}
.btn-element-select.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 992px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .app-main {
    margin-left: 0;
  }
  .btn-sidebar-toggle {
    display: inline-flex;
  }
  .app-content {
    padding: 20px;
  }
  .col-6, .col-4, .col-8 {
    width: 100%;
  }
}
