/* Application UI Styles - Not for markdown content typography */
@import url('https://fonts.googleapis.com/css2?family=Karla:wght@400;500;600;700&display=swap');

:root,
[data-theme="light"] {
  --bg-primary: #fafaf8;
  --bg-secondary: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: rgba(0, 0, 0, 0.6);
  --border-color: rgba(0, 0, 0, 0.1);
  --accent-color: #1a1a1a;
  --hover-bg: rgba(0, 0, 0, 0.05);
  
  /* Typography System (6 variations) */
  --font-ui: "Karla", -apple-system, BlinkMacSystemFont, sans-serif;
  --text-sm: 0.6875rem;   /* 11px - type labels */
  --text-md: 0.8125rem;   /* 13px - header, buttons, breadcrumb, meta */
  --text-lg: 1rem;        /* 16px - filename */

  /* UI font sizes (used across app, modals, editor, code-viewer) */
  --ui-font-xs: 0.625rem;   /* 10px - mobile meta */
  --ui-font-sm: 0.8125rem;  /* 13px - descriptions, footer, meta */
  --ui-font-md: 0.875rem;   /* 14px - button text, labels */
  --ui-font-lg: 1.125rem;   /* 18px - search input */
  --ui-font-xl: 1.25rem;    /* 20px - modal headings */
  
  /* Directory listing colors */
  --color-filename: #1a1a1a;
  --color-type-label: #666;
  --color-meta: #888;
  --color-separator: #ccc;
}

[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #1e1e1e;
  --text-primary: #eee;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --border-color: rgba(255, 255, 255, 0.1);
  --accent-color: #eee;
  --hover-bg: rgba(255, 255, 255, 0.05);
  
  /* Directory listing colors (dark) */
  --color-filename: #eee;
  --color-type-label: #888;
  --color-meta: #666;
  --color-separator: #444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 !important;
  padding: 0;
  font-family: var(--font-ui);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: var(--font-size-base, 18px);
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.375rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* Header inner container for aligned edges */
.header-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

/* Header layout: left group, middle (flexible), right group */
.header-inner>*:first-child:not(.controls):not(h1) {
  /* Back button or first element */
  flex-shrink: 0;
}

.header-inner h1 {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.viewer-title-block {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  max-height: 1.875rem;
}

.viewer-meta {
  margin: 0.25rem 0 0;
  font-size: var(--ui-font-sm);
  color: var(--text-secondary);
  font-weight: 400;
}

.header-inner .controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}

/* Header button groups */
header .controls>*:not(:last-child) {
  margin-right: 0;
}

/* Group action buttons together visually */
header #back-btn {
  margin-right: 0.5rem;
}

header #edit-btn,
header #export-pdf-btn,
header #save-btn,
header #save-as-btn {
  margin-right: 0.25rem;
}

/* ============================================
   Responsive Breakpoints
   ============================================
   Mobile: < 600px (Pixel 7 Pro, phones)
   Tablet: 600px - 1024px (Android tablets)
   Desktop: > 1024px (MacBooks)
   ============================================ */

/* Mobile (phones like Pixel 7 Pro) */
@media (max-width: 599px) {
  header {
    padding: 0.625rem 0.75rem;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-height: auto;
  }

  header h1 {
    font-size: 1rem;
    /* Mobile title size */
    max-width: 50%;
    order: 2;
    width: 100%;
    margin-top: 0.25rem;
  }

  header #back-btn {
    order: 1;
  }

  header .controls {
    order: 3;
    gap: 0.25rem;
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
    margin-top: 0.25rem;
  }

  header .controls button {
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    height: 2rem;
  }

  #theme-toggle,
  #font-decrease,
  #font-increase {
    width: 2rem;
    height: 2rem;
  }

  #font-size-display {
    min-width: 2.25rem;
    font-size: var(--ui-font-sm);
  }

  main {
    padding: 1rem 0.75rem;
  }

  #wrapper {
    padding: 1.5rem 1rem;
  }

  .directory-item {
    padding: 0.875rem 1rem;
    min-height: 3rem;
  }

  .directory-item .name {
    font-size: var(--ui-font-md);
  }

  .directory-item .meta {
    font-size: var(--ui-font-xs);
    margin-left: 0.5rem;
  }

  .split-container {
    flex-direction: column;
    height: auto;
    min-height: 400px;
  }

  .split-pane {
    min-height: 300px;
  }
}

/* Tablet (Android tablets - vertical and horizontal) */
@media (min-width: 600px) and (max-width: 1024px) {
  header {
    padding: 0.75rem 1.25rem;
    gap: 0.75rem;
  }

  header h1 {
    font-size: 1.125rem;
    /* Tablet title size */
    max-width: 45%;
  }

  header .controls {
    gap: 0.375rem;
  }

  header .controls button {
    padding: 0.45rem 0.875rem;
    font-size: 0.875rem;
  }

  main {
    padding: 1.5rem 1.25rem;
  }

  #wrapper {
    padding: 1.75rem 1.5rem;
  }

  main>*,
  #directory-content,
  #content-area,
  #wrapper,
  #breadcrumb,
  #sort-controls {
    max-width: 900px;
    /* Slightly narrower on tablets */
  }

  .directory-item {
    padding: 0.9375rem 1.125rem;
  }
}

/* Desktop (MacBooks 13" and 14") */
@media (min-width: 1025px) {
  header {
    padding: 0.375rem 2rem;
  }

  header h1 {
    font-size: 1.375rem;
  }

  main {
    padding: 2rem;
  }

  #wrapper {
    padding: 2rem;
  }

  main>*,
  #directory-content,
  #content-area,
  #wrapper,
  #breadcrumb,
  #sort-controls {
    max-width: 1250px;
    /* Increased for wider laptop view */
  }
}

/* Large desktop (if needed) */
@media (min-width: 1440px) {

  main>*,
  #directory-content,
  #content-area,
  #wrapper,
  #breadcrumb,
  #sort-controls {
    max-width: 1500px;
    /* Significantly wider on very large screens */
  }
}

/* Buttons */
button,
.upload-btn {
  font-family: var(--font-ui);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: var(--text-md);
  font-weight: 600;
  transition: background-color 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
  height: 1.875rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover,
.upload-btn:hover {
  background-color: var(--hover-bg);
}

button:active,
.upload-btn:active {
  opacity: 0.8;
}

button.active,
.upload-btn.active {
  background-color: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

[data-theme="dark"] header button:not(.primary):not(.active) {
  background-color: #2a2a2a;
  border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] button.active,
[data-theme="dark"] .upload-btn.active {
  color: #1a1a1a;
}

button.primary {
  background-color: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  font-weight: 500;
}

[data-theme="dark"] button.primary {
  color: #1a1a1a;
}

button.primary:hover {
  background-color: var(--accent-color);
  opacity: 0.9;
}

#delete-btn {
  color: #c0392b;
  border-color: rgba(192, 57, 43, 0.3);
}

#delete-btn:hover {
  background-color: rgba(192, 57, 43, 0.1);
  border-color: #c0392b;
}

#theme-toggle {
  font-size: 1.1rem;
  padding: 0.375rem;
  width: 1.875rem;
  /* Match button height */
  height: 1.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

#font-decrease,
#font-increase {
  width: 1.875rem;
  /* Match button height */
  height: 1.875rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: bold;
}

#font-size-display {
  min-width: 3rem;
  text-align: center;
  font-size: var(--ui-font-md);
  /* Consistent with button text */
  font-weight: 500;
  color: var(--text-primary);
}

/* Main content */
main {
  flex: 1;
  padding: 2rem;
  max-width: 100%;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
}

/* Content container with max-width for readability */
main>* {
  width: 100%;
  max-width: 1000px;
  /* Optimal for MacBooks and tablets */
  margin-left: auto;
  margin-right: auto;
}

/* Vertical rhythm: consistent spacing between main sections */
main>*+* {
  margin-top: 1.5rem;
}

/* Directory listing and viewer content */
#directory-content,
#content-area,
#wrapper {
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
}

/* Breadcrumb and sort controls */
#breadcrumb,
#sort-controls {
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
}

/* Breadcrumb */
#breadcrumb {
  font-size: var(--text-md);
  font-weight: 500;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#breadcrumb a {
  color: var(--accent-color);
  text-decoration: none;
  margin-right: 0.5rem;
}

#breadcrumb a:hover {
  text-decoration: underline;
}

#breadcrumb span {
  color: var(--text-secondary);
  margin: 0 0.5rem;
}

/* Sort controls */
#sort-controls {
  margin-bottom: 1rem;
  display: flex;
  gap: 0.5rem;
}

/* Directory listing */
#directory-content {
  display: flex;
  flex-direction: column;
}

/* ============================================
   LAYOUT X: Single-line cards with stacked meta
   ============================================ */
[data-layout="x"] #directory-content {
  gap: 0.5rem;
}

[data-layout="x"] .directory-item {
  display: flex;
  align-items: center;
  padding: 0.875rem 1.25rem;
  background-color: var(--bg-secondary);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-primary);
  transition: box-shadow 0.15s, transform 0.15s;
  cursor: pointer;
  gap: 1rem;
  min-height: 3.5rem;
}

[data-layout="x"] .directory-item:hover {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

[data-layout="x"] .directory-item .item-type {
  flex-shrink: 0;
  width: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-layout="x"] .directory-item .item-name {
  flex: 1;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-filename);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

[data-layout="x"] .directory-item .item-meta {
  display: flex;
  gap: 1rem;
  margin-left: auto;
  flex-shrink: 0;
}

[data-layout="x"] .directory-item .meta-col {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

[data-layout="x"] .directory-item .meta-col-right {
  text-align: right;
}

[data-layout="x"] .directory-item .meta-line {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-meta);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

[data-layout="x"] .directory-item .meta-line:empty {
  display: none;
}

/* ============================================
   LAYOUT Y: Two-line list
   ============================================ */
[data-layout="y"] #directory-content {
  gap: 0;
}

[data-layout="y"] .directory-item {
  display: flex;
  align-items: flex-start;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--text-primary);
  transition: background 0.15s;
  cursor: pointer;
  gap: 0.75rem;
}

[data-layout="y"] .directory-item:first-child {
  border-top: 1px solid var(--border-color);
}

[data-layout="y"] .directory-item:hover {
  background: var(--hover-bg);
  margin: 0 -1.5rem;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

[data-layout="y"] .directory-item .item-type {
  width: 2.75rem;
  flex-shrink: 0;
  padding-top: 0.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-layout="y"] .directory-item .item-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}

[data-layout="y"] .directory-item .item-name {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-filename);
  letter-spacing: -0.01em;
}

[data-layout="y"] .directory-item .item-meta-row {
  display: flex;
  align-items: center;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-meta);
  gap: 0.5rem;
}

[data-layout="y"] .directory-item .item-meta-row span {
  font-variant-numeric: tabular-nums;
}

[data-layout="y"] .directory-item .item-meta-row .sep {
  color: var(--color-separator);
}

/* File Type Icons */
.type-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.type-text {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-type-label);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 1;
}

.type-folder { color: #d4a843; }
.type-md     { color: #0969da; }
.type-js     { color: #d4a017; }
.type-pdf    { color: #cb3837; }
.type-css    { color: #5b7bd5; }
.type-html   { color: #e06030; }

[data-theme="dark"] .type-folder { color: #e0bc5a; }
[data-theme="dark"] .type-md     { color: #6199f5; }
[data-theme="dark"] .type-js     { color: #e8c844; }
[data-theme="dark"] .type-pdf    { color: #e06060; }
[data-theme="dark"] .type-css    { color: #7b9bef; }
[data-theme="dark"] .type-html   { color: #ef8050; }

/* Tier 5: Lock badge on directory items */
.lock-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  color: #d97706;
  opacity: 0.85;
  pointer-events: none;
  line-height: 1;
}

[data-theme="dark"] .lock-badge {
  color: #fbbf24;
}

/* Tier 5: Viewer edit button lock indicator */
.edit-btn-locked {
  opacity: 0.7;
}

.edit-lock-icon {
  color: #d97706;
  vertical-align: middle;
  margin-left: 2px;
}

[data-theme="dark"] .edit-lock-icon {
  color: #fbbf24;
}

/* Separator dots */
.item-stats .sep,
.item-row-2 .sep {
  color: var(--color-separator);
  margin: 0 0.5rem;
}

/* Default layout (fallback to X) */
#directory-content:not([data-layout]) .directory-item {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  background-color: var(--bg-secondary);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-primary);
  cursor: pointer;
}

/* Viewer */
#content-area {
  width: 100%;
  padding: 0;
}

#wrapper {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 2rem;
}

#loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
}

.toast {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  animation: slideIn 0.3s ease-out;
  min-width: 300px;
}

.toast.success {
  border-left: 4px solid #28a745;
}

.toast.error {
  border-left: 4px solid #dc3545;
}

.toast.warning {
  border-left: 4px solid #ffc107;
}

.toast.info {
  border-left: 4px solid #17a2b8;
}

.toast .toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.toast.success .toast-icon {
  color: #28a745;
}

.toast.error .toast-icon {
  color: #dc3545;
}

.toast.warning .toast-icon {
  color: #ffc107;
}

.toast.info .toast-icon {
  color: #17a2b8;
}

.toast .toast-content {
  flex: 1;
}

.toast .toast-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  font-size: var(--ui-font-md);
  /* Consistent with body text */
}

.toast .toast-message {
  font-size: var(--ui-font-md);
  /* Consistent typography */
  color: var(--text-secondary);
  line-height: 1.4;
}

.toast .toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.toast .toast-close:hover {
  opacity: 1;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.fade-out {
  animation: slideOut 0.3s ease-in forwards;
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }

  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

