/* ============================================================
   MALA OS v2 — Layout System
   ============================================================ */

@import url('tokens.css');

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--navy-950);
  color: var(--text-primary);
  line-height: var(--leading-normal);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── App Shell ── */
.app {
  display: grid;
  grid-template-areas:
    "rail header"
    "rail main";
  grid-template-columns: var(--rail-width) 1fr;
  grid-template-rows: var(--header-height) 1fr;
  min-height: 100vh;
}

/* ── Left Rail (Icon Navigation) ── */
.rail {
  grid-area: rail;
  background: var(--surface-deep);
  border-right: 1px solid var(--surface-glass-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-4) 0;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--rail-width);
  z-index: var(--z-sticky);
}

.rail-brand {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--gold-500);
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: var(--weight-bold);
  color: var(--text-inverse);
  margin-bottom: var(--space-6);
  flex-shrink: 0;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
  width: 100%;
  align-items: center;
}

.rail-item {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  border: none;
  background: none;
}

.rail-item:hover {
  background: var(--surface-elevated);
  color: var(--text-secondary);
}

.rail-item.active {
  background: var(--gold-500);
  color: var(--text-inverse);
  box-shadow: var(--shadow-gold);
}

.rail-item .tooltip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface-elevated);
  border: 1px solid var(--surface-glass-border);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
}

.rail-item:hover .tooltip {
  opacity: 1;
}

.rail-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
}

/* ── Top Header ── */
.header {
  grid-area: header;
  background: var(--surface-deep);
  border-bottom: 1px solid var(--surface-glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.header-breadcrumb {
  font-family: var(--font-serif);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.header-breadcrumb span {
  color: var(--gold-500);
}

.header-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header-search {
  position: relative;
}

.header-search input {
  background: var(--surface-panel);
  border: 1px solid var(--surface-glass-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-4) var(--space-2) 36px;
  color: var(--text-primary);
  font-size: var(--text-sm);
  width: 240px;
  transition: all var(--transition-base);
  outline: none;
}

.header-search input::placeholder {
  color: var(--text-muted);
}

.header-search input:focus {
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px var(--gold-glow);
  width: 300px;
}

.header-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.header-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--surface-panel);
  border: 1px solid var(--surface-glass-border);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
}

.header-btn:hover {
  background: var(--surface-elevated);
  color: var(--text-primary);
}

.header-btn .badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: var(--weight-bold);
  display: grid;
  place-items: center;
  border: 2px solid var(--surface-deep);
}

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--gold-500);
  display: grid;
  place-items: center;
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  color: var(--text-inverse);
  cursor: pointer;
  border: 2px solid var(--surface-glass-border);
}

/* ── Main Content Area ── */
.main {
  grid-area: main;
  padding: var(--space-6);
  overflow-y: auto;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(201, 162, 39, 0.04), transparent),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(30, 58, 95, 0.3), transparent),
    var(--navy-950);
  min-height: calc(100vh - var(--header-height));
}

.main-inner {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ── Section Header ── */
.section-header {
  margin-bottom: var(--space-6);
  animation: fadeIn 0.4s ease;
}

.section-header h1 {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.section-header p {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

/* ── Page transition ── */
.view {
  display: none;
  animation: fadeIn 0.35s ease;
}

.view.active {
  display: block;
}

/* ── Smooth Theme Transitions ── */
html, body, .rail, .header, .main, .panel, .kpi-card, .yacht-card,
.header-search input, .header-btn, .btn, .chip, .data-table td,
.data-table th, .modal-box, .quick-action, .audit-card {
  transition: background-color var(--transition-slow),
              color var(--transition-slow),
              border-color var(--transition-slow),
              box-shadow var(--transition-slow);
}

/* ── Keyboard Shortcuts Overlay ── */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 13, 24, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  z-index: var(--z-modal);
}

.shortcuts-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.shortcuts-box {
  background: var(--surface-panel);
  border: 1px solid var(--surface-glass-border);
  border-radius: var(--radius-2xl);
  width: min(520px, 95vw);
  max-height: 80vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
}

.shortcuts-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.shortcuts-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--surface-elevated);
  border: 1px solid var(--surface-glass-border);
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.shortcuts-grid {
  display: grid;
  gap: var(--space-3);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--surface-glass-border);
}

.shortcut-row:last-child {
  border-bottom: none;
}

.shortcut-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.shortcut-keys {
  display: flex;
  gap: var(--space-1);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 var(--space-2);
  background: var(--surface-elevated);
  border: 1px solid var(--surface-glass-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  box-shadow: 0 1px 0 var(--surface-glass-border);
}

/* ── Sync Pulse Animation ── */
@keyframes sync-pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.5); }
  100% { opacity: 0; transform: scale(2); }
}

.sync-pulse-ring {
  position: absolute;
  inset: -4px;
  border-radius: var(--radius-full);
  border: 2px solid var(--success);
  animation: sync-pulse 2s ease-out infinite;
  pointer-events: none;
}

.sync-pulse-ring:nth-child(2) {
  animation-delay: 0.6s;
}

.sync-pulse-ring:nth-child(3) {
  animation-delay: 1.2s;
}
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--navy-600);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--navy-500);
}
