/* ===== Единый дизайн приложения ===== */
:root {
  --bg: #e8e8e8;
  --fg: #263238;
  --card-bg: #ffffff;
  --card-border: #cfd8dc;
  --muted: #78909c;
  --accent: #4fc3f7;
  --accent-dark: #0288d1;
  --accent-fg: #000;
  --green: #2e7d32;
  --green-hover: #388e3c;
  --red: #c62828;
  --red-hover: #d32f2f;
  --btn-bg: #eceff1;
  --btn-fg: #37474f;
  --btn-hover: #e0e0e0;
  --input-bg: #ffffff;
  --input-border: #cfd8dc;
  --error: #c62828;
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
}

body.dark {
  --bg: #1e1e1e;
  --fg: #eceff1;
  --card-bg: #2a2a2a;
  --card-border: #444;
  --muted: #90a4ae;
  --accent: #4fc3f7;
  --accent-dark: #0288d1;
  --accent-fg: #000;
  --green: #2e7d32;
  --green-hover: #388e3c;
  --red: #c62828;
  --red-hover: #d32f2f;
  --btn-bg: #37474f;
  --btn-fg: #eceff1;
  --btn-hover: #455a64;
  --input-bg: #333;
  --input-border: #555;
  --error: #ef5350;
  --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; height:100%; }
body {
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
}

/* ===== Логин ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  color: var(--accent-dark);
}

.auth-card .subtitle {
  margin: 0 0 24px;
  font-size: 13px;
  color: var(--muted);
}

.auth-card label {
  display: block;
  font-size: 12px;
  font-weight: bold;
  margin-bottom: 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.auth-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--fg);
  font-size: 14px;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,195,247,0.2);
}

.auth-card .btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  margin-bottom: 10px;
  transition: 0.15s;
}

.auth-card .btn-primary {
  background: var(--green);
  color: #fff;
}
.auth-card .btn-primary:hover { background: var(--green-hover); }

.auth-card .btn-secondary {
  background: var(--btn-bg);
  color: var(--btn-fg);
}
.auth-card .btn-secondary:hover { background: var(--btn-hover); }

.auth-card .error {
  color: var(--error);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

.auth-card .switch {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 16px;
}

.auth-card .switch a {
  color: var(--accent-dark);
  cursor: pointer;
  text-decoration: underline;
}

.hidden { display: none !important; }

/* ===== Проекты ===== */
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  color: var(--accent-dark);
  flex: 1;
}

.topbar button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  background: var(--btn-bg);
  color: var(--btn-fg);
  transition: 0.15s;
}
.topbar button:hover { background: var(--btn-hover); }
.topbar button.primary { background: var(--green); color: #fff; }
.topbar button.primary:hover { background: var(--green-hover); }

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px;
}

.project-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: 0.15s;
  display: flex;
  flex-direction: column;
}
.project-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.project-card .name {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 6px;
  color: var(--fg);
  word-break: break-word;
}

.project-card .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.project-card .actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.project-card .actions button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.15s;
}

.project-card .actions .open {
  background: var(--green);
  color: #fff;
}
.project-card .actions .open:hover { background: var(--green-hover); }

.project-card .actions .delete {
  background: var(--red);
  color: #fff;
}
.project-card .actions .delete:hover { background: var(--red-hover); }

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.empty-state h2 { font-size: 20px; margin-bottom: 8px; color: var(--fg); }
.empty-state p { margin: 0; font-size: 14px; }

/* ===== Модалка ===== */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.show { display: flex; }

.modal {
  background: var(--card-bg);
  padding: 24px;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  width: 100%;
  max-width: 400px;
}
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--input-border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--fg);
  font-size: 14px;
  margin-bottom: 16px;
}
.modal .actions { display: flex; gap: 8px; }
.modal .actions button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
}
.modal .actions .primary { background: var(--green); color: #fff; }
.modal .actions .primary:hover { background: var(--green-hover); }
.modal .actions .secondary { background: var(--btn-bg); color: var(--btn-fg); }
.modal .actions .secondary:hover { background: var(--btn-hover); }

/* ===== Библиотека фигур (слева) ===== */
#library {
  width: 180px;
  background: var(--card-bg, #f8f9fa);
  border-right: 1px solid var(--card-border, #ccc);
  padding: 10px;
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#library h3 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--muted, #546e7a);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--card-border, #eee);
  padding-bottom: 6px;
}
.lib-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: var(--btn-bg, #eceff1);
  color: var(--btn-fg, #37474f);
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  text-align: left;
  transition: 0.15s;
  width: 100%;
}
.lib-item:hover { background: var(--btn-hover, #e0e0e0); }
.lib-item.active {
  background: var(--accent, #4fc3f7);
  color: var(--accent-fg, #000);
  border-color: var(--accent-dark, #0288d1);
}
.lib-icon { font-size: 16px; }
.lib-label { flex: 1; }

/* ===== Layout: адаптивная сетка ===== */
#main {
  display: flex;
  flex-direction: row;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}
#library {
  flex: 0 0 clamp(150px, 15%, 220px);
  width: clamp(150px, 15%, 220px);
  min-width: 0;
  max-width: 220px;
  box-sizing: border-box;
  overflow-y: auto;
}
#toolpanel {
  flex: 0 0 clamp(220px, 20%, 300px);
  width: clamp(220px, 20%, 300px);
  min-width: 0;
  max-width: 300px;
  box-sizing: border-box;
  overflow-y: auto;
}
#canvas-wrap {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
#canvas-wrap canvas {
  display: block;
  max-width: 100%;
}

/* Узкие экраны: панели вниз, canvas сверху */
@media (max-width: 900px) {
  #main {
    flex-direction: column;
  }
  #library {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    max-height: 25vh;
    border-right: none;
    border-bottom: 1px solid var(--card-border, #ccc);
  }
  #toolpanel {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    max-height: 30vh;
    border-left: none;
    border-top: 1px solid var(--card-border, #ccc);
  }
  #canvas-wrap {
    flex: 1 1 auto;
  }
}


/* ===== Тост ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2e7d32; color: #fff;
  padding: 12px 24px; border-radius: 8px;
  font-size: 14px; font-weight: bold;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  z-index: 4000; opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #c62828; }

/* ===== Модалки (confirm / prompt) ===== */
.confirm-backdrop {
  display: none !important;
  position: fixed !important;
  inset: 0 !important;
  background: rgba(0,0,0,0.6) !important;
  z-index: 3000 !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 20px !important;
  box-sizing: border-box !important;
}
.confirm-backdrop.show {
  display: flex !important;
}
.confirm-modal {
  background: #fff !important;
  padding: 24px !important;
  border-radius: 10px !important;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3) !important;
  width: 100% !important;
  max-width: 420px !important;
  font-family: Arial, sans-serif !important;
  box-sizing: border-box !important;
}
body.dark .confirm-modal {
  background: #2a2a2a !important;
  color: #eee !important;
}
.confirm-modal h2 {
  margin: 0 0 12px !important;
  font-size: 18px !important;
  color: #263238 !important;
}
body.dark .confirm-modal h2 {
  color: #eee !important;
}
.confirm-modal p {
  margin: 0 0 20px !important;
  font-size: 14px !important;
  color: #78909c !important;
  line-height: 1.5 !important;
}
.confirm-modal .actions {
  display: flex !important;
  gap: 8px !important;
}
.confirm-modal .actions button {
  flex: 1 !important;
  padding: 10px !important;
  border: none !important;
  border-radius: 6px !important;
  font-size: 13px !important;
  font-weight: bold !important;
  cursor: pointer !important;
  transition: 0.15s !important;
}
.confirm-modal .actions .secondary {
  background: #eceff1 !important;
  color: #37474f !important;
}
.confirm-modal .actions .secondary:hover {
  background: #e0e0e0 !important;
}
.confirm-modal .actions .danger {
  background: #c62828 !important;
  color: #fff !important;
}
.confirm-modal .actions .danger:hover {
  background: #d32f2f !important;
}
.confirm-modal .actions .primary {
  background: #2e7d32 !important;
  color: #fff !important;
}
.confirm-modal .actions .primary:hover {
  background: #388e3c !important;
}

/* ===== Тост ===== */
.toast {
  position: fixed !important;
  bottom: 24px !important;
  left: 50% !important;
  transform: translateX(-50%) translateY(20px) !important;
  background: #2e7d32 !important;
  color: #fff !important;
  padding: 12px 24px !important;
  border-radius: 8px !important;
  font-size: 14px !important;
  font-weight: bold !important;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3) !important;
  z-index: 4000 !important;
  opacity: 0 !important;
  transition: opacity 0.3s, transform 0.3s !important;
  pointer-events: none !important;
  font-family: Arial, sans-serif !important;
}
.toast.show {
  opacity: 1 !important;
  transform: translateX(-50%) translateY(0) !important;
}
.toast.error {
  background: #c62828 !important;
}
