/* SPDX-License-Identifier: AGPL-3.0-or-later */
/* Copyright (C) 2024-2026 Philippe Naveau — contact@perfshop.io */
/* PerfShop — Scripts UI — https://perfshop.io */

/**
 * layout.css — Page layout, login, header, main grid (sidebar + editor +
 * bottom panel), buttons, modals, toast.
 *
 * Loaded AFTER tokens.css. Component-level styling (tree nodes, pills,
 * status badges, tabs) lives in components.css.
 */

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

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background:  var(--bg);
  color:       var(--text);
  min-height:  100vh;
}

/* ── Login screen ─────────────────────────────────────────────────── */
#loginScreen {
  display:         flex;
  align-items:     center;
  justify-content: center;
  min-height:      100vh;
  padding:         1rem;
}
.login-card {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: 16px;
  padding:       2.5rem;
  width:         100%;
  max-width:     400px;
}
.login-logo  { font-size: 2.5rem;  text-align: center; margin-bottom: .5rem; }
.login-card h1 { font-size: 1.3rem; font-weight: 700; text-align: center; margin-bottom: .25rem; }
.login-card p  { font-size: .8rem;  color: var(--text2); text-align: center; font-family: var(--mono); margin-bottom: 1.75rem; }
.login-error {
  background:    rgba(255, 71, 87, .1);
  border:        1px solid rgba(255, 71, 87, .3);
  color:         #ff6b7a;
  border-radius: 8px;
  padding:       .75rem 1rem;
  margin-bottom: 1rem;
  font-size:     .85rem;
  /* display: none removed B1.ter — initial state set via .hidden class in HTML */
}
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .8rem; color: var(--text2); margin-bottom: .4rem; font-weight: 500; }
.field input {
  width:         100%;
  background:    var(--surface2);
  border:        1px solid var(--border);
  border-radius: 8px;
  color:         var(--text);
  padding:       .65rem .9rem;
  font-size:     .95rem;
  outline:       none;
  transition:    border-color .2s;
}
.field input:focus { border-color: var(--accent); }

/* ── Main screen + header ─────────────────────────────────────────── */
/* B1.ter: display: none removed — initial .hidden class in HTML controls it. */
#mainScreen { display: flex; flex-direction: column; min-height: 100vh; }
header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         14px 24px;
  border-bottom:   1px solid var(--border);
  background:      var(--surface);
  gap:             12px;
  flex-wrap:       wrap;
}
.header-left h1 { font-size: 1.2rem; font-weight: 700; }
.header-left p  { font-size: .72rem; color: var(--text2); font-family: var(--mono); }
.header-right   { display: flex; align-items: center; gap: 8px; }

/* ── Main layout (sidebar + editor area) ──────────────────────────── */
.main-layout {
  display:               grid;
  grid-template-columns: 260px 1fr;
  flex:                  1;
  overflow:              hidden;
  min-height:            0;
}
.sidebar {
  background:     var(--surface);
  border-right:   1px solid var(--border);
  display:        flex;
  flex-direction: column;
  overflow:       hidden;
}
.sidebar-top {
  padding:        10px;
  border-bottom:  1px solid var(--border);
  display:        flex;
  flex-direction: column;
  gap:            6px;
}
.sidebar-row { display: flex; gap: 5px; }

.tree-scroll { flex: 1; overflow-y: auto; padding: 6px; }
.tree-empty  { text-align: center; padding: 20px; color: var(--text2); font-size: .8rem; }

.editor-area { display: flex; flex-direction: column; overflow: hidden; }
.editor-bar {
  display:       flex;
  align-items:   center;
  gap:           8px;
  padding:       10px 16px;
  border-bottom: 1px solid var(--border);
  background:    var(--surface);
  flex-wrap:     wrap;
}
.editor-info { flex: 1; min-width: 0; }
.editor-path {
  font-family:   var(--mono);
  font-size:     .8rem;
  overflow:      hidden;
  text-overflow: ellipsis;
  white-space:   nowrap;
}
.editor-path.placeholder { color: var(--text2); }
/* B1.ter: display: none removed — initial .hidden class in HTML controls it. */
.dirty-mark              { color: var(--warning); margin-right: 4px; }
.editor-wrap             { flex: 1; overflow: hidden; min-height: 0; }

.CodeMirror {
  height:      100% !important;
  font-family: var(--mono);
  font-size:   .8rem;
  background:  var(--bg) !important;
}
.CodeMirror-scroll { height: 100%; }

.bottom-panel {
  height:         240px;
  border-top:     1px solid var(--border);
  display:        flex;
  flex-direction: column;
  background:     var(--surface);
  flex-shrink:    0;
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  padding:       6px 12px;
  border-radius: 7px;
  border:        none;
  cursor:        pointer;
  font-family:   'DM Sans', sans-serif;
  font-size:     .82rem;
  font-weight:   600;
  transition:    opacity .15s;
  display:       inline-flex;
  align-items:   center;
  gap:           5px;
  white-space:   nowrap;
}
.btn:hover    { opacity: .8; }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-success  { background: rgba(46, 213, 115, .15); color: var(--success); border: 1px solid rgba(46, 213, 115, .3); }
.btn-danger   { background: rgba(255, 71, 87, .15); color: var(--danger);  border: 1px solid rgba(255, 71, 87, .3); }
.btn-ghost    { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.btn-warning  { background: rgba(255, 165, 2, .15); color: var(--warning); border: 1px solid rgba(255, 165, 2, .3); }
.btn-new      { background: rgba(102, 126, 234, .15); color: var(--accent); border: 1px solid rgba(102, 126, 234, .3); }
.btn-sm       { padding: 4px 9px; font-size: .76rem; }
.btn-xs       { padding: 2px 7px; font-size: .7rem; }

/* ── Modals + toast ───────────────────────────────────────────────── */
.modal-overlay {
  position:        fixed;
  inset:           0;
  background:      rgba(10, 10, 30, .8);
  backdrop-filter: blur(4px);
  z-index:         100;
  display:         none;
  align-items:     center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: 14px;
  padding:       22px;
  width:         min(420px, 95vw);
}
.modal h3 { font-size: .95rem; font-weight: 700; margin-bottom: 14px; }
.modal-input {
  width:         100%;
  background:    var(--surface2);
  border:        1px solid var(--border);
  border-radius: 7px;
  color:         var(--text);
  padding:       .55rem .8rem;
  font-size:     .85rem;
  font-family:   var(--mono);
  outline:       none;
  margin-bottom: 10px;
  appearance:    none;
}
.modal-input:focus { border-color: var(--accent); }
.modal-hint {
  font-size:     .72rem;
  color:         var(--text2);
  margin-bottom: 14px;
  line-height:   1.5;
}
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position:       fixed;
  bottom:         20px;
  left:           50%;
  transform:      translateX(-50%);
  background:     var(--surface);
  border:         1px solid var(--border);
  border-radius:  9px;
  padding:        9px 18px;
  font-size:      .8rem;
  box-shadow:     0 6px 24px rgba(0, 0, 0, .4);
  z-index:        200;
  transition:     opacity .4s;
  pointer-events: none;
  opacity:        0;
  white-space:    nowrap;
  max-width:      90vw;
  overflow:       hidden;
  text-overflow:  ellipsis;
}
.toast-ok    { border-color: rgba(46, 213, 115, .4); color: var(--success); }
.toast-error { border-color: var(--danger);         color: var(--danger); }
.toast-warn  { border-color: rgba(255, 165, 2, .4); color: var(--warning); }
