:root {
  --sidebar-width: 250px;
  --header-height: 60px;
  --primary: #4e73df;
  --sidebar-bg: #1e293b;
  --sidebar-hover: #334155;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #f4f6f9;
  color: #333;
}
body.modal-open { overflow: hidden; }

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

.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-brand i { font-size: 20px; }

.sidebar-menu { list-style: none; margin: 0; padding: 10px 0; }
.sidebar-menu li a,
.menu-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-menu li a {
  padding: 12px 20px;
  color: #cbd5e1;
  text-decoration: none;
}
.menu-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}
.submenu-arrow {
  margin-left: auto;
  font-size: 12px;
  opacity: .7;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
  background: var(--sidebar-hover);
  color: #fff;
}

.menu-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #cbd5e1;
  padding: 12px 20px;
  font-size: 15px;
  cursor: pointer;
}
.menu-toggle:hover { background: var(--sidebar-hover); color: #fff; }

.submenu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: none;
  background: #0f172a;
}
.submenu.open { display: block; }
.submenu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px 10px 36px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 14px;
}
.submenu a:hover,
.submenu a.active { color: #fff; background: #1e293b; }

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-width));
}

.top-header {
  height: var(--header-height);
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 150;
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  font-size: 20px;
  cursor: pointer;
}

.header-logo img { height: 42px; width: auto; max-width: 120px; }

.header-actions {
  display: flex;
  align-items: center;
  margin-left: auto;
  margin-right: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.btn-install-app {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid #16a34a;
  border-radius: 8px;
  background: #ecfdf5;
  color: #166534;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-install-app:hover {
  background: #dcfce7;
}

.btn-install-login {
  width: 100%;
  justify-content: center;
  margin-bottom: 8px;
}

.login-install-wrap {
  margin: 0 0 16px;
}

.header-user { position: relative; }
.avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.user-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 48px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  min-width: 160px;
  box-shadow: 0 8px 20px rgba(0,0,0,.08);
}
.user-dropdown.show { display: block; }
.user-dropdown a {
  display: block;
  padding: 10px 16px;
  color: #333;
  text-decoration: none;
}
.user-dropdown a:hover { background: #f3f4f6; }

.page-body { padding: 24px 16px; }

.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  padding: 24px 16px;
}

.card-title {
  margin: 0 0 20px;
  font-size: 22px;
}

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.3;
}
.form-control {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.4;
  box-sizing: border-box;
}
textarea.form-control { min-height: 180px; height: auto; padding: 10px 12px; resize: vertical; }

/* ── news form layout ── */
.news-form .form-row {
  display: grid;
  gap: 16px;
  align-items: start;
}
.news-form .form-row-title {
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
}
.news-form .form-row-meta {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
  align-items: end;
  margin-bottom: 0;
}
.news-form .form-row-meta .form-group {
  margin-bottom: 0;
  min-width: 0;
}
.news-form .meta-control {
  min-height: 42px;
  display: flex;
  align-items: center;
}
.news-form .image-control {
  gap: 10px;
  flex-wrap: nowrap;
}
.news-form .btn-upload {
  height: 42px;
  min-height: 42px;
  max-height: 42px;
  padding: 0 16px;
  font-size: 14px;
  line-height: 1;
  width: auto;
  max-width: 100%;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  box-sizing: border-box;
}
.news-form .crop-preview-inline {
  width: 56px;
  height: 42px;
  min-width: 56px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  overflow: hidden;
  background: #f0ebe0;
  flex-shrink: 0;
}
.news-form .crop-preview-inline img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.news-form .template-control {
  width: 100%;
}
.news-form .template-item-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 42px;
  min-height: 42px;
  padding: 0 12px;
  margin: 0;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  font-weight: 400;
  box-sizing: border-box;
  cursor: pointer;
}
.news-form .template-item-inline span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.news-form .form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e5e7eb;
  clear: both;
  width: 100%;
}
.news-form .form-hint {
  display: block;
  color: #6b7280;
  font-size: 12px;
  margin: 6px 0 16px;
}
.news-form .form-hint-block {
  margin-top: 10px;
  margin-bottom: 0;
}
.news-form .note-editor {
  margin-bottom: 0;
}
.news-form .note-editor .note-editing-area {
  min-height: 240px;
}
.news-form textarea.summernote-editor,
.news-form #news_details.summernote-editor {
  min-height: 280px;
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
}

.form-row {
  display: grid;
  gap: 16px;
}
.form-row-title {
  grid-template-columns: minmax(0, 3fr) minmax(0, 7fr);
}
.form-row-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.form-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.columns-editor-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.column-editor-box {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  background: #fafafa;
}
.column-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #374151;
}
.column-editor-box .note-editor { margin-bottom: 0; }

.template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.template-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
}

.image-upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-success { background: #16a34a; color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.alert-success { background: #dcfce7; color: #166534; }
.alert-danger { background: #fee2e2; color: #991b1b; }

.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
.table th,
.table td {
  padding: 12px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: top;
}
.table th { background: #f9fafb; }

.crop-area {
  max-width: 100%;
  max-height: 55vh;
  overflow: hidden;
  background: #111;
}
.crop-area img { max-width: 100%; display: block; }
.crop-preview-wrap {
  width: 260px;
  max-width: 100%;
  border: 2px solid #ccc;
  background: #f0ebe0;
}
.crop-preview-wrap img { width: 100%; display: block; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-overlay.show { display: flex; }
.modal-dialog {
  width: 100%;
  max-width: 760px;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal-header,
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #f8fafc;
}
.modal-header h3 {
  margin: 0;
  font-size: 18px;
}
.modal-close {
  border: none;
  background: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
}
.modal-body { padding: 16px 18px; }
.modal-footer { justify-content: flex-end; gap: 10px; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b, #334155);
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 12px;
  padding: 32px 24px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.login-card h1 { margin: 0 0 8px; text-align: center; font-size: 24px; }
.login-card p { text-align: center; color: #6b7280; margin-bottom: 24px; }

.action-btns { display: flex; flex-wrap: wrap; gap: 6px; }

.table-news-list .col-id { width: 42px; white-space: nowrap; }
.table-news-list .col-actions { min-width: 110px; }

@media (max-width: 768px) {
  .table-news-list {
    min-width: 0;
    font-size: 12px;
  }
  .table-news-list th,
  .table-news-list td {
    padding: 8px 6px;
    font-size: 12px;
    line-height: 1.35;
  }
  .table-news-list .col-id {
    width: 28px;
    padding-right: 4px;
    font-size: 11px;
  }
  .table-news-list .col-actions {
    min-width: 72px;
    max-width: 88px;
    padding-left: 4px;
    padding-right: 4px;
  }
  .table-news-list .col-hide-mobile {
    display: none;
  }
  .table-news-list .action-btns {
    flex-direction: column;
    gap: 4px;
    align-items: stretch;
  }
  .table-news-list .action-btns .btn-action {
    padding: 3px 5px;
    font-size: 9px;
    line-height: 1.2;
    border-radius: 4px;
    white-space: nowrap;
    text-align: center;
  }
}

@media (max-width: 992px) {
  .news-form .form-row-title,
  .news-form .form-row-meta,
  .form-row-title,
  .form-row-2,
  .form-row-3,
  .columns-editor-grid {
    grid-template-columns: 1fr;
  }
  .news-form .form-row-meta .form-group {
    margin-bottom: 16px;
  }
  .news-form .form-row-meta .form-group:last-child {
    margin-bottom: 0;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
    width: 100%;
  }
  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .page-body,
  .card {
    padding-left: 12px;
    padding-right: 12px;
  }
  .card-title {
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  .top-header {
    padding: 0 10px;
  }
  .header-logo img {
    height: 34px;
  }
  .modal-dialog {
    max-width: 100%;
  }
}
