/*
 * Parallax Workspace — Layout & Components
 * All colors reference CSS custom properties from the theme file.
 */

/* ── Reset ──────────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background: var(--bg-body);
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--accent-hover); }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  transition: border-color var(--transition);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--border-focus);
}

code, pre {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
}

pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Layout shell ───────────────────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar-brand {
  padding: 1.25rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-text);
  font-weight: 700;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
}

.brand-text {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: all var(--transition);
  min-height: 44px;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.nav-link.active {
  background: var(--accent-muted);
  color: var(--accent);
}
.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}
.nav-link.active svg { opacity: 1; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  font-weight: 600;
}

.logout-link {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.logout-link:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

/* ── Main content area ──────────────────────────────────────────────────── */

.content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-body);
  position: sticky;
  top: 0;
  z-index: 50;
}

.content-header h1 {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.content-body {
  flex: 1;
  padding: 1.5rem;
}

.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.menu-toggle:hover { background: var(--bg-hover); }
.menu-toggle svg { width: 22px; height: 22px; }

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card-header {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

/* ── Stat grid (dashboard) ──────────────────────────────────────────────── */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.stat-value.status-ok {
  color: var(--success);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: var(--font-size-sm);
  transition: all var(--transition);
  min-height: 44px;
  border: 1px solid transparent;
}

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

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

.btn-ghost {
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: var(--font-size-xs);
  min-height: 32px;
}

.btn-danger {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error);
}
.btn-danger:hover {
  background: var(--error);
  color: var(--text-inverse);
}

/* ── File browser ───────────────────────────────────────────────────────── */

.file-browser {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  height: calc(100vh - 130px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-tree-panel {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.5rem 0;
}

.file-content-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-content-header {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  gap: 0.5rem;
  flex-wrap: wrap;
}

.file-path {
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-actions {
  display: flex;
  gap: 0.375rem;
  flex-shrink: 0;
}

.file-content-body {
  flex: 1;
  overflow: auto;
  padding: 1rem;
}

.file-content-body pre {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font-size: var(--font-size-sm);
  line-height: 1.7;
}

.file-editor {
  width: 100%;
  height: 100%;
  resize: none;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.7;
  background: var(--bg-body);
  border: none;
  border-radius: 0;
  padding: 1rem;
  color: var(--text-primary);
}
.file-editor:focus { border-color: transparent; }

.file-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: var(--font-size-base);
}

/* Tree items */
.tree-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.3125rem 0.75rem;
  padding-left: calc(0.75rem + var(--depth, 0) * 1.125rem);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  transition: all var(--transition);
  min-height: 32px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.tree-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.tree-item.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.tree-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.6;
}
.tree-item.active .tree-icon { opacity: 1; }

.tree-toggle {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform var(--transition);
  opacity: 0.4;
}
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.hidden { visibility: hidden; }

.tree-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-children {
  display: none;
}
.tree-children.open {
  display: block;
}

/* ── Journal ────────────────────────────────────────────────────────────── */

.journal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.month-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.month-selector select {
  min-width: 160px;
  min-height: 44px;
}

.journal-compose {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.journal-compose-header {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.journal-textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.journal-compose-actions {
  display: flex;
  justify-content: flex-end;
}

.journal-entries {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.journal-entry {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.journal-entry-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--accent);
  font-weight: 500;
}

.journal-entry-body {
  padding: 1.25rem;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ── Login page ─────────────────────────────────────────────────────────── */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg-body);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  margin-bottom: 2rem;
}

.login-brand .brand-icon {
  width: 36px;
  height: 36px;
  font-size: var(--font-size-base);
}

.login-brand .brand-text {
  font-size: var(--font-size-xl);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

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

.form-input {
  width: 100%;
  min-height: 44px;
  padding: 0.625rem 0.875rem;
}

.login-submit {
  margin-top: 0.5rem;
}

.login-error {
  background: var(--error-bg);
  color: var(--error);
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  text-align: center;
}

/* ── Toast notifications ────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
  width: 100%;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-lg);
  animation: toast-in 300ms ease forwards;
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.toast.fade-out {
  animation: toast-out 300ms ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

/* ── Utility ────────────────────────────────────────────────────────────── */

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Mobile tab bar ─────────────────────────────────────────────────────── */

.mobile-tabs {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-bar-height);
  background: var(--sidebar-bg);
  border-top: 1px solid var(--sidebar-border);
  z-index: 100;
}

.mobile-tabs .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  text-decoration: none;
  min-height: var(--tab-bar-height);
  transition: color var(--transition);
}
.mobile-tabs .tab:hover { color: var(--text-secondary); }
.mobile-tabs .tab.active { color: var(--accent); }
.mobile-tabs .tab svg {
  width: 20px;
  height: 20px;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .content {
    margin-left: 0;
    padding-bottom: var(--tab-bar-height);
  }

  .menu-toggle {
    display: flex;
  }

  .mobile-tabs {
    display: flex;
  }

  /* File browser: single panel mode */
  .file-browser {
    grid-template-columns: 1fr;
    height: calc(100vh - 130px - var(--tab-bar-height));
  }

  .file-tree-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .file-browser.show-content .file-tree-panel {
    display: none;
  }
  .file-browser.show-tree .file-content-panel {
    display: none;
  }

  .content-body {
    padding: 1rem;
  }

  .stat-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 2rem 1.5rem;
  }

  .journal-header {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ── Sidebar overlay for mobile ─────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}
.sidebar-overlay.visible {
  display: block;
}
