/* DDC Rental Platform — dark theme (Supabase/AnyDesk style) */

:root {
  --bg:        #0b0f1a;
  --bg-panel:  #111827;
  --bg-card:   #131b2c;
  --bg-inset:  #0d1424;
  --border:    #24304a;
  --text:      #e5e9f2;
  --text-dim:  #8a93a8;
  --accent:    #4f6ef7;
  --accent-2:  #6d5df6;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #eab308;
  --radius:    10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Sarabun', Tahoma, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

.mono { font-family: Consolas, 'Courier New', monospace; letter-spacing: 2px; }
.muted { color: var(--text-dim); font-size: 12px; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-panel); color: var(--text);
  padding: 8px 16px; font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: #1d4ed8; border-color: #2563eb; }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { background: var(--accent-2); border-color: var(--accent-2); }
.btn-secondary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-danger { border-color: #7f1d1d; color: #fca5a5; }
.btn-danger:hover { background: #7f1d1d; }

.input {
  background: var(--bg-inset); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 8px 12px; font-size: 13px; outline: none; width: 100%;
}
.input:focus { border-color: var(--accent); }
.select { width: auto; }

/* ---------- auth page ---------- */
.auth-body { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px; margin-top: 8vh;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px;
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.auth-logo h1 { font-size: 20px; }
.auth-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.auth-hint { color: var(--text-dim); font-size: 11px; margin-top: 16px; text-align: center; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.alert { border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid #7f1d1d; color: #fca5a5; }

.logo-block {
  width: 18px; height: 18px; border-radius: 4px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.logo-anydesk { background: #29b6f6; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border); background: var(--bg-panel);
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-left h1 { font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 14px; font-size: 12px;
}
.mainnav { display: flex; gap: 4px; margin-left: 18px; }
.mainnav a {
  color: var(--text-dim); text-decoration: none; font-size: 13px;
  padding: 6px 12px; border-radius: 8px;
}
.mainnav a:hover { color: var(--text); background: var(--bg-inset); }
.mainnav a.active { color: var(--text); background: var(--bg-inset); }

.page { max-width: 1080px; margin: 0 auto; padding: 24px 22px; }
.page h2 { font-size: 19px; margin-bottom: 4px; }
.page .sub { color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.alert-success { background: rgba(34,197,94,.12); border: 1px solid #14532d; color: #86efac; }

.panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.panel h3 { font-size: 15px; margin-bottom: 12px; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table th { color: var(--text-dim); font-weight: 600; font-size: 12px; }
.table tr:last-child td { border-bottom: none; }

.spec-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.spec-tag {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 9px; font-size: 11px; color: var(--text-dim);
}
.pkg-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 10px; }
.pkg-option { position: relative; }
.pkg-option input { position: absolute; opacity: 0; }
.pkg-option label {
  display: block; text-align: center; cursor: pointer;
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 8px;
}
.pkg-option input:checked + label { border-color: var(--accent); background: rgba(79,110,247,.12); }
.pkg-option .pkg-name { font-size: 13px; color: var(--text-dim); }
.pkg-option .pkg-price { font-size: 17px; font-weight: 700; margin-top: 3px; }

.status-chip { border-radius: 6px; padding: 3px 10px; font-size: 11px; font-weight: 600; display: inline-block; }
.st-pending  { background: rgba(234,179,8,.15); color: var(--yellow); }
.st-verified { background: rgba(79,110,247,.18); color: #93b1ff; }
.st-approved { background: rgba(34,197,94,.15); color: var(--green); }
.st-rejected { background: rgba(239,68,68,.15); color: var(--red); }
.st-active   { background: rgba(34,197,94,.15); color: var(--green); }
.st-grace    { background: rgba(234,179,8,.15); color: var(--yellow); }
.st-expired  { background: rgba(239,68,68,.15); color: var(--red); }
.st-cancelled{ background: rgba(148,163,184,.15); color: #94a3b8; }

.pairing-code {
  font-family: Consolas, monospace; font-size: 22px; letter-spacing: 8px;
  background: var(--bg-inset); border: 1px dashed var(--accent);
  border-radius: 10px; padding: 10px 16px; display: inline-block; margin-top: 6px;
}

/* ---- machine detail page ---- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .detail-grid { grid-template-columns: 1fr; } }
#metric-chart { width: 100%; display: block; }
.legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.legend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 4px; }
.codebox {
  background: var(--bg-inset); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; font-size: 11px; color: var(--text-dim); white-space: pre-wrap;
  word-break: break-word; margin-top: 8px; max-height: 220px; overflow: auto;
}
.row-warn td { background: rgba(234,179,8,.08); }
.row-crit td { background: rgba(239,68,68,.10); }
.update-item {
  border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  margin-bottom: 10px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.update-item.sec { border-color: #7f1d1d; }
.update-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.bsod-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.bsod-item:last-child { border-bottom: none; }
.pill { border-radius: 20px; padding: 4px 12px; font-size: 12px; font-weight: 600; }
.pill-green { background: rgba(34,197,94,.15); color: var(--green); }
.pill-red { background: rgba(239,68,68,.15); color: var(--red); }

/* ---------- toolbar / stats ---------- */
.toolbar { display: flex; gap: 10px; padding: 14px 22px; align-items: center; }
.toolbar .input[type="search"] { max-width: 240px; }

.stats-bar { display: flex; gap: 12px; padding: 4px 22px 14px; border-bottom: 1px solid var(--border); }
.stat-box {
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
  min-width: 92px; padding: 10px 14px; text-align: center;
}
.stat-num { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ---------- machine grid ---------- */
.grid {
  display: grid; gap: 16px; padding: 20px 22px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.empty-state { color: var(--text-dim); padding: 40px; text-align: center; grid-column: 1 / -1; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: #3b4a6b; transform: translateY(-2px); }

.card-shot {
  position: relative; height: 110px; background: var(--bg-inset); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 26px; letter-spacing: 3px; cursor: pointer;
}
/* striped placeholder shown only when there is no screenshot */
.card-shot.no-shot {
  background-image: linear-gradient(135deg, #16203a 25%, #101830 25%, #101830 50%, #16203a 50%, #16203a 75%, #101830 75%);
  background-size: 24px 24px;
}
.card-shot .shot-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: top;
}
/* machine name overlays the screenshot; hidden unless it's the placeholder */
.card-shot .shot-label {
  position: relative; z-index: 1; text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
.card-shot:not(.no-shot) .shot-label {
  position: absolute; bottom: 6px; left: 8px; font-size: 12px; letter-spacing: 1px;
  background: rgba(4,8,16,.55); padding: 2px 8px; border-radius: 5px;
}
.card-shot.offline { filter: grayscale(1) brightness(.6); }

.card-body { padding: 12px 14px; }
.card-name { font-size: 15px; font-weight: 700; }
.card-ip { color: var(--text-dim); font-size: 12px; margin: 2px 0 8px; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 6px; padding: 3px 9px; font-size: 11px; font-weight: 600; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-online { background: rgba(34,197,94,.15); color: var(--green); }
.badge-offline { background: rgba(239,68,68,.15); color: var(--red); }
.badge-maintenance { background: rgba(234,179,8,.15); color: var(--yellow); }
.badge-awaiting_reset { background: rgba(234,179,8,.15); color: var(--yellow); }

.meter-row { display: flex; align-items: center; gap: 8px; margin-top: 7px; font-size: 11px; }
.meter-row .label { width: 30px; color: var(--text-dim); }
.meter-row .value { width: 34px; text-align: right; }
.meter { flex: 1; height: 5px; border-radius: 3px; background: var(--bg-inset); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .5s; }
.meter > i.warn { background: var(--yellow); }
.meter > i.crit { background: var(--red); }

.card-anydesk {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.anydesk-id { display: inline-flex; align-items: center; gap: 6px; color: #29b6f6; font-size: 12px; font-weight: 600; cursor: pointer; }
.anydesk-id::before { content: ''; width: 12px; height: 12px; border-radius: 3px; background: #29b6f6; }

.rental-timer { margin-top: 8px; font-size: 11px; color: var(--text-dim); }
.rental-timer b { color: var(--yellow); }
.rental-timer.expiring b { color: var(--red); }
.renew-link { color: var(--accent); margin-left: 8px; text-decoration: none; }
.renew-link:hover { text-decoration: underline; }

.card-actions {
  display: grid; grid-template-columns: repeat(6, 1fr);
  border-top: 1px solid var(--border);
}
.card-actions button {
  background: none; border: none; border-right: 1px solid var(--border);
  color: var(--text-dim); font-size: 10px; padding: 8px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.card-actions button:last-child { border-right: none; }
.card-actions button:hover { background: var(--bg-inset); color: var(--text); }
.card-actions button .ico { font-size: 14px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4,8,16,.7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
/* the hidden attribute must always win over display:flex above */
.modal-backdrop[hidden] { display: none !important; }
.modal {
  width: 100%; max-width: 360px;
  background: #151b2b; border: 1px solid var(--border);
  border-radius: 14px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-title { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.modal-title h2 { font-size: 17px; }
.modal-section {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 12px;
}
.section-label { color: var(--accent-2); font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.section-value { font-size: 15px; font-weight: 700; }
.modal-section .input { margin-bottom: 10px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-panel); border: 1px solid var(--accent);
  border-radius: 10px; padding: 12px 20px; font-size: 13px; z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.error { border-color: var(--red); }

@media (max-width: 640px) {
  .stats-bar { flex-wrap: wrap; }
  .toolbar { flex-wrap: wrap; }
}
