:root {
  --sapphire: #103a5c;
  --sapphire-dark: #0a2a44;
  --marble: #f7f4f0;
  --marble-dark: #e6dfd6;
  --accent: #1d6aa5;
  --text: #1c2430;
  --muted: #61707f;
  --card: #ffffff;
  --border: #d7d1c8;
  --danger: #a93535;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, var(--marble) 0%, #f0ece7 45%, var(--marble-dark) 100%);
  min-height: 100vh;
}

.topbar {
  background: var(--sapphire);
  color: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 16px rgba(16, 58, 92, 0.25);
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.nav a {
  color: #fff;
  text-decoration: none;
  margin-left: 16px;
  font-weight: 500;
}

.container {
  max-width: 1200px;
  margin: 28px auto;
  padding: 0 20px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(16, 58, 92, 0.08);
}

.auth-card {
  max-width: 420px;
  margin: 40px auto;
}

.form label {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
}

.form input,
.form textarea,
.form select,
.form-grid input,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  margin-top: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--sapphire);
  background: #fff;
  color: var(--sapphire);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}

.btn.primary {
  background: var(--sapphire);
  color: #fff;
}

.icon-btn {
  border: 1px solid var(--sapphire);
  background: #fff;
  color: var(--sapphire);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.alert {
  background: #ffe9e9;
  border: 1px solid #f0b6b6;
  color: #8b2e2e;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.dashboard .template-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
}

.dashboard .template-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.editor-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  align-items: start;
}

.template-bar {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #f9f7f4;
  position: sticky;
  top: 90px;
}

.template-bar-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.template-actions {
  display: flex;
  gap: 8px;
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.template-box {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.template-box:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.template-box.active {
  border-color: var(--sapphire);
  box-shadow: 0 0 0 2px rgba(16, 58, 92, 0.15);
}

.template-box::after {
  content: attr(data-title);
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translate(-50%, 100%);
  background: #0f2a44;
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.template-box:hover::after {
  opacity: 1;
}

.subtasks {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fbfaf8;
}

.subtasks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.subtask-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  margin-bottom: 10px;
}

.preview-card {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}

.preview-card iframe {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  min-height: 480px;
  background: #fafafa;
}

.error-box {
  display: none;
  margin-top: 12px;
  background: #1c2430;
  color: #f5f2ee;
  padding: 10px;
  border-radius: 8px;
  overflow: auto;
  max-height: 220px;
}

.actions {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

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

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .template-bar {
    position: static;
  }

  .preview-card iframe {
    min-height: 360px;
  }
}
