/* ============================================================
   KirimWA — Main Stylesheet
   Dark mode glassmorphism design
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  --bg-primary:    #0d0f14;
  --bg-secondary:  #141720;
  --bg-card:       rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(99,179,237,0.5);

  --green:         #25D366;
  --green-dark:    #1a9e4a;
  --green-glow:    rgba(37,211,102,0.15);
  --blue:          #63b3ed;
  --blue-dark:     #3182ce;
  --red:           #fc8181;
  --yellow:        #f6e05e;
  --purple:        #b794f4;

  --text-primary:  #f0f4f8;
  --text-secondary:#a0aec0;
  --text-muted:    #718096;

  --sidebar-w:     240px;
  --header-h:      60px;
  --radius:        12px;
  --radius-sm:     8px;
  --transition:    0.2s ease;

  --shadow-sm:     0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:     0 4px 20px rgba(0,0,0,0.5);
  --shadow-green:  0 4px 20px rgba(37,211,102,0.2);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--text-primary); }

img { max-width: 100%; }
ul { list-style: none; }

/* ── Layout ────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-green);
  flex-shrink: 0;
}

.sidebar-logo .logo-text {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(to right, var(--green), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 12px 20px 6px;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  border-radius: 0;
  transition: all var(--transition);
  font-weight: 500;
  position: relative;
}

.nav-item a:hover,
.nav-item a.active {
  color: var(--text-primary);
  background: var(--bg-card);
}

.nav-item a.active {
  color: var(--green);
}

.nav-item a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--green);
  border-radius: 0 3px 3px 0;
}

.nav-item a .nav-icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.sidebar-footer .admin-name {
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-content {
  padding: 24px;
  flex: 1;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Stat Cards ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}

.stat-card.green::before  { background: var(--green); }
.stat-card.blue::before   { background: var(--blue); }
.stat-card.red::before    { background: var(--red); }
.stat-card.purple::before { background: var(--purple); }
.stat-card.yellow::before { background: var(--yellow); }

.stat-card:hover {
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  font-size: 28px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: #fff;
  border-color: var(--green-dark);
  box-shadow: 0 2px 8px rgba(37,211,102,0.25);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 16px rgba(37,211,102,0.4);
  transform: translateY(-1px);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(252,129,129,0.1);
  color: var(--red);
  border-color: rgba(252,129,129,0.3);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(252,129,129,0.2);
  border-color: var(--red);
  color: var(--red);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  transition: all var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--border-focus);
  background: rgba(255,255,255,0.07);
  box-shadow: 0 0 0 3px rgba(99,179,237,0.1);
}

.form-control::placeholder { color: var(--text-muted); }

textarea.form-control { resize: vertical; min-height: 120px; }

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23a0aec0' d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 36px;
}

option { background: var(--bg-secondary); }

.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  background: rgba(255,255,255,0.03);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-secondary);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success  { background: rgba(37,211,102,0.15); color: var(--green); }
.badge-danger   { background: rgba(252,129,129,0.15); color: var(--red); }
.badge-warning  { background: rgba(246,224,94,0.15);  color: var(--yellow); }
.badge-info     { background: rgba(99,179,237,0.15);  color: var(--blue); }
.badge-muted    { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.badge-purple   { background: rgba(183,148,244,0.15); color: var(--purple); }

/* ── Alerts / Flash ─────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
}

.alert-success {
  background: rgba(37,211,102,0.1);
  border: 1px solid rgba(37,211,102,0.3);
  color: var(--green);
}

.alert-error {
  background: rgba(252,129,129,0.1);
  border: 1px solid rgba(252,129,129,0.3);
  color: var(--red);
}

/* ── WA Preview Bubble ───────────────────────────────────────── */
.wa-preview-wrap {
  background: #0b141a;
  border-radius: var(--radius);
  padding: 20px;
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23182229' fill-rule='evenodd'%3E%3Cpath d='M0 40L40 0H20L0 20M40 40V20L20 40'/%3E%3C/g%3E%3C/svg%3E");
}

.wa-bubble {
  background: #202c33;
  border-radius: 8px 8px 8px 2px;
  padding: 10px 14px;
  max-width: 85%;
  display: inline-block;
  position: relative;
  font-size: 14px;
  line-height: 1.5;
  color: #e9edef;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.wa-bubble::before {
  content: '';
  position: absolute;
  left: -8px; top: 0;
  border: 8px solid transparent;
  border-right-color: #202c33;
  border-top-color: #202c33;
}

.wa-bubble-time {
  font-size: 11px;
  color: #8696a0;
  text-align: right;
  margin-top: 4px;
}

.wa-bubble strong { font-weight: 700; }
.wa-bubble em     { font-style: italic; }
.wa-bubble del    { text-decoration: line-through; }
.wa-bubble code   { font-family: 'Courier New', monospace; font-size: 13px; }

/* ── WA Editor Toolbar ───────────────────────────────────────── */
.wa-toolbar {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.wa-toolbar button {
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  transition: all var(--transition);
}

.wa-toolbar button:hover {
  background: var(--bg-card-hover);
  border-color: var(--border);
  color: var(--text-primary);
}

.wa-toolbar .sep {
  width: 1px;
  background: var(--border);
  margin: 4px;
}

.wa-toolbar-textarea {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
  border-top: none !important;
}

/* ── Variables Chips ─────────────────────────────────────────── */
.var-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.var-chip {
  background: rgba(99,179,237,0.1);
  border: 1px solid rgba(99,179,237,0.3);
  color: var(--blue);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  font-family: 'Courier New', monospace;
  transition: all var(--transition);
}

.var-chip:hover {
  background: rgba(99,179,237,0.2);
  border-color: var(--blue);
}

/* ── Slider ──────────────────────────────────────────────────── */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  outline: none;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  background: var(--green);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(37,211,102,0.4);
  transition: box-shadow var(--transition);
}

input[type=range]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 12px rgba(37,211,102,0.6);
}

/* ── Progress ────────────────────────────────────────────────── */
.progress-wrap {
  background: rgba(255,255,255,0.07);
  border-radius: 10px;
  overflow: hidden;
  height: 10px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue));
  border-radius: 10px;
  transition: width 0.5s ease;
  position: relative;
  overflow: hidden;
}

.progress-bar::after {
  content: '';
  position: absolute;
  top: 0; left: -100%; bottom: 0;
  width: 80%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  to { left: 150%; }
}

/* ── Send Log ────────────────────────────────────────────────── */
.send-log {
  max-height: 300px;
  overflow-y: auto;
  background: #0d0f14;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
}

.log-item {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.log-item:last-child { border-bottom: none; }
.log-time { color: var(--text-muted); flex-shrink: 0; }
.log-ok   { color: var(--green); }
.log-err  { color: var(--red); }
.log-msg  { color: var(--text-secondary); }

/* ── Pagination ──────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.pagination a:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.pagination .active { background: var(--green); border-color: var(--green); color: #fff; }
.pagination .disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Upload Area ─────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--green);
  background: var(--green-glow);
}

.upload-area input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon { font-size: 40px; margin-bottom: 12px; }
.upload-text { color: var(--text-secondary); }
.upload-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p  { font-size: 13px; margin-bottom: 20px; }

/* ── Login Page ──────────────────────────────────────────────── */
.login-bg {
  min-height: 100vh;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-bg::before {
  content: '';
  position: absolute;
  top: -200px; left: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(37,211,102,0.08) 0%, transparent 70%);
  pointer-events: none;
}

.login-bg::after {
  content: '';
  position: absolute;
  bottom: -200px; right: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(99,179,237,0.06) 0%, transparent 70%);
  pointer-events: none;
}

.login-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow-md);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .logo-icon {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin: 0 auto 12px;
  box-shadow: var(--shadow-green);
}

.login-logo h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(to right, var(--green), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-logo p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

/* ── Misc Utilities ──────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'Courier New', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease forwards; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.pulse { animation: pulse 2s infinite; }

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── datetime-local input ────────────────────────────────────── */
input[type=datetime-local] {
  color-scheme: dark;
}
input[type=datetime-local]::-webkit-calendar-picker-indicator {
  filter: invert(0.6);
  cursor: pointer;
}

/* ── form-control-sm ─────────────────────────────────────────── */
.form-control-sm {
  padding: 6px 10px;
  font-size: 12px;
}

/* ── Scheduled badge (laporan) ───────────────────────────────── */
.badge-purple { background: rgba(183,148,244,0.15); color: var(--purple); }

/* ── Device chip hover active ────────────────────────────────── */
.device-chip:hover {
  border-color: rgba(37,211,102,0.4) !important;
  color: var(--green) !important;
  background: rgba(37,211,102,0.08) !important;
}

/* ── Mapping page ────────────────────────────────────────────── */
.mapping-select option[value="-1"] { color: var(--text-muted); }

/* ── Storage/cron log link ───────────────────────────────────── */
code { font-family: 'Courier New', monospace; background: rgba(255,255,255,0.06);
       padding: 1px 5px; border-radius: 4px; font-size: 12px; }
