/* UI components */

/* ── Buttons ── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: 600;
    line-height: 1.4;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-base);
}

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

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

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

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

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.btn-success:hover { filter: brightness(1.08); color: #fff; }

.btn-warning {
    background: var(--warning);
    color: var(--text);
    border-color: var(--warning);
}

.btn-warning:hover { filter: brightness(1.05); color: var(--text); }

.btn-info {
    background: var(--info);
    color: #fff;
    border-color: var(--info);
}

.btn-info:hover { filter: brightness(1.08); color: #fff; }

.btn-light {
    background: var(--surface-raised);
    color: var(--text);
    border-color: var(--border);
}

.btn-light:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-outline-primary {
    background: transparent;
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary-muted);
    color: var(--primary);
}

.btn-outline-secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-outline-secondary:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.btn-outline-light {
    background: transparent;
    color: #fff;
    border-color: rgba(255, 255, 255, 0.5);
}

.btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-block { width: 100%; }

.btn-close {
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    position: relative;
    opacity: 0.7;
    flex-shrink: 0;
}

.btn-close::before,
.btn-close::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
}

.btn-close::before { transform: translate(-50%, -50%) rotate(45deg); }
.btn-close::after { transform: translate(-50%, -50%) rotate(-45deg); }

.btn-close:hover { opacity: 1; background: var(--surface-hover); }

.theme-toggle {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: var(--surface-raised);
    transition: all var(--transition);
}

.theme-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* ── Cards ── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-body { padding: var(--space-4); }

.card-header {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-subtle);
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
    font-weight: 600;
}

.card-title {
    font-size: var(--text-md);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.card-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.stat-card {
    border-left: 3px solid var(--border);
}

.stat-card.stat-primary { border-left-color: var(--primary); }
.stat-card.stat-success { border-left-color: var(--success); }
.stat-card.stat-warning { border-left-color: var(--warning); }
.stat-card.stat-info { border-left-color: var(--info); }

.stat-card .stat-label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: var(--space-1);
}

.stat-card .stat-value {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text);
}

/* ── Forms ── */

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    margin-bottom: var(--space-1);
    color: var(--text);
}

.form-control,
.form-select {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

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

.form-control::placeholder { color: var(--text-muted); }

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

.form-text {
    display: block;
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.form-check-input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.img-thumbnail {
    padding: var(--space-1);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-width: 100%;
}

/* ── Alerts ── */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    border: 1px solid transparent;
    margin-bottom: var(--space-3);
}

.alert-success {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.3);
    color: var(--success);
}

.alert-danger,
.alert-error {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.3);
    color: var(--danger);
}

.alert-warning {
    background: rgba(251, 191, 36, 0.12);
    border-color: rgba(251, 191, 36, 0.3);
    color: var(--warning);
}

.alert-info {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.3);
    color: var(--info);
}

.alert-dismissible { padding-right: var(--space-8); position: relative; }
.alert-dismissible .btn-close {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
}

/* ── Badges ── */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15em 0.55em;
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: var(--radius-sm);
    line-height: 1.4;
}

.bg-success.badge, .badge.bg-success { background: rgba(52, 211, 153, 0.15) !important; color: var(--success) !important; }
.bg-warning.badge, .badge.bg-warning { background: rgba(251, 191, 36, 0.15) !important; color: var(--warning) !important; }
.bg-danger.badge, .badge.bg-danger { background: rgba(248, 113, 113, 0.15) !important; color: var(--danger) !important; }
.bg-info.badge, .badge.bg-info { background: rgba(56, 189, 248, 0.15) !important; color: var(--info) !important; }
.bg-secondary.badge, .badge.bg-secondary { background: var(--surface-hover) !important; color: var(--text-secondary) !important; }
.bg-primary.badge, .badge.bg-primary { background: var(--primary-muted) !important; color: var(--primary) !important; }

/* ── Tables ── */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.table th,
.table td {
    padding: var(--space-2) var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: middle;
}

.table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--bg-subtle);
}

.table-hover tbody tr:hover {
    background: var(--surface-hover);
}

.table-striped tbody tr:nth-child(even) {
    background: var(--bg-subtle);
}

/* ── Tabs ── */

.nav-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-3);
    border-bottom: 1px solid var(--border);
}

.nav-tabs .nav-item { list-style: none; }

.nav-tabs .nav-link {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: -1px;
}

.nav-tabs .nav-link:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.nav-tabs .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: var(--primary-muted);
}

.tab-content { margin-top: var(--space-3); }

.tab-pane { display: none; }
.tab-pane.active,
.tab-pane.show.active { display: block; }

/* ── Accordion ── */

.accordion { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }

.accordion-item {
    border-bottom: 1px solid var(--border);
}

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

.accordion-header { margin: 0; }

.accordion-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: 600;
    text-align: left;
    background: var(--surface);
    color: var(--text);
    border: none;
    cursor: pointer;
    transition: background var(--transition);
}

.accordion-button::after {
    content: '+';
    font-size: var(--text-md);
    color: var(--text-muted);
    transition: transform var(--transition);
}

.accordion-button:not(.collapsed)::after {
    content: '−';
}

.accordion-button:hover { background: var(--surface-hover); }

.accordion-button:not(.collapsed) {
    background: var(--primary-muted);
    color: var(--primary);
}

.accordion-collapse { display: none; }
.accordion-collapse.show { display: block; }

.accordion-body {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    background: var(--bg-subtle);
    border-top: 1px solid var(--border-subtle);
}

/* ── Modals ── */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-slow);
}

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

.modal {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

.modal.show {
    display: flex;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-dialog {
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - var(--space-8));
    overflow-y: auto;
}

.modal-dialog.modal-lg { max-width: 720px; }

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

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

.modal-title {
    font-size: var(--text-md);
    font-weight: 600;
    margin: 0;
}

.modal-body { padding: var(--space-4); }

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
}

/* ── Icon circles ── */

.icon-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.icon-circle-sm { width: 40px; height: 40px; font-size: var(--text-sm); }
.icon-circle-md { width: 48px; height: 48px; font-size: var(--text-md); }
.icon-circle-lg { width: 64px; height: 64px; font-size: var(--text-lg); }
.icon-circle-xl { width: 80px; height: 80px; font-size: var(--text-xl); }

.icon-circle.bg-primary { background: var(--primary); color: var(--primary-text); }
.icon-circle.bg-success { background: var(--success); color: #fff; }
.icon-circle.bg-info { background: var(--info); color: #fff; }
.icon-circle.bg-warning { background: var(--warning); color: var(--text); }
.icon-circle.bg-danger { background: var(--danger); color: #fff; }
.icon-circle.bg-secondary { background: var(--secondary); color: #fff; }

/* ── Cirrus ERP Logo ── */

.cirrus-logo {
  display: inline-flex;
  align-items: center;
  width: auto;
  height: 48px;
  max-height: 48px;
  position: relative;
  z-index: 1;
}

.cirrus-logo svg {
  width: auto;
  height: 100%;
  display: block;
}

.cirrus-logo-hex {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cirrus-logo-dot {
  fill: var(--primary);
}

.cirrus-logo-connector {
  stroke: var(--primary);
  stroke-width: 3;
}

.cirrus-logo-brand {
  font-weight: 800;
  letter-spacing: 12px;
  fill: var(--text);
  font-family: var(--font-sans);
}

.cirrus-logo-tagline {
  font-weight: 600;
  letter-spacing: 2px;
  fill: var(--text-secondary);
  font-family: var(--font-sans);
}

/* ── Cirrus ERP Favicon ── */

.cirrus-favicon-hex {
  fill: none;
  stroke: var(--text-secondary);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cirrus-favicon-dot {
  fill: var(--primary);
}

/* ── Cirrus ERP Animated Logo ── */

.logo-animated-wrap {
  width: 360px;
  max-width: 90vw;
  margin: 0 auto;
}

.logo-animated-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

/* Overall lockup entrance */
#logo-lockup {
  transform-box: view-box;
  transform-origin: 50% 50%;
  animation: lockupIn 1.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes lockupIn {
  0%   { opacity: 0; transform: scale(0.94); }
  100% { opacity: 1; transform: scale(1); }
}

/* Hex draw-in */
.hex-draw {
  stroke-dasharray: var(--len, 2200);
  stroke-dashoffset: var(--len, 2200);
  filter: drop-shadow(0 0 0 rgba(0,0,0,0));
  animation: drawHex 1s cubic-bezier(0.65, 0, 0.35, 1) forwards, hexGlowFlash 1s ease-out forwards;
}

#hex1.hex-draw { animation-delay: 0s, 0s; }
#hex2.hex-draw { animation-delay: 0.15s, 0.15s; }
#hex3.hex-draw { animation-delay: 0.3s, 0.3s; }

@keyframes drawHex {
  from { stroke-dashoffset: var(--len, 2200); }
  to   { stroke-dashoffset: 0; }
}

@keyframes hexGlowFlash {
  0%   { filter: drop-shadow(0 0 0 transparent); }
  50%  { filter: drop-shadow(0 0 3px var(--primary)); }
  100% { filter: drop-shadow(0 0 0 transparent); }
}

/* Connector triangle draw-in */
.conn-draw {
  stroke-dasharray: var(--len, 200);
  stroke-dashoffset: var(--len, 200);
  animation: drawHex 0.5s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

#conn1.conn-draw { animation-delay: 1.55s; }
#conn2.conn-draw { animation-delay: 1.7s; }
#conn3.conn-draw { animation-delay: 1.85s; }

/* Dots pop-in */
.dot-pop {
  opacity: 0;
  transform: scale(0);
  transform-box: fill-box;
  transform-origin: 50% 50%;
  animation: dotPop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#dotT.dot-pop  { animation-delay: 1.1s; }
#dotB.dot-pop  { animation-delay: 1.22s; }
#dotRt.dot-pop { animation-delay: 1.34s; }

@keyframes dotPop {
  0%   { opacity: 0; transform: scale(0); }
  60%  { opacity: 1; transform: scale(1.25); }
  100% { opacity: 1; transform: scale(1); }
}

/* Tagline dash lines */
.dash-line {
  transform-box: fill-box;
  opacity: 0;
  animation: dashGrow 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

#dashLeft  { transform-origin: 100% 50%; animation-delay: 2.1s; }
#dashRight { transform-origin: 0% 50%;   animation-delay: 2.1s; }

@keyframes dashGrow {
  0%   { opacity: 0; transform: scaleX(0); }
  100% { opacity: 1; transform: scaleX(1); }
}

/* Text reveal */
#brandText {
  opacity: 0;
  animation: brandReveal 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: 1.95s;
}

@keyframes brandReveal {
  0%   { opacity: 0; letter-spacing: 40px; transform: translateY(8px); }
  100% { opacity: 1; letter-spacing: 12px; transform: translateY(0); }
}

#taglineText {
  opacity: 0;
  animation: taglineReveal 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: 2.25s;
}

@keyframes taglineReveal {
  0%   { opacity: 0; letter-spacing: 12px; }
  100% { opacity: 1; letter-spacing: 2px; }
}

/* Infinite ambient loop (starts after entrance) */
.hex-comet {
  fill: none;
  stroke: var(--primary);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}

.loop-on .hex-comet {
  animation: cometFade 0.6s ease-out both, cometTravel var(--travel-dur, 2.6s) linear infinite;
}

#hex1Comet.hex-comet { animation-delay: 0s, 0.6s; --travel-dur: 2.6s; }
#hex2Comet.hex-comet { animation-delay: 0.2s, 0.8s; --travel-dur: 2.9s; }
#hex3Comet.hex-comet { animation-delay: 0.4s, 1s; --travel-dur: 3.2s; }

@keyframes cometFade {
  from { opacity: 0; }
  to   { opacity: 0.9; }
}

@keyframes cometTravel {
  from { stroke-dashoffset: var(--len, 2200); }
  to   { stroke-dashoffset: var(--comet-end, -400); }
}

.pulse-dot {
  fill: var(--primary);
  opacity: 0;
  filter: drop-shadow(0 0 3px var(--primary));
}

.loop-on .pulse-dot {
  animation: pulseFade 0.6s ease-out 0.9s forwards, pulseTravel 3.6s linear 0.9s infinite;
}

@keyframes pulseFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes pulseTravel {
  0%   { offset-distance: 0%; }
  100% { offset-distance: 100%; }
}

.loop-on .cirrus-logo-dot-glow {
  animation: dotBreathe 2.6s ease-in-out infinite;
}

#dotTGlow.cirrus-logo-dot-glow  { animation-delay: 0s; }
#dotBGlow.cirrus-logo-dot-glow  { animation-delay: 0.5s; }
#dotRtGlow.cirrus-logo-dot-glow { animation-delay: 1s; }

@keyframes dotBreathe {
  0%, 100% { opacity: 0.25; transform: scale(1); }
  50%      { opacity: 0.65; transform: scale(1.35); }
}

.cirrus-logo-dot-glow {
  transform-box: fill-box;
  transform-origin: 50% 50%;
  opacity: 0;
  fill: var(--primary);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  #logo-lockup, .hex-draw, .conn-draw, .dot-pop, .dash-line, #brandText, #taglineText,
  .hex-comet, .pulse-dot, .cirrus-logo-dot-glow {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
    stroke-dashoffset: 0 !important;
    letter-spacing: normal !important;
  }
  .cirrus-logo-brand { letter-spacing: 12px !important; }
  .cirrus-logo-tagline { letter-spacing: 2px !important; }
}
