/* WrytaEngine — Three-Column Layout */
/* Dark writer's console theme */

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #16162a;
  --bg-tertiary: #1e1e38;
  --bg-hover: #28284a;
  --bg-active: #32325c;
  --border-color: #2a2a4a;
  --border-light: #3a3a5a;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0c0;
  --text-muted: #6a6a8a;
  --accent-primary: #5b9bd5;
  --accent-hover: #7ab5e8;
  --accent-dim: #3a6a9a;
  --success: #4caf84;
  --warning: #d4a843;
  --danger: #d44a5a;
  --sidebar-width-left: 300px;
  --sidebar-width-right: 320px;
  --header-height: 0px;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-serif: 'Crimson Text', 'Georgia', 'Times New Roman', serif;
  --font-script: 'Dancing Script', 'Segoe Script', 'Brush Script MT', cursive;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* App Shell */
#app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  overflow: hidden;
}

/* Left Sidebar */
#sidebar-left {
  width: var(--sidebar-width-left);
  min-width: var(--sidebar-width-left);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-header .logo {
  font-family: var(--font-script);
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: 0;
  line-height: 1;
}

.sidebar-header .logo .logo-gold {
  color: var(--warning);
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
}

.sidebar-header .logo-tagline {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  line-height: 1.2;
}

.sidebar-header .logo-icon {
  font-size: 1.5rem;
}

.sidebar-header .logo-img {
  height: 120px;
  width: auto;
  border-radius: var(--radius-sm);
  padding: 2px;
  display: block;
  object-fit: contain;
}
.sidebar-header .logo-img-light {
  background: #ffffff;
}
.sidebar-header .logo-img-dark {
  background: transparent;
  display: none;
}
html[data-theme="dark"] .sidebar-header .logo-img-light { display: none; }
html[data-theme="dark"] .sidebar-header .logo-img-dark { display: block; }

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-y: overlay;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 4px;
  font-weight: 600;
}

/* Main Panel */
#main-panel {
  flex: 1;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.main-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-y: overlay;
  -webkit-overflow-scrolling: touch;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Right Sidebar */
#sidebar-right {
  width: var(--sidebar-width-right);
  min-width: var(--sidebar-width-right);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: row;   /* content column + vertical tab rail (rail on the far right edge) */
  overflow: hidden;
}

/* ============================================ */
/* MOBILE NAV TOGGLE (legacy floating button)   */
/* ============================================ */

.mobile-nav-toggle {
  display: none;
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  right: calc(20px + env(safe-area-inset-right, 0px));
  z-index: 200;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  font-size: 1.4rem;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: background var(--transition-fast);
  border: none;
  cursor: pointer;
}

.mobile-nav-toggle:hover {
  background: var(--accent-hover);
}

/* ============================================ */
/* RESPONSIVE BREAKPOINTS                       */
/* ============================================ */

/* Medium: Right sidebar becomes overlay */
@media (max-width: 1100px) {
  #sidebar-right {
    position: fixed;
    right: 0;
    top: 0;
    z-index: 100;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
  }

  #sidebar-right.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  #sidebar-left {
    width: 260px;
    min-width: 260px;
  }
}

/* Tablet/Mobile: Left sidebar becomes full-width overlay */
@media (max-width: 768px) {
  #sidebar-left {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    width: 100vw;
    width: 100dvw;
    min-width: 100vw;
    min-width: 100dvw;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    height: 100vh;
    height: 100dvh;
  }

  #sidebar-left.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  #sidebar-right {
    position: fixed;
    right: 0;
    top: 0;
    z-index: 100;
    width: 100vw;
    width: 100dvw;
    min-width: 100vw;
    min-width: 100dvw;
    height: 100vh;
    height: 100dvh;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
  }

  #sidebar-right.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  #main-panel {
    width: 100%;
  }

  .mobile-nav-toggle {
    display: flex !important;
  }

  .main-content {
    padding: 12px 14px;
  }

  .main-toolbar {
    padding: 10px 14px;
  }
}

/* Small phone breakpoint — sidebars remain full-width overlays */
@media (max-width: 480px) {
  .main-content {
    padding: 10px 12px;
    gap: 12px;
  }

  .main-toolbar {
    padding: 8px 12px;
    font-size: 0.8rem;
  }
}

/* ============================================ */
/* MODAL OVERLAY                                */
/* ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  backdrop-filter: blur(2px);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: min(400px, 92vw);
  max-width: 600px;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 480px) {
  .modal {
    padding: 16px;
    min-width: 92vw;
    max-height: 90vh;
    max-height: 90dvh;
  }

  .modal h3 {
    font-size: 1rem;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
  }
}

.modal h3 {
  margin-bottom: 16px;
  color: var(--text-primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ============================================ */
/* TOAST NOTIFICATIONS                          */
/* ============================================ */

#toast-container {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 300ms ease;
  max-width: min(360px, 90vw);
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--accent-primary); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(50px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================ */
/* MOBILE BOTTOM TAB BAR                        */
/* ============================================ */

#mobile-tab-bar {
  display: none;
}

@media (max-width: 768px) {
  #mobile-tab-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 250;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 6px;
  }

  .mobile-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    height: 50px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition-fast);
    font-family: var(--font-sans);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }

  .mobile-tab .tab-icon {
    font-size: 1.3rem;
    line-height: 1;
  }

  .mobile-tab.active {
    color: var(--accent-primary);
  }

  .mobile-tab:active {
    color: var(--accent-hover);
  }

  /* Push main panel up to not be hidden behind tab bar */
  #main-panel {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  /* Prevent sidebars from overlapping tab bar */
  #sidebar-left {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  #sidebar-right {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }
}