/* ═══════════════════════════════════════════════
   CtrlGrana Admin — Mobile-First Design
   ═══════════════════════════════════════════════ */

/* ─── Reset & Variables ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --navy: #1E3A5F;
  --navy-dark: #152b47;
  --teal: #2E8B9E;
  --teal-light: #e8f4f8;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.12);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --sidebar-width: 250px;
  --header-height: 56px;
}
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Inter, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
  min-height: 100vh; overflow-x: hidden;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App Layout ─── */
.app { display: flex; min-height: 100vh; position: relative; }

/* ═══════════════════════════════════════════════
   MOBILE HEADER (visible only on mobile)
   ═══════════════════════════════════════════════ */
.mobile-header {
  display: flex; align-items: center; gap: 12px;
  height: var(--header-height); padding: 0 16px;
  background: var(--navy); color: #fff;
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.hamburger {
  background: none; border: none; color: #fff;
  font-size: 24px; cursor: pointer; padding: 6px;
  border-radius: 8px; display: flex; align-items: center;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.hamburger:hover { background: rgba(255,255,255,0.1); }
.mobile-logo { font-size: 17px; font-weight: 700; }

/* ─── Sidebar Overlay (mobile) ─── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 98; opacity: 0; transition: opacity var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.sidebar-overlay.show { display: block; opacity: 1; }

/* ═══════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--navy); color: #fff;
  padding: 24px 16px;
  display: flex; flex-direction: column;
  flex-shrink: 0;
  /* Mobile: off-canvas */
  position: fixed; top: 0; left: calc(var(--sidebar-width) * -1);
  bottom: 0; z-index: 99;
  transition: left var(--transition);
  box-shadow: var(--shadow-xl);
}
.sidebar.open { left: 0; }
.sidebar-logo {
  font-size: 20px; font-weight: 700; margin-bottom: 32px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 4px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar a.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 10px;
  color: rgba(255,255,255,0.6); font-size: 14px; font-weight: 500;
  transition: all .15s; text-decoration: none;
  min-height: 44px;
}
.sidebar a.nav-link:hover,
.sidebar a.nav-link.active {
  background: rgba(255,255,255,0.1); color: #fff; text-decoration: none;
}
.sidebar a.nav-link.active {
  background: rgba(255,255,255,0.14);
  box-shadow: inset 3px 0 0 var(--teal);
}
.sidebar .logout {
  margin-top: auto; border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 16px;
}

/* ═══════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════ */
.main {
  flex: 1;
  padding: 16px;
  padding-top: calc(var(--header-height) + 16px);
  max-width: 100%; min-width: 0;
}
.topbar {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 8px;
}
.topbar h1 {
  font-size: 20px; font-weight: 700; color: var(--navy);
}
.topbar .subtitle {
  font-size: 13px; color: var(--text-secondary); font-weight: 400;
}

/* ═══════════════════════════════════════════════
   CARDS GRID
   ═══════════════════════════════════════════════ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px; margin-bottom: 24px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:active { transform: scale(0.97); }
.stat-card .num {
  font-size: 24px; font-weight: 700; color: var(--navy);
  letter-spacing: -.5px; line-height: 1.2;
}
.stat-card .label {
  font-size: 12px; color: var(--text-secondary); margin-top: 4px;
  text-transform: uppercase; letter-spacing: .3px; font-weight: 500;
}

/* ═══════════════════════════════════════════════
   SECTION CARDS
   ═══════════════════════════════════════════════ */
.section {
  background: var(--card); border-radius: var(--radius);
  padding: 18px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.section h3 {
  font-size: 15px; font-weight: 600; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.section p.hint {
  font-size: 13px; color: var(--text-secondary); margin-top: 8px;
}

/* ─── Chips (keywords) ─── */
.chips {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef4f7; border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 12px;
  font-size: 13px; font-weight: 500;
}
.chip a { font-size: 14px; }

/* ═══════════════════════════════════════════════
   FORMS
   ═══════════════════════════════════════════════ */
.form-group { margin-bottom: 12px; }
.form-row {
  display: flex; flex-direction: column; gap: 10px;
}
.form-row + .form-row { margin-top: 0; }
.form-row label {
  font-size: 13px; display: flex; align-items: center; gap: 6px;
  cursor: pointer; font-weight: 500; color: var(--text-secondary);
}
input[type="text"], input[type="password"], input[type="number"],
textarea, select {
  padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit;
  transition: border-color var(--transition);
  background: #fff; width: 100%;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 100px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(46,139,158,0.1);
}

/* ─── Buttons ─── */
button, .btn {
  padding: 12px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; justify-content: center;
  min-height: 44px; -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--navy); }
.btn-primary:active { transform: scale(0.97); }
.btn-sm {
  padding: 8px 14px; font-size: 12px; border-radius: var(--radius-sm);
  min-height: 36px;
}
.btn-block { width: 100%; justify-content: center; }
.btn-warning { background: #f59e0b; color: #1a1a2e; }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-info { background: #e0f2fe; color: #075985; }
.btn-ghost {
  background: transparent; color: var(--text-secondary);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--bg); }

/* ═══════════════════════════════════════════════
   TABLES (desktop) / CARDS (mobile)
   ═══════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 12px 14px; font-weight: 600;
  color: var(--text-secondary);
  background: #f9fafb; border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid #f3f4f6; }
tbody tr:hover td { background: #f9fafb; }

/* ─── Avatar ─── */
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.avatar-placeholder {
  width: 36px; height: 36px; border-radius: 50%; background: #e5e7eb;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--text-secondary); flex-shrink: 0;
}
.mono { font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace; font-size: 11px; color: var(--text-secondary); word-break: break-all; }

/* ─── Badges ─── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-premium { background: #fef3c7; color: #92400e; }
.badge-tester { background: #e0f2fe; color: #075985; }
.badge-none { background: #f3f4f6; color: #6b7280; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-notice { background: #fff3e0; color: #e65100; }
.badge-tip { background: #e8f5e9; color: #2e7d32; }
.badge-global { background: #e3f2fd; color: #1565c0; }
.badge-user { background: #f3e5f5; color: #7b1fa2; }

/* ─── User info cell ─── */
.user-info { display: flex; align-items: center; gap: 10px; }

/* ═══════════════════════════════════════════════
   MOBILE TABLE → CARDS
   ═══════════════════════════════════════════════ */
@media (max-width: 767px) {
  .table-responsive table,
  .table-responsive thead,
  .table-responsive tbody,
  .table-responsive tr,
  .table-responsive th,
  .table-responsive td { display: block; }
  .table-responsive thead { display: none; }
  .table-responsive tbody tr {
    background: var(--card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
  }
  .table-responsive tbody tr:hover td { background: transparent; }
  .table-responsive tbody td {
    padding: 6px 0;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
  }
  .table-responsive tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .3px;
    color: var(--text-secondary);
    min-width: 70px;
    flex-shrink: 0;
  }
  .table-responsive tbody td:first-child::before { display: none; }
  .table-responsive tbody td:first-child {
    padding-top: 0;
    font-weight: 500;
  }
  .table-responsive tbody td:last-child { padding-bottom: 0; }
  .table-responsive .action-buttons {
    display: flex; gap: 6px; flex-wrap: wrap; width: 100%; margin-top: 6px;
  }
  .table-responsive .action-buttons::before { display: none; }
  .table-responsive .action-buttons form { flex: 1; min-width: 0; }
  .table-responsive .action-buttons .btn-sm { width: 100%; justify-content: center; }
  .table-responsive .user-info { width: 100%; }
}

/* ═══════════════════════════════════════════════
   MESSAGE CARDS
   ═══════════════════════════════════════════════ */
.msg-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px; margin-bottom: 10px;
  transition: box-shadow var(--transition);
}
.msg-card:hover { box-shadow: var(--shadow-lg); }
.msg-card .msg-header {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  margin-bottom: 6px;
}
.msg-card .msg-title { font-weight: 600; font-size: 14px; }
.msg-card .msg-body {
  font-size: 13px; color: var(--text-secondary);
  max-height: 48px; overflow: hidden;
  line-height: 1.5;
}
.msg-card .msg-actions {
  display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap;
}
.msg-card .msg-actions form { flex: 1; min-width: 0; }
.msg-card .msg-actions .btn-sm { width: 100%; justify-content: center; }

/* ═══════════════════════════════════════════════
   MARKDOWN PREVIEW
   ═══════════════════════════════════════════════ */
.preview-wrap {
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow-y: auto;
  max-height: 240px;
  line-height: 1.7;
  font-size: 14px;
  min-height: 120px;
}
.preview-wrap h1 { font-size: 18px; margin: 14px 0 6px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.preview-wrap h2 { font-size: 16px; margin: 12px 0 4px; }
.preview-wrap h3 { font-size: 14px; margin: 10px 0 4px; }
.preview-wrap p { margin: 6px 0; }
.preview-wrap ul, .preview-wrap ol { padding-left: 20px; margin: 6px 0; }
.preview-wrap li { margin: 2px 0; }
.preview-wrap code { background: #f0f0f0; padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.preview-wrap pre { background: #1e1e2e; color: #cdd6f4; padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 13px; }
.preview-wrap pre code { background: transparent; padding: 0; color: inherit; }
.preview-wrap blockquote { border-left: 4px solid var(--teal); padding-left: 12px; margin: 8px 0; color: var(--text-secondary); }
.preview-wrap a { color: var(--teal); }
.preview-wrap hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* ─── Editor Grid (markdown side-by-side) ─── */
.editor-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }

/* ═══════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════ */
.empty-state {
  text-align: center; padding: 32px 16px; color: var(--text-secondary);
}
.empty-state .icon { font-size: 40px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ═══════════════════════════════════════════════
   TABLET / DESKTOP
   ═══════════════════════════════════════════════ */
@media (min-width: 768px) {
  .mobile-header { display: none; }
  .sidebar-overlay { display: none !important; }
  .sidebar {
    position: sticky; top: 0; left: 0;
    height: 100vh; z-index: auto;
    box-shadow: none;
  }
  .main {
    padding: 28px 32px;
    padding-top: 28px;
  }
  .topbar h1 { font-size: 24px; }
  .cards-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
  .stat-card { padding: 20px; }
  .stat-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
  .stat-card .num { font-size: 28px; }
  .stat-card:active { transform: translateY(-2px); }
  .section { padding: 24px; margin-bottom: 24px; }
  .section h3 { font-size: 16px; }
  .form-row { flex-direction: row; align-items: center; }
  .form-row + .form-row { margin-top: 10px; }
  .form-row label { white-space: nowrap; }
  .editor-grid { grid-template-columns: 1fr 1fr; }
  input[type="text"], input[type="password"], textarea, select {
    font-size: 14px; padding: 10px 14px;
  }
  .table-responsive table { min-width: 650px; }
  .table-responsive tbody td {
    padding: 12px 14px; border-bottom: 1px solid #f3f4f6; display: table-cell;
  }
  .table-responsive tbody td::before { display: none; }
  .table-responsive tbody tr {
    display: table-row; background: none; border-radius: 0; padding: 0;
    margin-bottom: 0; box-shadow: none; border: none;
  }
  .table-responsive tbody td:first-child { padding-top: 12px; }
  .table-responsive tbody td:last-child { padding-bottom: 12px; }
  .msg-card { padding: 18px; }
  .msg-card .msg-actions { flex-wrap: nowrap; }
  .msg-card .msg-actions form { flex: none; }
  .msg-card .msg-actions .btn-sm { width: auto; }
  .preview-wrap { max-height: 300px; min-height: 200px; }
  button, .btn { padding: 10px 20px; min-height: auto; }
  .btn-block { width: auto; }
}

/* ─── Large screens ─── */
@media (min-width: 1200px) {
  .main { padding: 32px 40px; }
  .cards-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; }
}
