/* Reset & Base */
:root {
  --bg-color: #0F1219;
  --panel-bg: rgba(25, 30, 41, 0.65);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text-primary: #FFFFFF;
  --text-secondary: #94A3B8;
  --primary: #3B82F6;
  --primary-hover: #2563EB;
  --success: #10B981;
  --danger: #EF4444;
  --input-bg: rgba(15, 18, 25, 0.6);
  --radius: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  overflow: hidden;
  /* Tablet app feel */
}

h1,
h2,
h3 {
  font-family: 'Outfit', sans-serif;
}

.app-container {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Top Bar */
.top-bar {
  position: absolute;
  top: 0;
  width: 100%;
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  pointer-events: none;
  /* Allow clicks to pass through to content below */
}

.top-bar .header-left,
.top-bar .top-controls {
  pointer-events: auto;
  /* Re-enable clicks for buttons and controls */
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.logo i {
  color: var(--primary);
  font-size: 1.5rem;
}

.top-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.datetime-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 35px;
  /* アイコンの幅に合わせて調整 */
  pointer-events: none;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  opacity: 0.9;
}

.date-display {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 500;
}

.clock-display {
  font-size: 1rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* Header Tabs (PC Friendly) */
.header-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: auto;
}

.header-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: 0.2s;
}

.header-tab-btn i {
  font-size: 1.1rem;
}

.header-tab-btn:hover {
  color: white;
}

.header-tab-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Screen Layout */
.screen {
  flex: 1;
  display: none;
  height: 100%;
}

.screen.active {
  display: block;
}

/* QR Scanner */
.scanner-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}

#reader {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#reader video {
  min-width: 100%;
  min-height: 100%;
  object-fit: cover;
}

.scanner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scanner-frame {
  width: 250px;
  height: 250px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 24px;
  position: relative;
  box-shadow: 0 0 0 4000px rgba(15, 18, 25, 0.7);
  /* Dark overlay around scanner */
}

.scanner-frame::before,
.scanner-frame::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  border-color: var(--primary);
  border-style: solid;
}

.scanner-frame::before {
  top: -2px;
  left: -2px;
  border-width: 4px 0 0 4px;
  border-radius: 24px 0 0 0;
}

.scanner-frame::after {
  bottom: -2px;
  right: -2px;
  border-width: 0 4px 4px 0;
  border-radius: 0 0 24px 0;
}

.scanner-text {
  margin-top: 40px;
  text-align: center;
  z-index: 2;
}

.scanner-text h2 {
  margin-bottom: 8px;
  font-size: 1.5rem;
}

.scanner-text p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Glassmorphism Bottom Sheet */
.bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 16px;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 20;
  max-height: 90vh;
  display: flex;
  justify-content: center;
}

.bottom-sheet.open {
  transform: translateY(0);
}

.glass {
  background: var(--panel-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  padding: 32px;
  width: 100%;
  max-width: 600px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  max-height: 85vh;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 24px;
  right: 24px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  color: white;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: 0.2s;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Key Header */
.key-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
}

.key-icon-large {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(59, 130, 246, 0.05));
  border: 1px solid rgba(59, 130, 246, 0.3);
  display: grid;
  place-items: center;
  font-size: 2rem;
  color: var(--primary);
}

.key-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

#key-id-display {
  font-size: 2rem;
  margin-top: 4px;
}

.status-badge {
  margin-left: auto;
  padding: 8px 16px;
  border-radius: 40px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-badge.in {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.out {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Action Section */
.action-section h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.action-buttons {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.action-btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.2s;
}

.action-btn.primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

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

.action-btn.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.action-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.action-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.action-btn.secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Form */
.form-section {
  background: rgba(0, 0, 0, 0.2);
  padding: 24px;
  border-radius: 20px;
  margin-bottom: 24px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.form-section.hidden {
  display: none;
}

.form-section h3 {
  margin-bottom: 20px;
  font-size: 1.1rem;
}

.input-group {
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper i {
  position: absolute;
  left: 16px;
  color: var(--text-secondary);
  pointer-events: none;
}

input[type="date"] {
  position: relative;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.input-wrapper input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px 14px 14px 44px;
  color: white;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: 0.2s;
}

.input-wrapper input:focus {
  border-color: var(--primary);
}

.submit-btn {
  width: 100%;
  padding: 16px;
  background: white;
  color: black;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1rem;
  margin-top: 8px;
  cursor: pointer;
  transition: 0.2s;
}

.submit-btn:hover {
  background: #e2e8f0;
}

.cancel-btn {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  font-size: 0.9rem;
  margin-top: 8px;
  cursor: pointer;
}

/* History */
.history-section h3 {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.history-item {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 16px;
  margin-bottom: 8px;
}

.hist-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.hist-icon.borrow {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.hist-icon.return {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.hist-info {
  flex: 1;
}

.hist-info strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 2px;
}

.hist-info span {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  gap: 6px;
  align-items: center;
}

.hist-time {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  font-family: 'Outfit', sans-serif;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 24px 0;
}

/* Custom HTML5 QR Code Scanner styles to hide defaults */
#reader__dashboard_section_csr span,
#reader__dashboard_section_csr button {
  font-family: inherit;
}

#reader__dashboard_section_swaplink {
  text-decoration: none;
  color: var(--primary);
}

#reader video {
  border-radius: 0;
}

/* Dashboard Area */
#dashboard-screen {
  padding-top: 120px;
  /* Data content is pushed further down to avoid header overlap */
  overflow-y: auto;
  align-items: center;
  flex-direction: column;
}

#dashboard-screen.active {
  display: flex;
}

.dashboard-container {
  width: 100%;
  max-width: 800px;
  padding: 24px;
}

.glass-panel {
  background: rgba(25, 30, 41, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.dashboard-header h2 {
  font-size: 1.5rem;
}

.tabs {
  display: flex;
  gap: 8px;
  background: var(--input-bg);
  padding: 4px;
  border-radius: 12px;
}

.tab-btn {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: 0.2s;
}

.tab-btn.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

/* Status Filter Toggle */
.status-filter {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background: var(--input-bg);
  padding: 6px;
  border-radius: 14px;
  width: fit-content;
}

.filter-btn {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 8px 20px;
  font-size: 0.95rem;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.2s;
  font-family: inherit;
  font-weight: 600;
}

.filter-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Grid for Key Status (Grouped List) */
#status-container {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

#status-tab.hidden {
  display: none;
}

.group-section {
  width: 100%;
}

.group-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: 0.2s;
  border-radius: 12px;
}

.group-title:hover {
  background: rgba(255, 255, 255, 0.05);
}

.group-title-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.group-title-left i {
  color: var(--primary);
}

.caret-icon {
  margin-left: auto;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-secondary);
  font-size: 1.2rem;
}

/* Accordion States */
.group-section.collapsed .caret-icon {
  transform: rotate(-90deg);
}

.group-section.collapsed .group-grid {
  display: none !important;
}

.group-grid {
  display: grid;
  grid-template-columns: 1fr;
  /* リスト形式 */
  gap: 12px;
}

.key-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 16px 24px;
  border-radius: 16px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.key-card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateX(6px);
  /* リストの選択感 */
}

.kc-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 160px;
}

.kc-id {
  font-size: 1.1rem;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  gap: 10px;
}

.kc-id i {
  color: var(--primary);
  font-size: 1.2rem;
}

.kc-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 20px;
}

.kc-body span {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.kc-body strong {
  color: white;
  font-size: 1rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .key-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .kc-body {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
}

/* Key Group UI in Panel */
.key-group-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  margin-top: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  width: fit-content;
  transition: 0.2s;
}

.key-group-row:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.key-group-row .edit-icon {
  font-size: 0.8rem;
  opacity: 0.6;
}

/* Login Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  transition: 0.3s;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.login-box {
  width: 90%;
  max-width: 400px;
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-icon-large {
  width: 72px;
  height: 72px;
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
  border-radius: 20px;
  display: grid;
  place-items: center;
  margin: 0 auto 24px;
  font-size: 2.2rem;
}

.login-header h2 {
  font-size: 1.5rem;
  color: white;
  margin-bottom: 8px;
}

.login-header p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.login-error {
  color: #fb7185;
  font-size: 0.85rem;
  margin-bottom: 8px;
  background: rgba(251, 113, 133, 0.1);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(251, 113, 133, 0.2);
}

.login-error.hidden {
  display: none;
}

.login-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 30px;
}

.login-actions .submit-btn {
  width: 100%;
  font-size: 1rem;
  padding: 14px;
}

.login-actions .cancel-btn {
  width: 100%;
  background: transparent;
  color: var(--text-secondary);
}

.login-actions .cancel-btn:hover {
  color: white;
}

/* Global History List */
#history-tab.hidden {
  display: none;
}

.global-history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Login Settings Tab */
#settings-tab.hidden {
  display: none;
}

.settings-header {
  margin-bottom: 24px;
}

.settings-header h3 {
  font-size: 1.1rem;
  color: white;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.settings-header p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.user-slot {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 16px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.slot-number {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.slot-inputs {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.slot-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.slot-input-group label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 4px;
}

.slot-inputs input {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 12px;
  color: white;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: 0.2s;
  width: 100%;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-with-icon input {
  padding-right: 40px;
}

.toggle-password-btn {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  transition: 0.2s;
  z-index: 2;
}

.toggle-password-btn:hover {
  color: white;
}

.slot-inputs input:focus {
  border-color: var(--primary);
  background: rgba(0, 0, 0, 0.3);
}

.settings-footer {
  padding: 12px;
  background: rgba(59, 130, 246, 0.05);
  border-radius: 8px;
  border-left: 3px solid var(--primary);
}

.settings-footer p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

@media (max-width: 600px) {
  .user-slot {
    flex-direction: column;
    align-items: flex-start;
  }

  .slot-inputs {
    grid-template-columns: 1fr;
    width: 100%;
  }
}

/* --- Lock Screen Specifics --- */
.lock-wrapper {
  background: #000000;
}
.lock-frame {
  border-color: #EF4444;
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.85);
}
.locked-tab {
  opacity: 0.3 !important;
  pointer-events: none;
}

/* --- Toggle Switch --- */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .3s;
  border-radius: 28px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* --- System Settings Card --- */
.system-settings-card {
  padding: 20px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.setting-info strong {
  display: block;
  color: white;
  font-size: 0.95rem;
  margin-bottom: 2px;
}

.setting-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}