/* ============================================
   File    : app/css/layout.css
   Fungsi  : Layout utama — topbar, sidebar, editor, bottombar
   Letak   : lumennote/app/css/layout.css
   ============================================ */

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

/* ---------- BRAND (Lumen — gradasi terracotta) ---------- */
.brand {
  background: linear-gradient(135deg, #d4844d 0%, #c9764a 40%, #a85a35 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 700;
  letter-spacing: -0.03em;
}

[data-theme="dark"] .brand {
  background: linear-gradient(135deg, #f0a172 0%, #e08a5c 40%, #c9764a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------- TOPBAR ---------- */
.topbar {
  padding: calc(var(--safe-top) + 8px) 10px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
  min-height: 60px;
  flex-shrink: 0;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: var(--fs-md);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
  line-height: 1.1;
}

.topbar-title .brand {
  font-size: var(--fs-xl);
  display: block;
  line-height: 1.1;
}

.topbar-title small {
  display: block;
  font-weight: 500;
  font-size: 10px;
  color: var(--fg-3);
  margin-top: 4px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-family: var(--font-ui);
  line-height: 1;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 84%;
  max-width: 360px;
  background: var(--bg);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(-102%);
  transition: transform var(--dur-slow) var(--ease);
  box-shadow: var(--shadow-lg);
  border-right: 1px solid var(--border);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-head {
  padding: 22px 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-head h1 {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.sidebar-head h1 span {
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
  background: none;
}

.sidebar-tagline {
  font-size: 10px;
  color: var(--fg-3);
  padding: 0 20px 20px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 500;
  font-family: var(--font-ui);
  line-height: 1;
}

/* Search */
.search-wrap {
  padding: 0 12px 10px;
  position: relative;
  flex-shrink: 0;
}

.search-wrap svg {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--fg-3);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  outline: none;
  transition: border var(--dur-fast), background var(--dur-fast);
}

.search-wrap input:focus {
  border-color: var(--accent);
  background: var(--bg);
}

/* Filter chips */
.filters {
  display: flex;
  gap: 6px;
  padding: 0 12px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}

.filters::-webkit-scrollbar {
  display: none;
}

/* Notes list */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px calc(var(--safe-bottom) + 90px);
  -webkit-overflow-scrolling: touch;
}

/* Sidebar footer */
.sidebar-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px calc(var(--safe-bottom) + 10px);
  background: linear-gradient(transparent, var(--bg) 30%);
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-top: 1px solid var(--border);
}

.sidebar-foot-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  color: var(--fg-2);
  transition: background var(--dur-fast);
  cursor: pointer;
}

.sidebar-foot-item:hover,
.sidebar-foot-item:active {
  background: var(--bg-2);
  color: var(--fg);
}

.sidebar-foot-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--fg-3);
}

.sidebar-foot-item.donate {
  color: var(--accent);
}

.sidebar-foot-item.donate svg {
  color: var(--accent);
}

/* ---------- BACKDROP ---------- */
.backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow);
}

.backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- MAIN ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 18px calc(var(--safe-bottom) + 96px);
  -webkit-overflow-scrolling: touch;
  position: relative;
}

#editor {
  width: 100%;
  min-height: calc(100vh - 220px);
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-editor);
  font-size: var(--fs-md);
  line-height: 1.7;
  color: var(--fg);
  caret-color: var(--accent);
  letter-spacing: -0.01em;
  display: block;
}

#editor::placeholder {
  color: var(--fg-3);
  font-family: var(--font-ui);
}

/* Font size variants */
body[data-font="sm"] { --fs-md: 14px; }
body[data-font="base"] { --fs-md: 16px; }
body[data-font="lg"] { --fs-md: 18px; }
body[data-font="xl"] { --fs-md: 20px; }

/* Font family variants */
body[data-fontfamily="sans"] { --font-editor: var(--font-ui); }
body[data-fontfamily="serif"] { --font-editor: Georgia, 'Times New Roman', serif; }
body[data-fontfamily="mono"] { --font-editor: var(--font-mono); }

/* Line height variants */
body[data-lineheight="tight"] #editor { line-height: 1.4; }
body[data-lineheight="normal"] #editor { line-height: 1.7; }
body[data-lineheight="relaxed"] #editor { line-height: 2; }

/* Editor width variants */
body[data-width="normal"] .editor-body { padding-left: 18px; padding-right: 18px; }
body[data-width="wide"] .editor-body { padding-left: 12px; padding-right: 12px; }

/* Empty state */
.empty-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  color: var(--fg-3);
  gap: 6px;
}

.empty-main .logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--accent);
}

.empty-main h2 {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.empty-main p {
  font-size: var(--fs-sm);
  max-width: 280px;
}

/* Status bar */
.statusbar {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 76px);
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--fs-xs);
  color: var(--fg-3);
  pointer-events: none;
  z-index: 14;
  background: var(--bg);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  opacity: 0.9;
}

/* Bottom bar */
.bottombar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  display: flex;
  gap: 6px;
  align-items: center;
  background: linear-gradient(transparent, var(--bg) 30%);
  pointer-events: none;
  z-index: 15;
}

.bottombar > * {
  pointer-events: auto;
}

.fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e08a5c 0%, #c9764a 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(201, 118, 74, 0.4);
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
  flex-shrink: 0;
  margin-left: auto;
}

.fab:active {
  transform: scale(0.92);
  box-shadow: 0 3px 10px rgba(201, 118, 74, 0.5);
}

.fab svg {
  width: 22px;
  height: 22px;
}

/* ============================================
   DESKTOP LAYOUT — CSS Grid, 2 kolom rapi
   ============================================ */
@media (min-width: 720px) {
  body {
    background: var(--bg);
    display: block;
    padding: 0;
    overflow: hidden;
  }

  /* Grid: sidebar kiri (full height) + topbar & main di kanan */
  .app {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "sidebar topbar"
      "sidebar main";
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
    overflow: hidden;
    box-shadow: none;
    border: none;
    background: var(--bg);
  }

  /* Topbar: kolom 2, baris 1 (di atas editor) */
  .topbar {
    grid-area: topbar;
    padding: 16px 32px;
    min-height: 72px;
    border-bottom: 1px solid var(--border);
    border-left: none;
    background: var(--bg);
    z-index: 10;
  }

  .topbar-title {
    padding: 0 16px;
  }

  .topbar-title .brand {
    font-size: var(--fs-2xl);
    line-height: 1;
  }

  .topbar-title small {
    font-size: 10.5px;
    letter-spacing: 0.18em;
    margin-top: 6px;
  }

  /* Sidebar: kolom 1, full height */
  .sidebar {
    grid-area: sidebar;
    position: relative;
    transform: none;
    width: auto;
    min-width: 0;
    max-width: none;
    box-shadow: none;
    border-right: 1px solid var(--border);
    border-bottom: none;
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 0;
    background: var(--bg-2);
    z-index: 5;
    overflow: hidden;
  }

  [data-theme="dark"] .sidebar {
    background: var(--bg-2);
  }

  .sidebar-head {
    padding: 28px 24px 10px;
  }

  .sidebar-tagline {
    padding: 0 24px 22px;
    font-size: 10.5px;
    letter-spacing: 0.18em;
  }

  .sidebar-footer {
    position: relative;
    background: transparent;
    border-top: 1px solid var(--border);
    padding: 10px 12px 14px;
    margin-top: auto;
  }

  .search-wrap {
    padding: 0 16px 12px;
  }

  .filters {
    padding: 0 16px 14px;
  }

  .notes-list {
    padding: 4px 10px 20px;
  }

  /* Main: kolom 2, baris 2 */
  .main {
    grid-area: main;
    border-left: none;
    border-top: none;
    background: var(--bg);
    overflow: hidden;
    position: relative;
  }

  /* Hamburger: hide paksa di desktop */
  .menu-btn {
    display: none !important;
  }

  /* Backdrop: hide paksa di desktop */
  .backdrop {
    display: none !important;
  }

  /* Editor: konten nyaman dibaca */
  .editor-body {
    padding: 40px 0 130px;
    max-width: 100%;
  }

  body[data-width="normal"] .editor-body {
    padding-left: max(56px, calc((100% - 720px) / 2));
    padding-right: max(56px, calc((100% - 720px) / 2));
  }

  body[data-width="wide"] .editor-body {
    padding-left: 64px;
    padding-right: 64px;
  }

  .statusbar {
    bottom: 100px;
    font-size: 11px;
    padding: 4px 12px;
  }

  .bottombar {
    padding: 14px 32px 20px;
    background: linear-gradient(transparent, var(--bg) 45%);
  }

  .icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
  }

  .icon-btn:hover {
    background: var(--bg-2);
    color: var(--fg);
  }

  /* Sidebar tinggi: gunakan flex untuk footer */
  .sidebar {
    display: flex;
    flex-direction: column;
  }
}

/* Layar sangat lebar */
@media (min-width: 1280px) {
  .app {
    grid-template-columns: 340px 1fr;
  }

  body[data-width="normal"] .editor-body {
    padding-left: max(72px, calc((100% - 760px) / 2));
    padding-right: max(72px, calc((100% - 760px) / 2));
  }
}

/* ---------- MOBILE EXTRA ---------- */
@media (max-width: 719px) {
  .sidebar-foot-desktop {
    display: none;
  }
}

/* Safe area for iOS notch */
@supports (padding: max(0px)) {
  .topbar {
    padding-top: max(calc(var(--safe-top) + 8px), 14px);
  }
}