/* ==========================================================================
   物販管理ハブ ダッシュボード — Design System
   ========================================================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
    /* Colors — Light Theme */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-card-hover: rgba(255, 255, 255, 1);

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --text-inverse: #f8fafc;

    --accent-blue: #2563eb;
    --accent-blue-light: #3b82f6;
    --accent-blue-dark: #1d4ed8;
    --accent-green: #059669;
    --accent-green-light: #10b981;
    --accent-amber: #d97706;
    --accent-amber-light: #f59e0b;
    --accent-red: #dc2626;
    --accent-purple: #7c3aed;

    --border-color: rgba(99, 102, 241, 0.08);
    --border-color-hover: rgba(99, 102, 241, 0.16);

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.06), 0 8px 10px -6px rgba(0, 0, 0, 0.06);
    --shadow-glow-blue: 0 0 20px rgba(37, 99, 235, 0.08);
    --shadow-glow-green: 0 0 20px rgba(5, 150, 105, 0.08);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout */
    --sidebar-width: 260px;
    --header-height: 64px;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--accent-blue-light);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-blue);
}

/* --- Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-right: 1px solid var(--border-color);
    padding: var(--space-6) 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition-base);
}

.sidebar-brand {
    padding: 0 var(--space-6) var(--space-6);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-4);
}

.sidebar-brand-name {
    font-size: var(--font-size-lg);
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-blue-light), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.025em;
}

.sidebar-brand .brand-sub {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 0 var(--space-3);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-1);
    cursor: pointer;
}

.nav-item:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--text-primary);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(139, 92, 246, 0.1));
    color: var(--accent-blue-light);
    box-shadow: var(--shadow-glow-blue);
}

.nav-item .nav-icon {
    font-size: var(--font-size-lg);
    width: 24px;
    text-align: center;
    flex-shrink: 0;
}

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.page-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: var(--space-5) var(--space-8);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
}

.page-title {
    font-size: var(--font-size-xl);
    font-weight: 600;
    letter-spacing: -0.025em;
}

.page-subtitle {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.page-body {
    padding: var(--space-8);
}

/* Mobile menu toggle */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: var(--font-size-xl);
    cursor: pointer;
    padding: var(--space-2);
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    backdrop-filter: blur(10px);
    transition: all var(--transition-base);
}

.card:hover {
    border-color: var(--border-color-hover);
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
}

.card-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-secondary);
}

/* --- Summary Cards --- */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    backdrop-filter: blur(10px);
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.summary-card.blue::before { background: linear-gradient(90deg, var(--accent-blue), var(--accent-blue-light)); }
.summary-card.green::before { background: linear-gradient(90deg, var(--accent-green), var(--accent-green-light)); }
.summary-card.amber::before { background: linear-gradient(90deg, var(--accent-amber), var(--accent-amber-light)); }
.summary-card.purple::before { background: linear-gradient(90deg, var(--accent-purple), #a78bfa); }

.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-color-hover);
}

.summary-card .card-icon {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--space-3);
}

.summary-card .card-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
    margin-bottom: var(--space-2);
}

.summary-card .card-value {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.summary-card .card-sub {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: var(--space-2);
}

/* --- Filter Bar --- */
.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-6);
    margin-bottom: var(--space-6);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
    min-width: 160px;
}

.filter-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filter-input,
.filter-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    color: var(--text-primary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    transition: border-color var(--transition-fast);
    outline: none;
    width: 100%;
}

.filter-input:focus,
.filter-select:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

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

.filter-actions {
    display: flex;
    gap: var(--space-2);
    align-items: flex-end;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    line-height: 1.5;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-blue-dark));
    color: white;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-blue-light), var(--accent-blue));
    box-shadow: var(--shadow-glow-blue);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.btn-sm {
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
}

/* --- Data Tables --- */
.table-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

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

thead {
    background: rgba(241, 245, 249, 0.85);
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

td {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    vertical-align: middle;
}

tbody tr {
    transition: background-color var(--transition-fast);
}

tbody tr:hover {
    background: rgba(59, 130, 246, 0.05);
}

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

/* Row animation */
tbody tr {
    animation: rowSlideIn var(--transition-base) ease-out;
}

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

/* --- Status Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.badge-shipped {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green-light);
}

.badge-pending {
    background: rgba(245, 158, 11, 0.15);
    color: var(--accent-amber-light);
}

.badge-canceled {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

.badge-default {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-secondary);
}

/* --- Pagination --- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.pagination-info {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.pagination-buttons {
    display: flex;
    gap: var(--space-1);
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 var(--space-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.page-btn:hover:not(.active):not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-color-hover);
}

.page-btn.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

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

/* --- Detail Panel --- */
.detail-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    margin-top: var(--space-4);
    animation: panelSlideDown var(--transition-base) ease-out;
}

@keyframes panelSlideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.detail-label {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.detail-value {
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    font-weight: 500;
}

/* --- Bar Chart (CSS) --- */
.bar-chart {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4) 0;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.bar-label {
    min-width: 140px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-align: right;
    white-space: nowrap;
}

.bar-track {
    flex: 1;
    height: 28px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-blue-light));
    border-radius: var(--radius-sm);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: var(--space-2);
    min-width: fit-content;
}

.bar-value {
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: white;
    white-space: nowrap;
    padding-left: var(--space-2);
}

/* --- Recent Activity Timeline --- */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.timeline-item {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-3) 0;
    border-left: 2px solid var(--border-color);
    margin-left: var(--space-3);
    padding-left: var(--space-5);
    position: relative;
    transition: background-color var(--transition-fast);
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -5px;
    top: calc(var(--space-3) + 4px);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-blue);
    border: 2px solid var(--bg-primary);
}

.timeline-item.purchase::before {
    background: var(--accent-green);
}

.timeline-content {
    flex: 1;
}

.timeline-title {
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
}

.timeline-meta {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: var(--space-1);
}

/* --- Amount formatting --- */
.amount {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.amount-positive {
    color: var(--accent-green-light);
}

/* --- Loading / HTMX indicators --- */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-flex;
}

.loading-spinner {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-8);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    width: 100%;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-card-hover) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    height: 16px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Clickable Row --- */
.clickable-row {
    cursor: pointer;
}

.clickable-row:hover {
    background: rgba(59, 130, 246, 0.08) !important;
}

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-12) var(--space-8);
    color: var(--text-muted);
    text-align: center;
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.empty-state-text {
    font-size: var(--font-size-sm);
}

/* --- Section with two columns --- */
.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: var(--space-6);
}

/* --- Store drill-down --- */
.store-drilldown {
    margin-top: var(--space-4);
    animation: panelSlideDown var(--transition-base) ease-out;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-menu-toggle {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .page-body {
        padding: var(--space-4);
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-4);
    }

    .filter-bar {
        flex-direction: column;
    }

    .filter-group {
        min-width: 100%;
    }

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

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

    .pagination {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .pagination-buttons {
        justify-content: center;
    }

    .bar-label {
        min-width: 80px;
        font-size: var(--font-size-xs);
    }
}

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

/* --- Sidebar overlay for mobile --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* --- Table count badge --- */
.table-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-6);
    border-bottom: 1px solid var(--border-color);
}

.table-count {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.table-count strong {
    color: var(--text-primary);
    font-weight: 600;
}
