/* HSystem Admin - 管理員介面樣式 */

:root {
  --bg-dark: #0d1117;
  --bg-sidebar: #161b22;
  --bg-card: #21262d;
  --bg-hover: #30363d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-dim: rgba(56, 139, 253, 0.15);
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;
  --radius: 8px;
  --radius-sm: 6px;
  --font-sans: "Noto Sans TC", sans-serif;
  --font-mono: "JetBrains Mono", monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-dark);
  background-image: linear-gradient(rgba(13, 17, 23, 0.75), rgba(13, 17, 23, 0.82)), url("../img/background.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* ========== 登錄頁面 ========== */
.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background-image: linear-gradient(rgba(13, 17, 23, 0.5), rgba(13, 17, 23, 0.7)), url("../img/background.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-brand .login-logo {
  max-width: 180px;
  height: auto;
  margin: 0 auto 1rem;
  display: block;
}

.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.login-brand p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.login-form .form-group:last-of-type {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.form-group input,
.select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.form-group textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  resize: vertical;
}

.form-group input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.form-group-inline label {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-group-inline .select {
  width: auto;
  min-width: 180px;
}

.form-error {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--error);
  min-height: 1.25rem;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  transition: background 0.2s, color 0.2s;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* ========== 主介面 ========== */
.main-view {
  min-height: 100vh;
  display: flex;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .sidebar-logo-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
  flex-shrink: 0;
}

.sidebar-brand .sidebar-logo-icon img {
  width: 100%;
  height: 100%;
}

.brand-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9375rem;
  transition: color 0.2s, background 0.2s;
}

.nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.nav-icon {
  font-size: 1.25rem;
  font-variation-settings: 'opsz' 24;
}

.nav-icon.material-symbols-outlined {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.api-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 2s infinite;
}

.status-dot.online {
  background: var(--success);
}

.status-dot.offline {
  background: var(--error);
}

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

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-image: linear-gradient(rgba(13, 17, 23, 0.6), rgba(13, 17, 23, 0.75)), url("../img/background.jpg");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

.content-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.content-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.content-body {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

/* Pages */
.page {
  display: none;
}

.page.active {
  display: block;
}

.page-toolbar {
  margin-bottom: 1.5rem;
}

/* Stats */
.stats-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  min-width: 120px;
}

.stat-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
}

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Table */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
}

.data-table th {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  font-size: 0.9375rem;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

.empty-msg {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  padding: 2rem !important;
}

.panel-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  padding: 1rem;
}

/* ========== APP 頁面 ========== */
.apps-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.apps-header-left {
  flex: 1;
  min-width: 0;
}

.apps-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

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

.apps-header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.apps-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.apps-stat-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 600;
}

.apps-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-icon {
  font-size: 1.125rem;
  margin-right: 0.25rem;
}

.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.app-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.app-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.app-card-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.app-card-status {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--success);
  color: #fff;
}

.app-card-status.suspended {
  background: var(--text-muted);
}

.app-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.app-card-id {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.app-card-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.app-card-action {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.apps-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 2rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.apps-empty p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* APP 詳情視圖 */
.app-detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.app-detail-top {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.btn-back {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

.app-detail-info {
  flex: 1;
}

.app-detail-info h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.app-detail-id {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.app-detail-body {
  display: flex;
  gap: 1.5rem;
  flex: 1;
  min-height: 0;
}

.app-detail-sidebar {
  flex-shrink: 0;
  width: 180px;
}

.app-detail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 0;
}

.app-nav-item {
  padding: 0.625rem 1rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.app-nav-item:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.app-nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.app-detail-main {
  flex: 1;
  min-width: 0;
}

.sub-panel {
  display: none;
}

.sub-panel.active {
  display: block;
}

.sub-panel-header {
  margin-bottom: 1rem;
}

.sub-panel-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.sub-panel-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.module-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.module-card h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Module */
.module-section {
  margin-bottom: 1.5rem;
}

.module-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.module-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.module-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  border-radius: 24px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* Shield */
.shield-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.shield-block h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* About */
.about-card {
  max-width: 480px;
  padding: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.about-card .about-logo {
  max-width: 240px;
  height: auto;
  margin-bottom: 1rem;
}

.about-card h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.about-card p {
  margin-bottom: 0.5rem;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.create-admin-section {
  margin-top: 1.5rem;
}

.perm-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  cursor: pointer;
}

.perm-item input {
  width: auto;
}

/* ========== 設置頁面 ========== */
.settings-container {
  max-width: 560px;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.settings-card-header {
  padding: 1.5rem 1.5rem 0;
  margin-bottom: 1rem;
}

.settings-card-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

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

.settings-form {
  padding: 0 1.5rem 1.5rem;
}

.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
}

.contact-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.contact-field-full {
  grid-column: 1 / -1;
}

.contact-field label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.contact-field input {
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.contact-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.contact-field input::placeholder {
  color: var(--text-muted);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.settings-message {
  font-size: 0.875rem;
}

.settings-message.success {
  color: var(--success);
}

.settings-message.error {
  color: var(--error);
}

.settings-note {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: var(--accent-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text-muted);
}

.settings-note strong {
  color: var(--text);
}

/* ========== 創建管理員 / 管理員管理頁面 ========== */
.admin-manage-page {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.admin-list-section,
.create-admin-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.section-header {
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

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

.create-admin-form .form-group {
  margin-bottom: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.perm-group {
  margin-top: 1.25rem;
}

.perm-group label {
  display: block;
  margin-bottom: 0.75rem;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
}

.perm-item-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.2s;
}

.perm-item-card:hover {
  border-color: var(--accent);
}

.perm-item-card input {
  width: auto;
  margin: 0;
}

.perm-item-card .perm-label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.perm-item-card .perm-zh {
  font-size: 0.9375rem;
}

.perm-item-card .perm-en {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.create-admin-message {
  margin-top: 1rem;
  font-size: 0.875rem;
}

.create-admin-message.success {
  color: var(--success);
}

.create-admin-message.error {
  color: var(--error);
}

.modal-lg {
  max-width: 560px;
}

.admin-detail-section {
  margin-bottom: 1.5rem;
}

.admin-detail-section h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.admin-detail-json {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  padding: 1rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 280px;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }

  .perm-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .contact-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .apps-header {
    flex-direction: column;
    align-items: stretch;
  }

  .apps-header-right {
    justify-content: space-between;
  }

  .app-detail-body {
    flex-direction: column;
  }

  .app-detail-sidebar {
    width: 100%;
  }

  .app-detail-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1.5rem;
}

.modal-body .form-group {
  margin-bottom: 1rem;
}

.modal-body .btn {
  margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 64px;
    padding: 0.5rem 0;
  }

  .sidebar-brand .brand-title,
  .nav-item span:not(.nav-icon) {
    display: none;
  }

  .sidebar-brand {
    justify-content: center;
    padding: 1rem;
  }

  .nav-item {
    justify-content: center;
    padding: 1rem;
  }

  .table-wrap {
    overflow-x: auto;
  }

  .data-table {
    min-width: 500px;
  }
}
