/*
 Design System Tokens & Components
 - Scope: Global (loaded from RCL as /_content/RIICAdmission.Client/css/theme.css)
 - Goal: Cohesive UI across pages (Nav, Topbar, Records, etc.)
*/

:root {
  /* Brand colors (darker purple) */
  --color-brand: #4B217F;         /* Deep Purple */
  --color-brand-600: #4B217F;
  --color-brand-500: #5B2BBF;
  --color-brand-700: #2E1065;     /* Darkest */

  /* Gold accent system */
  --color-gold: #FFD700;          /* Pure Gold */
  --color-gold-light: #FFF8DC;    /* Light Gold/Cornsilk */
  --color-gold-dark: #B8860B;     /* Dark Gold */
  --color-gold-accent: #F4D03F;   /* Warm Gold */

  --color-accent: #3b82f6;        /* Blue 500 */
  --color-success: #10b981;       /* Emerald 500 */
  --color-danger: #ef4444;        /* Red 500 */
  --color-warning: #f59e0b;       /* Amber 500 */

  /* Neutrals */
  --color-bg: #f8fafc;            /* slate-50 */
  --color-surface: #ffffff;       /* white */
  --color-border: #e5e7eb;        /* gray-200 */
  --color-border-strong: #d1d5db; /* gray-300 */
  --color-text: #0f172a;          /* slate-900 */
  --color-subtle: #64748b;        /* slate-500 */

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 2px 10px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;

  /* Typography */
  --font-base: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

html, body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, var(--color-brand-700), var(--color-brand-500));
  color: #fff;
  box-shadow: 2px 0 8px rgba(0,0,0,.08), inset -2px 0 0 0 var(--color-gold-accent);
  z-index: 30;
}

.sidebar-inner { padding: var(--sp-5) var(--sp-4); height: 100%; display:flex; flex-direction:column; }
.nav-brand { display:flex; align-items:center; gap: var(--sp-3); padding: 0 var(--sp-2) var(--sp-5); }
.nav-brand img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.nav-brand .brand-text { font-weight: 800; letter-spacing: .2px; }

.nav { display:flex; flex-direction:column; gap: 4px; }
.nav a { display:flex; align-items:center; gap: 10px; padding: 10px 12px; color: rgba(255,255,255,.92); border-radius: var(--radius-sm); text-decoration: none; transition: .2s ease; position: relative; }
.nav a::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 0; height: 80%; background: var(--color-gold); border-radius: 0 4px 4px 0; transition: width .2s ease; }
.nav a:hover { background: rgba(255,255,255,.12); transform: translateX(4px); }
.nav a:hover::before { width: 3px; }
.nav a.active { background: rgba(255,255,255,.18); box-shadow: inset 2px 0 0 0 var(--color-gold); color: #fff; }
.nav a.active::before { width: 3px; background: var(--color-gold); }
.nav .icon { width: 20px; text-align:center; }

.sidebar-footer { margin-top:auto; padding: var(--sp-4) var(--sp-2); color: rgba(255,255,255,.7); font-size: 12px; }

.app-main { display:flex; flex-direction: column; min-width: 0; }

.app-topbar {
  position: sticky; top: 0; z-index: 20;
  height: 64px; display:flex; align-items:center; justify-content: space-between;
  padding: 0 var(--sp-6);
  background: linear-gradient(90deg, var(--color-surface) 0%, var(--color-gold-light) 100%);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 3px rgba(0,0,0,.05), inset 0 -1px 0 0 var(--color-gold-accent);
}

.topbar-left { display:flex; align-items:center; gap: var(--sp-4); }
.topbar-title { font-weight: 700; font-size: 16px; color: var(--color-text); }
.topbar-actions { display:flex; align-items:center; gap: var(--sp-2); }

.app-content { padding: var(--sp-6); }

/* Page header */
.page-header { display:flex; align-items:center; justify-content: space-between; margin-bottom: var(--sp-6); }
.page-header h2 { display:flex; align-items:center; gap: var(--sp-3); margin:0; font-size: 22px; }
.header-actions { display:flex; gap: var(--sp-2); }

/* Cards */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, var(--color-brand), var(--color-gold-accent)); opacity: 0; transition: opacity .2s ease; }
.card:hover::before { opacity: 1; }
.card.pad { padding: var(--sp-5); }

/* Buttons */
.btn { border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text); padding: 9px 14px; border-radius: var(--radius-sm); font-weight: 600; cursor:pointer; transition: .2s ease; position: relative; overflow: hidden; }
.btn::after { content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255,215,0,.2), transparent); transition: left .3s ease; }
.btn:hover { box-shadow: var(--shadow-sm), 0 0 0 1px var(--color-gold-accent); transform: translateY(-1px); }
.btn:hover::after { left: 100%; }
.btn:disabled { opacity:.6; cursor:not-allowed; transform:none; }

.btn-primary { background: var(--color-brand); border-color: var(--color-brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.05); box-shadow: var(--shadow-md), 0 0 12px rgba(255,215,0,.3); }
.btn-secondary { background:#eef2ff; border-color:#e0e7ff; color: #3730a3; }
.btn-success { background: var(--color-success); border-color: var(--color-success); color:#fff; }
.btn-danger { background: var(--color-danger); border-color: var(--color-danger); color:#fff; }
.btn-outline { background: transparent; border-color: var(--color-border-strong); color: var(--color-text); }
.btn-icon { padding: 8px 10px; display:inline-flex; align-items:center; justify-content:center; }

/* Gold accent button variant */
.btn-gold { background: linear-gradient(135deg, var(--color-gold), var(--color-gold-accent)); border-color: var(--color-gold-dark); color: var(--color-brand-700); font-weight: 700; }
.btn-gold:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg), 0 0 20px rgba(255,215,0,.4); }

/* Inputs */
.input, .select, .textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: #fff; transition: .2s ease; }
.input:focus, .select:focus, .textarea:focus { outline:none; border-color: var(--color-brand); box-shadow: 0 0 0 3px rgba(75,33,127,0.18), 0 0 0 1px var(--color-gold-accent); }

/* Tables */
.table-container { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow:hidden; position: relative; }
.table-container::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--color-brand), var(--color-gold), var(--color-brand)); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead th { background: linear-gradient(90deg, var(--color-brand-700), var(--color-brand-600)); color:#fff; text-align:left; padding: 12px; font-weight:700; letter-spacing:.2px; position: relative; }
.table thead th::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px; background: var(--color-gold-accent); opacity: 0.6; }
.table tbody td { padding: 12px; border-top: 1px solid var(--color-border); vertical-align: middle; }
.table tbody tr:hover { background: linear-gradient(90deg, #f8fafc, var(--color-gold-light)); }

/* Tags */
.tag { display:inline-flex; align-items:center; gap: 6px; padding: 4px 8px; border-radius: 9999px; font-size: 12px; border: 1px solid var(--color-border); background:#f1f5f9; color:#0f172a; position: relative; overflow: hidden; }
.tag::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 1px; background: var(--color-gold-accent); opacity: 0.5; }
.tag.department { background:#ecfeff; border-color:#a5f3fc; color:#155e75; }
.tag.programme { background:#f5f3ff; border-color:#ddd6fe; color:#3730a3; }
.tag.gold { background: linear-gradient(135deg, var(--color-gold-light), var(--color-gold-accent)); border-color: var(--color-gold-dark); color: var(--color-brand-700); font-weight: 600; }

/* Pagination */
.pagination { display:flex; align-items:center; gap: 6px; }
.page-btn { border:1px solid var(--color-border-strong); background:#fff; padding:6px 10px; border-radius: var(--radius-sm); cursor:pointer; transition: .2s ease; }
.page-btn:hover { border-color: var(--color-gold-accent); box-shadow: 0 0 0 1px var(--color-gold-accent); }
.page-btn.active { background: linear-gradient(135deg, var(--color-brand), var(--color-brand-600)); color:#fff; border-color: var(--color-brand); box-shadow: 0 0 8px rgba(255,215,0,.3); }
.page-info { color: var(--color-subtle); font-size: 13px; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(2,6,23,.6); display:flex; align-items:center; justify-content:center; z-index: 50; backdrop-filter: blur(2px); padding: 20px; overflow-y: auto; }
.modal-content { width: min(900px, 92vw); max-height: 90vh; background:#fff; border-radius: var(--radius-md); box-shadow: var(--shadow-lg), 0 0 30px rgba(255,215,0,.1); overflow:hidden; border:1px solid var(--color-border); position: relative; display: flex; flex-direction: column; }
.modal-content::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, var(--color-brand), var(--color-gold), var(--color-brand)); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--color-border); background: linear-gradient(90deg, #f8fafc, var(--color-gold-light)); flex-shrink: 0; }
.modal-body { padding: var(--sp-5); overflow-y: auto; flex: 1; }
.scrollable-modal-body { max-height: 60vh; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--color-border); background: linear-gradient(90deg, #fafafa, var(--color-gold-light)); flex-shrink: 0; }
.close-btn { background: transparent; border: none; font-size: 18px; cursor: pointer; color: var(--color-subtle); padding: 4px; border-radius: 4px; transition: all 0.2s ease; }
.close-btn:hover { background: rgba(255, 0, 0, 0.1); color: var(--color-danger); }

/* Document viewer modal specific styles */
.document-viewer-modal {
  width: min(1200px, 95vw);
  max-height: 95vh;
}

.document-modal-body {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  background: #f5f5f5;
}

.document-modal-body img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  margin: auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.document-modal-body iframe {
  width: 100%;
  height: 70vh;
  border: 0;
  background: white;
}

/* Qualifications modal */
.qualifications-modal {
  width: min(1000px, 95vw);
}

.qual-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.qual-table th,
.qual-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.qual-table th {
  background: var(--color-brand);
  color: white;
  font-weight: 600;
}

.qual-table tr:hover {
  background: var(--color-gold-light);
}

.download-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 12px;
  margin-right: 8px;
}

.no-doc {
  color: var(--color-subtle);
  font-style: italic;
}

/* Manage documents modal */
.manage-documents-modal {
  width: min(600px, 90vw);
}

.document-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.document-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}

.document-list li:last-child {
  border-bottom: none;
}

.document-list i {
  color: var(--color-brand);
  width: 20px;
  text-align: center;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-brand);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: auto;
  font-size: 14px;
}

.btn-link:hover {
  color: var(--color-gold-dark);
}

/* Responsive */
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar { position: fixed; left: -280px; width: 260px; transition: left .25s ease; }
  .app-sidebar.show { left: 0; }
  .app-topbar { padding: 0 var(--sp-4); }
}

/* Gold accent animations and utilities */
@keyframes goldShimmer {
  0% { background-position: -200px 0; }
  100% { background-position: calc(200px + 100%) 0; }
}

.gold-shimmer {
  background: linear-gradient(90deg, transparent, var(--color-gold-accent), transparent);
  background-size: 200px 100%;
  animation: goldShimmer 2s infinite;
}

.text-gold { color: var(--color-gold-dark); }
.bg-gold { background: var(--color-gold-light); }
.border-gold { border-color: var(--color-gold-accent); }

/* Premium card variant */
.card-premium {
  background: linear-gradient(135deg, #ffffff 0%, var(--color-gold-light) 100%);
  border: 2px solid var(--color-gold-accent);
  box-shadow: var(--shadow-md), 0 0 20px rgba(255,215,0,.15);
  position: relative;
  overflow: hidden;
}

.card-premium::after {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, var(--color-brand), var(--color-gold), var(--color-brand), var(--color-gold));
  background-size: 400% 400%;
  animation: gradientShift 3s ease infinite;
  z-index: -1;
  border-radius: var(--radius-md);
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* Status indicators with gold accents */
.status-active { color: var(--color-success); }
.status-pending { color: var(--color-gold-dark); }
.status-inactive { color: var(--color-subtle); }

/* Gold loading spinner */
.spinner-gold {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-gold-light);
  border-top: 2px solid var(--color-gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsive Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2,6,23,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
  padding: 20px;
  overflow-y: auto;
}

.modal-content {
  width: min(900px, 92vw);
  max-height: 90vh;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(255,215,0,.1);
  overflow: hidden;
  border: 1px solid var(--color-border);
  position: relative;
  display: flex;
  flex-direction: column;
}

.modal-content::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-brand), var(--color-gold), var(--color-brand));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--color-border);
  background: linear-gradient(90deg, #f8fafc, var(--color-gold-light));
  flex-shrink: 0;
}

.modal-body {
  padding: var(--sp-5);
  overflow-y: auto;
  flex: 1;
}

.scrollable-modal-body {
  max-height: 60vh;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--color-border);
  background: linear-gradient(90deg, #fafafa, var(--color-gold-light));
  flex-shrink: 0;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--color-subtle);
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: rgba(255, 0, 0, 0.1);
  color: var(--color-danger);
}

/* Document viewer modal specific styles */
.document-viewer-modal {
  width: min(1200px, 95vw);
  max-height: 95vh;
}

.document-modal-body {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  background: #f5f5f5;
}

.document-modal-body img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  margin: auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.document-modal-body iframe {
  width: 100%;
  height: 70vh;
  border: 0;
  background: white;
}

/* Qualifications modal */
.qualifications-modal {
  width: min(1000px, 95vw);
}

.qual-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

.qual-table th,
.qual-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

.qual-table th {
  background: var(--color-brand);
  color: white;
  font-weight: 600;
}

.qual-table tr:hover {
  background: var(--color-gold-light);
}

.download-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 12px;
  margin-right: 8px;
}

.no-doc {
  color: var(--color-subtle);
  font-style: italic;
}

/* Manage documents modal */
.manage-documents-modal {
  width: min(600px, 90vw);
}

.document-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.document-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}

.document-list li:last-child {
  border-bottom: none;
}

.document-list i {
  color: var(--color-brand);
  width: 20px;
  text-align: center;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-brand);
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: auto;
  font-size: 14px;
}

.btn-link:hover {
  color: var(--color-gold-dark);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 10px;
    align-items: flex-start;
    padding-top: 20px;
  }
  
  .modal-content {
    width: 100%;
    max-height: 90vh;
  }
  
  .modal-header {
    padding: var(--sp-3) var(--sp-4);
  }
  
  .modal-header h3 {
    font-size: 16px;
  }
  
  .modal-body {
    padding: var(--sp-4);
  }
  
  .modal-footer {
    padding: var(--sp-3) var(--sp-4);
  }
  
  .document-viewer-modal {
    width: 100%;
  }
  
  .document-modal-body img {
    max-height: 50vh;
  }
  
  .document-modal-body iframe {
    height: 50vh;
  }
  
  .qual-table {
    font-size: 12px;
  }
  
  .qual-table th,
  .qual-table td {
    padding: 8px 4px;
  }
  
  .document-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .btn-link {
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .modal-overlay {
    padding: 5px;
  }
  
  .modal-header h3 {
    font-size: 14px;
  }
  
  .modal-body {
    padding: var(--sp-3);
  }
  
  .document-modal-body img {
    max-height: 40vh;
  }
  
  .document-modal-body iframe {
    height: 40vh;
  }
}

/* Detail grid responsive */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.detail-section {
  background: #f8fafc;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.detail-section h4 {
  margin: 0 0 12px 0;
  color: var(--color-brand);
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--color-gold-accent);
  padding-bottom: 4px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
  gap: 12px;
}

.detail-row .label {
  font-weight: 600;
  color: var(--color-subtle);
  min-width: 120px;
  font-size: 13px;
}

.detail-row .value {
  font-weight: 500;
  color: var(--color-text);
  text-align: right;
  word-break: break-word;
}

@media (max-width: 768px) {
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .detail-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  
  .detail-row .label {
    min-width: auto;
  }
  
  .detail-row .value {
    text-align: left;
  }
}

/* Candidate photo in detail modal */
.candidate-photo-container {
  text-align: center;
  margin-bottom: 24px;
}

.candidate-photo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--color-gold-accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

@media (max-width: 768px) {
  .candidate-photo {
    width: 80px;
    height: 80px;
  }
}
