/* ===== 作業マニア - Task Time Tracker ===== */
/* Dark theme, responsive, accessible design */

/* ===== CSS Variables ===== */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1e2a47;
  --bg-hover: #253456;
  --bg-active: #1b3a5c;
  --text-primary: #e0e0e0;
  --text-secondary: #adb5bd;
  --text-muted: #6c757d;
  --accent: #4fc3f7;
  --accent-hover: #29b6f6;
  --success: #66bb6a;
  --danger: #ef5350;
  --warning: #ffa726;
  --border: #2d3a5c;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 0.2s ease;
  --sidebar-width: 380px;
  --header-height: 56px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Focus Styles (Accessibility) ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(79,195,247,0.2);
}

/* ===== Layout ===== */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
}

.app-logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.app-logo svg {
  flex-shrink: 0;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.period-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.period-btn {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all var(--transition);
  white-space: nowrap;
}

.period-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.period-btn.active {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
  font-weight: 600;
}

.nav-arrow {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
}

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

#period-label {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
  min-width: 100px;
  text-align: center;
  white-space: nowrap;
}

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

.btn-header {
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.btn-header:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ===== Main Content ===== */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

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

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

.search-box {
  flex: 1;
  padding: 0.5rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  transition: border-color var(--transition);
}

.search-box:focus {
  border-color: var(--accent);
}

.search-box::placeholder {
  color: var(--text-muted);
}

.btn-add {
  padding: 0.5rem 0.85rem;
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background var(--transition);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

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

.item-list-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

/* ===== Item Row ===== */
.item-row {
  display: flex;
  align-items: center;
  padding: 0.6rem 0.5rem;
  border-radius: var(--radius);
  margin-bottom: 0.35rem;
  background: var(--bg-card);
  border: 1px solid transparent;
  transition: all var(--transition);
  gap: 0.5rem;
}

.item-row:hover {
  background: var(--bg-hover);
  border-color: var(--border);
}

.item-row.active-item {
  background: var(--bg-active);
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(79,195,247,0.15);
  animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { border-color: var(--accent); }
  50% { border-color: rgba(79,195,247,0.4); }
}

.item-color-bar {
  width: 4px;
  height: 36px;
  border-radius: 2px;
  flex-shrink: 0;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

.item-desc {
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-stats {
  color: var(--text-muted);
}

.item-timer {
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 700;
  min-width: 70px;
  text-align: right;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.btn-timer {
  padding: 0.4rem 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-start {
  background: var(--success);
  color: #111;
}

.btn-start:hover {
  background: #81c784;
}

.btn-stop {
  background: var(--danger);
  color: #fff;
}

.btn-stop:hover {
  background: #e57373;
}

.btn-icon {
  padding: 0.35rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-delete:hover, .btn-delete-sm:hover {
  color: var(--danger);
}

/* ===== Content Area ===== */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1rem;
  gap: 1rem;
}

/* ===== Summary Stats ===== */
.summary-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  font-family: 'Courier New', monospace;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

/* ===== Charts ===== */
.charts-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.75rem;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  position: relative;
}

.chart-wrapper {
  position: relative;
  width: 100%;
  height: 260px;
}

.chart-wrapper canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ===== Session Table ===== */
.session-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.session-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.session-table th {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.session-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

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

.session-color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: middle;
}

.session-duration {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: var(--accent);
}

/* ===== Dialogs ===== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}

.dialog-overlay.open {
  display: flex;
}

.dialog-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-width: 340px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.dialog-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--accent);
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: border-color var(--transition);
}

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

.form-group input[type="color"] {
  height: 40px;
  padding: 0.25rem;
  cursor: pointer;
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.dialog-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.btn-primary {
  padding: 0.5rem 1.2rem;
  background: var(--accent);
  color: #111;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background var(--transition);
}

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

.btn-secondary {
  padding: 0.5rem 1.2rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  padding: 0.5rem 1.2rem;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: background var(--transition);
}

.btn-danger:hover {
  background: #e57373;
}

/* ===== Export Dialog ===== */
.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.export-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.export-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.export-card-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.export-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.2rem;
}

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

.import-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.import-note {
  font-size: 0.75rem;
  color: var(--warning);
  margin-top: 0.5rem;
  padding: 0.5rem;
  background: rgba(255,167,38,0.1);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,167,38,0.2);
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + 0.5rem);
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-success {
  background: var(--success);
  color: #111;
}

.toast-error {
  background: var(--danger);
  color: #fff;
}

.toast-info {
  background: var(--accent);
  color: #111;
}

/* ===== Empty State ===== */
.empty-state {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2rem;
  display: block;
  margin-bottom: 0.5rem;
}

.empty-state .hint {
  font-size: 0.8rem;
  margin-top: 0.3rem;
}

/* ===== Import Mode Dialog ===== */
.import-mode-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0;
}

.import-mode-options .btn-primary,
.import-mode-options .btn-danger {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.9rem;
}

/* ===== Settings ===== */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-label {
  font-size: 0.85rem;
  color: var(--text-primary);
}

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

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.3s;
}

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

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

/* ===== Shortcut Hints ===== */
.shortcut-hint {
  font-size: 0.65rem;
  background: var(--bg-card);
  color: var(--text-muted);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-family: monospace;
  margin-left: 0.3rem;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .charts-section {
    grid-template-columns: 1fr;
  }

  .summary-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  :root {
    --sidebar-width: 320px;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .main-content {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: -100%;
    width: 85%;
    max-width: 360px;
    height: calc(100vh - var(--header-height));
    z-index: 150;
    transition: left 0.3s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.4);
  }

  .sidebar.mobile-open {
    left: 0;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .header-center {
    flex: 1;
    justify-content: center;
  }

  .period-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
  }

  #period-label {
    font-size: 0.75rem;
    min-width: 70px;
  }

  .btn-header span.btn-text {
    display: none;
  }

  .content-area {
    padding: 0.75rem;
  }

  .charts-section {
    grid-template-columns: 1fr;
  }

  .chart-wrapper {
    height: 220px;
  }

  .summary-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .session-table {
    font-size: 0.75rem;
  }

  .session-table th,
  .session-table td {
    padding: 0.35rem 0.3rem;
  }

  /* Hide some columns on mobile */
  .session-table th:nth-child(1),
  .session-table td:nth-child(1) {
    display: none;
  }

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

@media (max-width: 480px) {
  .header {
    padding: 0 0.5rem;
  }

  .nav-arrow {
    padding: 0.3rem 0.4rem;
  }

  .period-btn {
    padding: 0.25rem 0.4rem;
    font-size: 0.65rem;
  }

  .summary-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-card {
    padding: 0.5rem;
  }

  .stat-value {
    font-size: 1rem;
  }

  .item-row {
    padding: 0.5rem 0.3rem;
  }

  .btn-timer {
    padding: 0.35rem 0.5rem;
    font-size: 0.72rem;
  }

  .item-timer {
    font-size: 0.82rem;
    min-width: 60px;
  }
}

/* ===== Mobile Overlay ===== */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--header-height);
  background: rgba(0,0,0,0.5);
  z-index: 140;
  backdrop-filter: blur(2px);
}

.mobile-overlay.show {
  display: block;
}

/* ===== Print Styles ===== */
@media print {
  .header, .sidebar, .btn-timer, .btn-icon, .toast-container {
    display: none !important;
  }
  
  .main-content {
    display: block;
  }
  
  .content-area {
    padding: 0;
  }
  
  body {
    background: #fff;
    color: #000;
  }
  
  .stat-card, .chart-card, .session-section {
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
