/* ==============================================================================
   Ziokt Unified Graphical Client - Core Design System & Responsive Stylesheet
   ============================================================================== */

:root {
  /* Cyber Dark Theme (Default) */
  --bg-main: #070a12;
  --bg-sidebar: #0d121f;
  --bg-card: #131b2e;
  --bg-card-hover: #19233c;
  --bg-input: #0a0e17;
  --border-subtle: #1e293b;
  --border-bright: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(56, 189, 248, 0.25);
  --accent-cyan: #38bdf8;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #818cf8;
  --accent-red: #ef4444;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sidebar-width: 250px;
  --topbar-height: 56px;
  --bottombar-height: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-main: #f1f5f9;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input: #f8fafc;
  --border-subtle: #e2e8f0;
  --border-bright: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(2, 132, 199, 0.15);
}

[data-theme="contrast"] {
  --bg-main: #000000;
  --bg-sidebar: #000000;
  --bg-card: #0a0a0a;
  --bg-card-hover: #171717;
  --bg-input: #000000;
  --border-subtle: #ffffff;
  --border-bright: #ffffff;
  --text-main: #ffffff;
  --text-muted: #e5e5e5;
  --text-dim: #d4d4d4;
  --primary: #38bdf8;
  --accent-green: #22c55e;
  --accent-amber: #facc15;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

/* App Shell Layout */
#app-root {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar (Desktop) */
#sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
  z-index: 100;
}

.brand-header {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  box-shadow: 0 0 12px var(--primary-glow);
}

.brand-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.brand-ver {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.nav-menu {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-weight: 500;
  position: relative;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.nav-item.active {
  background: rgba(2, 132, 199, 0.15);
  color: var(--accent-cyan);
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--accent-cyan);
  border-radius: 0 4px 4px 0;
}

.nav-item.nav-locked, .bottom-item.nav-locked {
  opacity: 0.45;
  filter: grayscale(0.6);
  position: relative;
}

.nav-item.nav-locked::after {
  content: "🔒";
  font-size: 0.72rem;
  margin-left: auto;
  opacity: 0.85;
}

.bottom-item.nav-locked {
  opacity: 0.45;
  position: relative;
}

.bottom-item.nav-locked .bottom-icon::after {
  content: "🔒";
  font-size: 0.55rem;
  position: absolute;
  top: 0;
  right: 4px;
}

.nav-icon {
  font-size: 1.15rem;
  width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.offline {
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
}

/* Main Content Area */
#main-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
}

#topbar {
  height: calc(var(--topbar-height) + var(--safe-top));
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--safe-top) 20px 0 20px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

.mode-pill {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 9999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-family: var(--font-mono);
  font-weight: 600;
}

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

.did-pill {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: var(--transition);
}

.did-pill:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

#content-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* Bottom Bar (Mobile Navigation) */
#bottombar {
  display: none;
  height: var(--bottombar-height);
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-subtle);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
}

/* Card System */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: var(--transition);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.15);
}

.card:hover {
  border-color: var(--border-bright);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
  word-break: break-all;
}

.card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Buttons & Inputs */
.btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  user-select: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-bright);
}
.btn-secondary:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background-color: rgba(239, 68, 68, 0.3);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.input-text, .input-select, .input-textarea {
  background-color: var(--bg-input);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-main);
  font-size: 0.85rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  transition: var(--transition);
}

.input-text:focus, .input-select:focus, .input-textarea:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Tables */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  text-align: left;
}

th {
  background: var(--bg-sidebar);
  color: var(--text-muted);
  padding: 10px 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-subtle);
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

tr:hover td {
  background-color: var(--bg-card-hover);
}

/* WATChat Dual UI Container */
.chat-page-wrapper {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-height) - var(--safe-top) - 48px);
  min-height: 400px;
  box-sizing: border-box;
}

/* WATChat Login Screen with Dual UI Switcher */
.chat-login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 24px 16px;
}
.chat-login-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-md);
  transition: all 0.25s ease;
}
.chat-login-container.login-classic .chat-login-card {
  border-color: rgba(16, 185, 129, 0.45);
  box-shadow: 0 8px 32px rgba(16, 185, 129, 0.15);
  background: #0f171c;
}
.chat-login-switcher-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.dual-ui-toggle-group {
  display: inline-flex;
  background: var(--bg-input);
  padding: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
}
.chat-classic-telemetry-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(16, 185, 129, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 12px 0;
}

/* ==============================================================================
   WATChat Classic Rich Edition (Replicated from WATChat-code.zip)
   ============================================================================== */
.watchat-classic-root {
  background: #101417 !important;
  color: #f4f7f8 !important;
  font-family: system-ui, -apple-system, sans-serif !important;
}

/* Classic Login Box */
.login-classic .chat-login-card {
  max-width: 320px;
  background: #192126 !important;
  border: 1px solid #2b383f !important;
  border-radius: 16px !important;
  padding: 24px 18px !important;
  text-align: center !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45) !important;
}
.login-classic .login-box h1 {
  font-size: 28px !important;
  margin: 0 !important;
  color: #f4f7f8 !important;
  font-weight: 800 !important;
}
.login-classic .login-box p {
  color: #9fb0b8 !important;
  margin: 5px 0 14px !important;
  font-size: 14px !important;
}
.login-classic .input-text {
  min-height: 48px !important;
  border: 1px solid #2b383f !important;
  background: #101417 !important;
  color: #f4f7f8 !important;
  padding: 0 12px !important;
  border-radius: 11px !important;
  width: 100% !important;
  margin-top: 8px !important;
}
.login-classic #chat-login-btn {
  width: 100% !important;
  margin-top: 10px !important;
  min-height: 48px !important;
  border: 0 !important;
  background: #45d483 !important;
  color: #07140d !important;
  font-weight: 700 !important;
  border-radius: 11px !important;
  font-size: 16px !important;
  cursor: pointer !important;
}

/* Classic App Layout */
.chat-classic-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #101417;
  color: #f4f7f8;
  overflow: hidden;
  border: 1px solid #2b383f;
  border-radius: var(--radius-md);
}
.chat-classic-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid #2b383f;
  background: #192126;
  min-height: 52px;
  flex-shrink: 0;
}
.chat-classic-header strong {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 17px;
  color: #f4f7f8;
  margin: 0 4px;
}
.chat-classic-header span.online {
  font-size: 12px;
  color: #45d483;
  padding: 0 4px;
  font-weight: 600;
}
.chat-classic-head-btn {
  width: 40px;
  min-height: 40px;
  padding: 0;
  background: transparent;
  color: #f4f7f8;
  font-size: 18px;
  border: 0;
  cursor: pointer;
  border-radius: 8px;
  display: grid;
  place-items: center;
}
.chat-classic-head-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}
.chat-classic-head-btn.btn-text-badge {
  font-size: 14px;
  font-weight: 700;
  border: 1px solid #2b383f;
  min-width: 36px;
  width: 36px;
  height: 36px;
}

/* Classic Contacts */
.chat-classic-contact {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 58px;
  margin-bottom: 7px;
  padding: 6px 12px;
  text-align: left;
  background: #192126 !important;
  color: #f4f7f8 !important;
  border-radius: 11px !important;
  border: 1px solid #2b383f !important;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chat-classic-contact:hover,
.chat-classic-contact.active {
  border-color: #45d483 !important;
  background: #202b32 !important;
}
.chat-classic-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  min-width: 42px;
  margin-right: 10px;
  border-radius: 50%;
  background: #45d483 !important;
  color: #07140d !important;
  font-weight: 800 !important;
  font-size: 16px !important;
}

/* Classic Messages */
.chat-classic-messages {
  flex: 1;
  overflow-y: auto;
  padding: 9px 7px;
  scrollbar-width: none;
  display: flex;
  flex-direction: column;
  background: #101417 !important;
}
.chat-classic-msg {
  width: fit-content;
  max-width: 86%;
  padding: 9px 11px;
  margin-bottom: 8px;
  background: #192126;
  border-radius: 4px 13px 13px;
  overflow-wrap: anywhere;
  color: #f4f7f8;
  font-size: 15px;
  border: 1px solid #2b383f;
}
.chat-classic-msg.mine {
  margin-left: auto;
  align-self: flex-end;
  background: #246b49;
  border-radius: 13px 4px 13px 13px;
  color: #fff;
  border-color: transparent;
}
.chat-classic-msg time {
  display: block;
  text-align: right;
  color: #bed0c7;
  font-size: 11px;
  margin-top: 3px;
}

/* Classic Composer */
.chat-classic-composer {
  display: grid;
  grid-template-columns: 46px 46px 46px minmax(0, 1fr) 48px;
  gap: 4px;
  padding: 5px;
  border-top: 1px solid #2b383f;
  background: #192126 !important;
  flex-shrink: 0;
  box-sizing: border-box;
}
.chat-classic-media-btn {
  min-height: 48px;
  height: 48px;
  font: inherit;
  border-radius: 11px;
  border: 0;
  background: #45d483 !important;
  color: #07140d !important;
  font-weight: 700;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  font-size: 16px;
}
.chat-classic-media-btn:hover {
  background: #4de78f !important;
}
.chat-classic-input {
  min-width: 0;
  min-height: 48px;
  height: 48px;
  border: 1px solid #2b383f !important;
  background: #101417 !important;
  color: #f4f7f8 !important;
  padding: 0 10px;
  border-radius: 11px !important;
  font-size: 15px;
  box-sizing: border-box;
}
.chat-classic-input:focus {
  outline: 2px solid #45d483;
}

.chat-subheader {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: none;
  flex-shrink: 0;
}

.chat-container {
  display: flex;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
}

.chat-sidebar {
  width: 280px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-input-bar {
  flex-shrink: 0;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-sidebar);
  position: relative;
  z-index: 50;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.15);
}

.chat-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.4;
  word-break: break-word;
}

.bubble-mine {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 2px;
}

.bubble-theirs {
  align-self: flex-start;
  background: var(--bg-sidebar);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 2px;
}

/* Modal Dialog */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-lg);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.15s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-bright);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  min-width: 260px;
  animation: toastIn 0.2s ease-out;
}

.toast.success { border-left: 4px solid var(--accent-green); }
.toast.error { border-left: 4px solid var(--accent-red); }
.toast.info { border-left: 4px solid var(--accent-cyan); }
.toast.warning { border-left: 4px solid var(--accent-amber); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile Responsive Breakpoints */
@media (max-width: 768px) {
  #sidebar {
    display: none;
  }
  #bottombar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: calc(var(--bottombar-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    box-sizing: border-box;
  }
  .bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px;
  }
  .bottom-item.active {
    color: var(--accent-cyan);
  }
  .bottom-icon {
    font-size: 1.25rem;
  }
  #content-container {
    padding: 16px 14px calc(var(--bottombar-height) + var(--safe-bottom) + 16px) 14px;
  }
  .grid-cards {
    grid-template-columns: 1fr;
  }
  .chat-page-wrapper {
    height: calc(100vh - var(--topbar-height) - var(--safe-top) - var(--bottombar-height) - var(--safe-bottom) - 36px);
    min-height: 380px;
  }
  .chat-container {
    flex-direction: column;
    height: auto;
  }
  .chat-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
  .chat-sidebar #contact-search {
    display: none;
  }
  .chat-sidebar #add-contact-btn {
    display: none;
  }
  .chat-sidebar #contact-list {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    padding: 6px 8px;
    gap: 8px;
  }
  .chat-sidebar .contact-item {
    padding: 6px 10px !important;
    border-bottom: none !important;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    gap: 8px !important;
  }
  .chat-input-bar {
    padding: 10px 12px;
    position: sticky;
    bottom: 0;
    z-index: 60;
    background: var(--bg-sidebar);
  }
}
