:root {
  color-scheme: light;
  --bg: #f4f4f5;
  --bg-pattern: #d4d4d8;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-3: #e4e4e7;
  --border: #e4e4e7;
  --border-focus: #a1a1aa;
  --text: #09090b;
  --text-muted: #71717a;
  --accent: #09090b;
  --accent-hover: #27272a;
  --accent-text: #ffffff;
  --danger: #ef4444;
  --success: #10b981;
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; transition: all 0.2s ease; }
.mono { font-family: var(--font-mono); }
.w-full { width: 100%; }

.long-press-btn {
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.long-press-btn:active {
  transform: scale(0.95);
  background: var(--surface-3) !important;
}

.bg-pattern {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: radial-gradient(var(--bg-pattern) 1.5px, transparent 1.5px);
  background-size: 24px 24px;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes popIn {
  0%   { transform: scale(0.3); opacity: 0; }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.view-container { display: none; width: 100vw; height: 100dvh; }
#loginView { display: none; }
#keyAuthView { display: none; align-items: center; justify-content: center; padding: 24px; }
#bootView { display: none; align-items: center; justify-content: center; }
#importView { display: none; align-items: center; justify-content: center; background: var(--bg); }
#appView { display: none; flex-direction: column; animation: fadeIn 0.3s ease-out; }

/* ==== KEY AUTH VIEW ==== */
.keyauth-content { width: 100%; max-width: 400px; }
.keyauth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: slideUp 0.5s cubic-bezier(0.16,1,0.3,1);
}
.keyauth-logo {
  width: 56px; height: 56px;
  background: var(--accent); color: var(--accent-text);
  border-radius: 16px; display: grid; place-items: center;
  font-weight: 700; font-size: 26px;
  margin: 0 auto 24px;
  box-shadow: var(--shadow-md);
}
.keyauth-card h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.6px; margin-bottom: 6px; }
.keyauth-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }
.keyauth-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.keyauth-input {
  width: 100%; height: 48px; padding: 0 16px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; font-family: var(--font-mono);
  font-size: 15px; letter-spacing: 2px;
  color: var(--text); text-align: center;
  transition: all 0.2s;
}
.keyauth-input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px rgba(0,0,0,0.05); }
.keyauth-input::placeholder { color: var(--text-muted); letter-spacing: 2px; }
.keyauth-error { font-size: 12px; color: var(--danger); min-height: 16px; text-align: left; margin: 0; }
.keyauth-foot { margin-top: 24px; font-size: 11px; color: var(--text-muted); }

/* ==== TAMBAHAN INPUT GROUP & PASTE BUTTON ==== */
.keyauth-input-group {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.keyauth-input-group .keyauth-input {
  padding-right: 48px; /* Memberi ruang agar teks tidak menabrak ikon */
}

.paste-btn {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
}

.paste-btn:hover, .paste-btn:active {
  background: var(--surface-3);
  color: var(--text);
}

/* ==== IMPORT VIEW ANIMATION ==== */
.import-content { width: 100%; max-width: 400px; padding: 24px; }
.import-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 48px 32px; box-shadow: var(--shadow-lg); text-align: center; animation: slideUp 0.4s ease-out; }
.import-icon-wrap { width: 80px; height: 80px; margin: 0 auto 24px; position: relative; display: flex; align-items: center; justify-content: center; }
.import-spinner { width: 64px; height: 64px; border: 4px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.import-check { width: 64px; height: 64px; border-radius: 50%; background: var(--success); color: #fff; font-size: 36px; display: flex; align-items: center; justify-content: center; font-weight: 700; animation: popIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.import-title { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 8px; }
.import-status { font-size: 14px; color: var(--text-muted); margin-bottom: 24px; min-height: 20px; transition: color 0.3s; }
.import-bar-wrap { width: 100%; height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.import-bar-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 99px; transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1); }

/* ==== BOOT ==== */
.boot-content { width: 100%; max-width: 400px; padding: 24px; }
.boot-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px; box-shadow: var(--shadow-lg); }
.boot-head { margin-bottom: 24px; }
.boot-title { font-size: 14px; font-weight: 500; }
.loader-bar { width: 100%; height: 4px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-bottom: 16px; }
.loader-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.15s; }

/* ==== APP ==== */
#appView { background: transparent; }
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100%; position: relative; }

.app-topbar { height: 64px; padding: 0 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; background: var(--surface); position: relative; z-index: 100; min-height: 64px; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.status-wrap { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.4); }
.status-dot.err { background: var(--danger); box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }

.admin-menu-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.admin-menu-btn:hover { background: var(--surface-3); transform: translateY(-1px); }
.admin-menu-btn:active { transform: scale(0.92); }

.admin-dropdown {
  position: absolute;
  top: 68px;
  left: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 200px;
  z-index: 999;
  opacity: 0;
  transform: translateY(-10px) scale(0.95);
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: top left;
}
.admin-dropdown.show { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.dropdown-item { padding: 12px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; color: var(--text); transition: background 0.15s; }
.dropdown-item:hover { background: var(--bg); }

.page-container { flex: 1; overflow: hidden; display: flex; flex-direction: column; position: relative; }
.page-view { display: none; flex-direction: column; height: 100%; animation: fadeIn 0.3s ease-out; }
.page-view.active { display: flex; }

/* ==== DASHBOARD ==== */
.page-body { flex: 1; overflow-y: auto; padding: 32px 24px; display: flex; flex-direction: column; gap: 32px; width: 100%; box-sizing: border-box; }
.app-section { display: flex; flex-direction: column; gap: 12px; }
.section-header h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.device-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.device-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow-sm); transition: all 0.2s; }
.device-item:hover { border-color: var(--border-focus); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.device-label { font-size: 12px; color: var(--text-muted); }
.device-value { font-size: 18px; font-family: var(--font-mono); font-weight: 600; }
.action-panel { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; box-shadow: var(--shadow-sm); }
.action-desc h4 { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.action-desc p { font-size: 13px; color: var(--text-muted); }
.action-buttons { display: flex; gap: 12px; }

.settings-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tab-content { display: none; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.tab-content.active { display: flex; animation: fadeIn 0.2s ease-out; }

/* ==== TOOLBAR ==== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 20;
}
.search-wrap { flex: 1; position: relative; display: flex; align-items: center; }
.input-search { display: block; width: 100%; height: 42px; padding: 0 70px 0 16px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none; transition: all 0.2s; }
.input-search:focus { border-color: var(--border-focus); background: var(--surface); box-shadow: 0 0 0 3px rgba(0,0,0,0.05); }
#deleteSearchInput { padding: 0 16px !important; }
.search-count { position: absolute; right: 16px; font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); pointer-events: none; background: var(--surface-2); padding: 2px 8px; border-radius: 4px; }
.toolbar-actions { display: flex; gap: 8px; }

.preset-bar { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.preset-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.preset-btns { display: flex; gap: 8px; }

.list-scroll-area { flex: 1; overflow-y: auto; min-height: 0; background: var(--surface); }
.scroll-padding { padding: 24px; }

.edit-list { display: flex; flex-direction: column; }
.edit-row { display: grid; grid-template-columns: 1fr 140px; padding: 12px 24px; border-bottom: 1px solid var(--border); align-items: center; gap: 16px; transition: background 0.15s; content-visibility: auto; contain-intrinsic-size: 56px; }
.edit-row.hidden { display: none; }
.edit-row:hover { background: var(--bg); }
.edit-row label { font-size: 13px; font-family: var(--font-mono); color: var(--text); word-break: break-all; }
.edit-row label mark { background: var(--accent); color: var(--accent-text); padding: 0 2px; border-radius: 2px; }
.edit-row input { width: 100%; height: 38px; padding: 0 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-family: var(--font-mono); font-size: 13px; color: var(--text); text-align: right; outline: none; }
.edit-row input:focus { border-color: var(--accent); background: var(--surface); }
.edit-row input[type="text"] { text-align: left; }

.cert-row { display: grid; grid-template-columns: 160px 1fr; padding: 12px 24px; border-bottom: 1px solid var(--border); align-items: center; gap: 16px; }
.cert-row label { font-size: 13px; color: var(--text-muted); font-family: var(--font-mono); }
.cert-row input { width: 100%; height: 38px; padding: 0 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-family: var(--font-mono); font-size: 13px; color: var(--text); outline: none; }
.cert-row input:focus { border-color: var(--accent); background: var(--surface); }
.no-result { padding: 40px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ==== TUNE ==== */
.tune-box { background: var(--surface); padding: 24px; border-radius: 12px; border: 1px solid var(--border); max-width: 500px; box-shadow: var(--shadow-sm); }
.tune-box h3 { font-size: 16px; margin-bottom: 8px; }
.flex-row { display: flex; gap: 12px; align-items: stretch; }
.flex-row select { background-color: var(--bg); border: 1px solid var(--border); border-radius: 6px; font-size: 13px; outline: none; padding: 0 10px; }
.percent-input-wrap { position: relative; flex: 1; display: flex; align-items: center; }
.percent-sign { position: absolute; right: 16px; font-weight: 600; color: var(--text-muted); pointer-events: none; }

/* ==== BUTTONS ==== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 20px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; box-shadow: var(--shadow-sm); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-focus); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 12px; border-radius: 6px; }
.btn-spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; }

/* ==== DIALOG ==== */
dialog { margin: auto; padding: 0; width: calc(100% - 32px); max-width: 480px; max-height: 90dvh; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: 0 24px 48px -12px rgba(0,0,0,0.3); overflow: hidden; display: none; flex-direction: column; }
dialog[open] { display: flex; animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(4px); }

.dialog-header { padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.dialog-header h3 { font-size: 16px; font-weight: 600; }
.close-btn { background: transparent; border: none; color: var(--text-muted); font-size: 18px; padding: 4px; }
.close-btn:hover { color: var(--text); }

.dialog-body { flex: 1; overflow-y: auto; min-height: 0; }
.dialog-footer { padding: 16px 24px; display: flex; justify-content: flex-end; gap: 12px; border-top: 1px solid var(--border); background: var(--surface-2); flex-shrink: 0; }

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.input-label { font-size: 12px; font-weight: 600; color: var(--text); }
.input-field { width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-family: var(--font-mono); font-size: 13px; outline: none; }
.input-field:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px rgba(0,0,0,0.05); }
.input-field[readonly] { opacity: 0.8; cursor: text; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.filename-input-group { display: flex; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); overflow: hidden; }
.filename-input-group:focus-within { border-color: var(--accent); background: var(--surface); }
.filename-input-group input { flex: 1; border: none; background: transparent; padding: 0 12px; height: 44px; font-family: var(--font-mono); font-size: 13px; outline: none; }
.filename-ext { padding: 0 12px; background: var(--surface-2); border-left: 1px solid var(--border); color: var(--text-muted); font-size: 13px; display: flex; align-items: center; }

.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.code-block { padding: 24px; font-family: var(--font-mono); font-size: 12px; white-space: pre-wrap; word-break: break-all; color: var(--text-muted); margin: 0; background: var(--bg); }

[data-type-preset].active, [data-preset].active { background: var(--accent) !important; color: var(--accent-text) !important; border-color: var(--accent) !important; }

.delete-list { display: flex; flex-direction: column; }
.delete-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--border); transition: background 0.15s; }
.delete-item:hover { background: var(--bg); }
.delete-item label { font-size: 13px; font-family: var(--font-mono); color: var(--text); flex: 1; word-break: break-all; padding-right: 16px; }
.delete-item button { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: none; padding: 8px; border-radius: 6px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; cursor: pointer; }
.delete-item button:hover { background: var(--danger); color: #fff; transform: scale(1.05); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px); background: #09090b; color: #fff; padding: 12px 24px; border-radius: 8px; font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,0.3); opacity: 0; transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease; z-index: 9999; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-focus); border-radius: 4px; }

@media (max-width: 768px) {
  .login-brand { display: none; }
  .login-form-wrap { padding: 16px; align-items: center; }
  .login-form-inner { padding: 32px 24px; border-radius: 12px; }

  .app-topbar { padding: 0 16px; height: 60px; min-height: 60px; }
  .page-title { font-size: 16px; }
  .status-wrap { display: none; }
  .topbar-right .btn { height: 32px; padding: 0 12px; font-size: 12px; }

  .admin-dropdown { left: 16px; top: 62px; }

  .page-body { padding: 20px 16px; gap: 24px; }
  .device-grid { grid-template-columns: 1fr; }
  .action-panel { flex-direction: column; align-items: stretch; gap: 16px; }
  .action-buttons { flex-direction: column; }

  .toolbar { flex-direction: column; align-items: stretch; padding: 12px 16px; gap: 12px; }
  .search-wrap { width: 100%; min-height: 42px; }
  .input-search { display: block; width: 100%; }
  
  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  
  .toolbar-actions .btn {
    width: 100%;
    padding: 0 8px;
    font-size: 12px;
  }

  #resetBtn {
    grid-column: span 2;
  }

  .preset-bar { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 16px; }
  .preset-btns { width: 100%; justify-content: space-between; }
  .preset-btns .btn { flex: 1; }

  .edit-row { grid-template-columns: 1fr 100px; padding: 12px 16px; gap: 12px; }
  .cert-row { grid-template-columns: 1fr; padding: 12px 16px; gap: 8px; }
  .grid-2 { grid-template-columns: 1fr; }
}