/* =========================================================
   GrandLine Design System
   Shared component styles layered on top of Tailwind utilities.
   ========================================================= */

:root {
  --gl-primary: #00275E;
  --gl-primary-dark: #00122E;
  --gl-secondary: #FCCB0C;
  --gl-surface: #F5F7FB;
  --gl-radius: 0.875rem;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Plus Jakarta Sans', ui-sans-serif, system-ui, sans-serif;
  background: linear-gradient(180deg, #F7F9FC 0%, #F1F4F9 100%);
  background-attachment: fixed;
}

h1, h2, h3, .font-display {
  font-family: 'Sora', ui-sans-serif, system-ui, sans-serif;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* Top navbar (replaces the old sidebar)
   Fixed bar; #mainContent is pushed down by --nav-h. Below 1024px the links
   collapse into a hamburger dropdown. */
:root { --nav-h: 3.5rem; }

#topnav {
  height: var(--nav-h);
  background: linear-gradient(90deg, var(--gl-primary) 0%, var(--gl-primary-dark) 100%);
  box-shadow: 0 4px 24px rgba(0, 18, 46, 0.18);
}
#mainContent { margin-left: 0 !important; margin-top: var(--nav-h); }
@media print { #topnav { display: none !important; } #mainContent { margin-top: 0 !important; } }

#topnav .tn-inner { height: 100%; display: flex; align-items: center; gap: 1rem; padding: 0 1.25rem; }
#topnav .tn-logo { flex-shrink: 0; display: flex; align-items: center; }
#topnav .tn-logo img { height: 2rem; width: auto; object-fit: contain; }
#topnav .tn-toggle {
  display: none; margin-left: auto; width: 2.25rem; height: 2.25rem; border-radius: .5rem;
  color: rgba(255,255,255,.8); align-items: center; justify-content: center;
}
#topnav .tn-toggle:hover { color: #fff; background: rgba(255,255,255,.1); }

#topnav .tn-menu { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
#topnav .tn-nav { list-style: none; margin: 0; padding: 0; display: flex; align-items: center; gap: .15rem; }

#topnav .nav-link, #topnav .tn-logout {
  position: relative; display: flex; align-items: center; gap: .5rem;
  padding: .45rem .7rem; border-radius: .5rem; white-space: nowrap;
  font-size: .8rem; line-height: 1.25rem; color: rgba(255,255,255,.85);
  transition: background-color .18s ease, color .18s ease;
}
#topnav .nav-link i, #topnav .tn-logout i { width: 1rem; flex-shrink: 0; text-align: center; font-size: .8rem; }
#topnav .nav-link i { transition: transform .18s ease; }
#topnav .nav-link:hover { background: rgba(255,255,255,.08); }
#topnav .nav-link:hover i { transform: scale(1.1); }
#topnav .nav-link.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
#topnav .nav-link.active::after {
  content: ''; position: absolute; left: .7rem; right: .7rem; bottom: -.4rem; height: 3px;
  border-radius: 999px; background: var(--gl-secondary); box-shadow: 0 0 10px rgba(252,203,12,.6);
}

#topnav .tn-user-area { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; padding-left: .75rem; border-left: 1px solid rgba(255,255,255,.12); }
#topnav .tn-user { display: flex; align-items: center; gap: .5rem; color: rgba(255,255,255,.85); font-size: .75rem; min-width: 0; max-width: 11rem; }
#topnav .tn-avatar {
  width: 1.6rem; height: 1.6rem; border-radius: 999px; flex-shrink: 0;
  background: rgba(255,255,255,.1); display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,.7); font-size: .7rem;
}
#topnav .tn-logout { color: rgba(255,255,255,.7); }
#topnav .tn-logout:hover { color: #fff; background: rgba(255,255,255,.1); }

/* Tighter: hide link labels' icons on mid-size screens, keep labels */
@media (max-width: 1280px) { #topnav .nav-link i { display: none; } #topnav .tn-user span { display: none; } }

/* Narrow screens: hamburger + dropdown panel */
@media (max-width: 1023px) {
  #topnav .tn-toggle { display: flex; }
  #topnav .tn-menu {
    display: none; position: absolute; top: var(--nav-h); left: 0; right: 0; flex: none;
    flex-direction: column; align-items: stretch; gap: .5rem; padding: .5rem .75rem .75rem;
    background: var(--gl-primary-dark); box-shadow: 0 12px 24px rgba(0,18,46,.3);
    max-height: calc(100vh - var(--nav-h)); overflow-y: auto;
  }
  #topnav.open .tn-menu { display: flex; }
  #topnav .tn-nav { flex-direction: column; align-items: stretch; }
  #topnav .nav-link i { display: inline-block; }
  #topnav .nav-link.active::after { left: 0; right: auto; bottom: 20%; top: 20%; width: 3px; height: auto; }
  #topnav .tn-user-area { border-left: 0; padding-left: 0; border-top: 1px solid rgba(255,255,255,.12); padding-top: .5rem; justify-content: space-between; }
  #topnav .tn-user span { display: inline; }
}

/* Cards / KPI stat cards */
.gl-card {
  background: #fff;
  border-radius: var(--gl-radius);
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: 0 1px 2px rgba(16,24,40,0.04), 0 2px 8px rgba(16,24,40,0.05);
}
.kpi-card {
  background: #fff;
  border-radius: var(--gl-radius);
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow: 0 1px 2px rgba(16,24,40,0.04), 0 2px 8px rgba(16,24,40,0.05);
  padding: 1.25rem;
  transition: transform .2s ease, box-shadow .2s ease;
  position: relative;
  overflow: hidden;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(16,24,40,0.08), 0 12px 32px rgba(16,24,40,0.10); }
.kpi-card .kpi-icon {
  width: 2.75rem; height: 2.75rem;
  border-radius: 0.75rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.kpi-value { font-family: 'Sora', ui-sans-serif, system-ui, sans-serif; font-size: 1.65rem; font-weight: 700; color: #0F1E3D; line-height: 1.1; }
.kpi-label { font-size: .78rem; color: #6B7280; font-weight: 500; }
.kpi-trend { font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; }

/* Tables */
.table-wrap { border-radius: var(--gl-radius); overflow: hidden; border: 1px solid rgba(15,23,42,0.06); }
table.dataTable:not(.display) thead th, .gl-table thead th {
  background: #F8FAFC !important;
  text-transform: uppercase;
  font-size: .68rem;
  letter-spacing: .04em;
  color: #64748B;
  position: sticky; top: 0; z-index: 1;
}
table.dataTable tbody tr, .gl-table tbody tr { transition: background-color .15s ease; }
table.dataTable:not(.display) tbody tr:hover, .gl-table tbody tr:hover { background-color: #F8FAFC !important; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.badge-dot { width: .4rem; height: .4rem; border-radius: 999px; background: currentColor; }
.badge-success { background: #ECFDF5; color: #059669; }
.badge-warning  { background: #FFFBEB; color: #D97706; }
.badge-danger   { background: #FEF2F2; color: #DC2626; }
.badge-info     { background: #EFF6FF; color: #2563EB; }
.badge-neutral  { background: #F1F5F9; color: #475569; }
.item-badge { background: #EEF3FA; color: #00275E; font-weight: 700; border-radius: 999px; padding: .05rem .5rem; font-size: .72rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; font-size: .84rem; padding: .55rem 1.1rem; border-radius: .65rem; transition: transform .12s ease, box-shadow .12s ease, background-color .15s ease; position: relative; overflow: hidden; }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--gl-primary); color: #fff; }
.btn-primary:hover { background: #013275; box-shadow: 0 4px 12px rgba(0,39,94,0.25); }
.btn-secondary { background: var(--gl-secondary); color: #00275E; }
.btn-secondary:hover { box-shadow: 0 4px 12px rgba(252,203,12,0.35); }
.btn-ghost { background: transparent; color: #374151; border: 1px solid #E5E7EB; }
.btn-ghost:hover { background: #F9FAFB; }
.btn-icon { width: 2.1rem; height: 2.1rem; display: inline-flex; align-items: center; justify-content: center; border-radius: .6rem; transition: background-color .15s ease, transform .12s ease; }
.btn-icon:hover { background: #F1F5F9; transform: translateY(-1px); }
.btn .ripple { position: absolute; border-radius: 50%; transform: scale(0); animation: gl-ripple .5s linear; background: rgba(255,255,255,0.5); pointer-events: none; }
@keyframes gl-ripple { to { transform: scale(2.5); opacity: 0; } }

/* Forms */
.gl-field { position: relative; }
.gl-field input, .gl-field select, .gl-field textarea {
  width: 100%; border: 1px solid #E2E8F0; border-radius: .65rem;
  padding: .85rem .9rem .55rem 2.4rem; font-size: .875rem; background: #fff;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.gl-field input:focus, .gl-field select:focus, .gl-field textarea:focus {
  outline: none; border-color: var(--gl-primary); box-shadow: 0 0 0 3px rgba(0,39,94,0.10);
}
.gl-field .field-icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-30%); color: #94A3B8; font-size: .85rem; pointer-events: none; }
.gl-field label { position: absolute; left: 2.4rem; top: .6rem; font-size: .7rem; color: #94A3B8; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; pointer-events: none; }
.gl-field.valid input { border-color: #10B981; }
.gl-field.invalid input { border-color: #EF4444; }
.gl-field .field-msg { font-size: .72rem; margin-top: .25rem; }
.gl-field .field-msg.error { color: #DC2626; }
.gl-field .field-msg.success { color: #059669; }
.form-progress { display: flex; gap: .35rem; }
.form-progress .step { flex: 1; height: 4px; border-radius: 999px; background: #E2E8F0; }
.form-progress .step.done { background: var(--gl-secondary); }

/* Empty states */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 3.5rem 1.5rem; color: #64748B; }
.empty-state .empty-icon { width: 4rem; height: 4rem; border-radius: 999px; background: #EEF3FA; color: #00275E; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; margin-bottom: 1rem; }
.empty-state h4 { color: #1E293B; font-weight: 700; margin-bottom: .25rem; }

/* Skeletons / shimmer */
.skeleton { position: relative; overflow: hidden; background: #EDF1F7; border-radius: .5rem; }
.skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,0.65), transparent); animation: gl-shimmer 1.4s infinite; }
@keyframes gl-shimmer { 100% { transform: translateX(100%); } }

/* Motion */
.fade-in { animation: gl-fade-in .35s ease both; }
@keyframes gl-fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.animate-counter { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; } }

/* Toasts */
#gl-toast-region { position: fixed; top: 1.25rem; right: 1.25rem; z-index: 9999; display: flex; flex-direction: column; gap: .6rem; }
.gl-toast { min-width: 260px; max-width: 340px; background: #fff; border-radius: .75rem; box-shadow: 0 4px 12px rgba(16,24,40,0.08), 0 12px 32px rgba(16,24,40,0.12); border-left: 4px solid var(--gl-primary); padding: .8rem 1rem; font-size: .85rem; display: flex; align-items: flex-start; gap: .55rem; animation: gl-fade-in .25s ease both; }
.gl-toast.success { border-color: #10B981; }
.gl-toast.error { border-color: #EF4444; }

/* Responsive: table -> card */
@media (max-width: 640px) {
  .table-to-cards thead { display: none; }
  .table-to-cards tbody tr { display: block; margin-bottom: .75rem; border: 1px solid #E5E7EB; border-radius: .75rem; padding: .5rem; }
  .table-to-cards tbody td { display: flex; justify-content: space-between; gap: .75rem; padding: .4rem .5rem !important; text-align: right !important; }
  .table-to-cards tbody td::before { content: attr(data-label); font-weight: 600; color: #64748B; text-align: left; }
}

body.square { --gl-radius: 0; }
body.square [class*="rounded"]:not(.rounded-full),
body.square .btn,
body.square .btn-icon,
body.square .kpi-card,
body.square .kpi-card .kpi-icon,
body.square .gl-card,
body.square .table-wrap,
body.square .badge,
body.square .item-badge,
body.square .kpi-trend,
body.square .gl-toast,
body.square .skeleton,
body.square .gl-field input,
body.square .gl-field select,
body.square .gl-field textarea,
body.square .empty-state .empty-icon,
body.square #topnav .nav-link,
body.square #topnav .tn-toggle,
body.square #topnav .tn-logout { border-radius: 0; }