:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e3e5e9;
  --text: #1c1e21;
  --muted: #6b7280;
  --accent: #e85d04;
  --accent-dark: #c94e02;
  --success-bg: #eafaf0;
  --success-text: #146c34;
  --error-bg: #fdecec;
  --error-text: #a4262c;
  --sidebar-bg: #17181c;
  --sidebar-text: #cfd2d8;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.sidebar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  line-height: 1.2;
  margin-bottom: 28px;
  padding: 0 8px;
}

.sidebar a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  font-size: 14px;
}

.sidebar a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar a.active { background: var(--accent); color: #fff; font-weight: 600; }

.logout-form { margin-top: auto; }

.link-button {
  background: none;
  border: none;
  color: var(--sidebar-text);
  font-size: 14px;
  padding: 10px 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  border-radius: 8px;
}
.link-button:hover { background: rgba(255,255,255,0.06); color: #fff; }

.content {
  flex: 1;
  padding: 32px 40px;
  max-width: 980px;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }
.page-header { margin-bottom: 24px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.stat-grid { display: flex; gap: 16px; flex-wrap: wrap; }
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  min-width: 180px;
}
.stat .value { font-size: 26px; font-weight: 700; }
.stat .label { font-size: 13px; color: var(--muted); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-ok { background: var(--success-bg); color: var(--success-text); }
.badge-error { background: var(--error-bg); color: var(--error-text); }
.badge-neutral { background: #eef0f3; color: var(--muted); }

form.inline { display: inline; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #374151; }
label + label { margin-top: 14px; }

input[type=text], input[type=password], input[type=time], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input[type=file] { font-size: 14px; }
textarea { resize: vertical; min-height: 80px; }

.field-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 20px; }
legend { font-weight: 700; font-size: 14px; padding: 0 6px; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: #eef0f3; color: var(--text); }
.btn-secondary:hover { background: #e2e4e9; }
.btn-danger { background: var(--error-bg); color: var(--error-text); }
.btn-danger:hover { background: #f9dada; }
.btn-block { width: 100%; }

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }

.preview-img { max-width: 260px; border-radius: 8px; border: 1px solid var(--border); display: block; margin-top: 12px; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--sidebar-bg);
}
.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 32px 32px 28px;
  width: 320px;
}
.login-card .brand { font-weight: 700; font-size: 20px; margin-bottom: 2px; }
.login-card .muted { margin-bottom: 20px; }

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .sidebar .brand { display: none; }
  .logout-form { margin-top: 0; }
  .content { padding: 20px; }
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.template-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fafafa;
}
.template-card-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(232,93,4,0.15); }
.template-card img { width: 100%; aspect-ratio: 1080 / 1920; object-fit: cover; display: block; background: #eee; }
.template-card-body { padding: 10px 12px 12px; }
.template-card-name { font-size: 13px; font-weight: 600; margin-bottom: 8px; word-break: break-word; }
.template-preview-links { font-size: 12px; margin-bottom: 8px; }
.template-preview-links a { color: var(--accent); text-decoration: none; }
.template-preview-links a:hover { text-decoration: underline; }
.template-preview-links a + a::before { content: " · "; color: var(--muted); }
