/* ============================================
   確定申告 売上管理
   ============================================ */

.sales-tracking {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ヘッダー */
.st-header {
    margin-bottom: 24px;
}
.st-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 4px;
}
.st-subtitle {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0;
}

/* ナビゲーション */
.st-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.st-nav-left, .st-nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* 期間セレクター（リデザイン） */
.st-period-selector {
    display: inline-flex;
    align-items: center;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    overflow: hidden;
}
.st-period-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 40px;
    font-size: 1.3rem;
    color: #64748b;
    text-decoration: none;
    transition: all 0.15s;
    user-select: none;
}
.st-period-arrow:hover {
    background: #f1f5f9;
    color: #1e293b;
}
.st-period-display {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    height: 40px;
    cursor: pointer;
    border-left: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    transition: background 0.15s;
    user-select: none;
}
.st-period-display:hover {
    background: #f8fafc;
}
.st-period-text {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
}
.st-period-chevron {
    color: #94a3b8;
    transition: transform 0.2s;
    flex-shrink: 0;
}
.st-period-dropdown-open .st-period-chevron {
    transform: rotate(180deg);
}

/* 月選択ドロップダウン */
.st-period-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 100;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    padding: 12px;
    min-width: 260px;
}
.st-period-dropdown.st-dropdown-visible {
    display: block;
}
.st-nav-left {
    position: relative;
}
.st-dropdown-year-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 10px;
}
.st-dropdown-year {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    min-width: 60px;
    text-align: center;
}
.st-dropdown-year-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    font-size: 1.1rem;
    color: #64748b;
    cursor: pointer;
    transition: all 0.15s;
}
.st-dropdown-year-arrow:hover {
    background: #f1f5f9;
    color: #1e293b;
}
.st-dropdown-months {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}
.st-dropdown-month {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #374151;
    text-decoration: none;
    transition: all 0.15s;
}
.st-dropdown-month:hover {
    background: #eef2ff;
    color: #4f46e5;
}
.st-dropdown-month-active {
    background: #4f46e5;
    color: #fff;
    font-weight: 600;
}
.st-dropdown-month-active:hover {
    background: #4338ca;
    color: #fff;
}
.st-dropdown-today {
    display: block;
    text-align: center;
    padding: 8px;
    font-size: 0.8rem;
    color: #4f46e5;
    text-decoration: none;
    border-top: 1px solid #e2e8f0;
    padding-top: 10px;
}
.st-dropdown-today:hover {
    text-decoration: underline;
}

/* ビュー切替トグル */
.st-view-toggle {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 3px;
}
.st-view-btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    color: #64748b;
    text-decoration: none;
    transition: all 0.15s;
}
.st-view-btn:hover {
    color: #374151;
}
.st-view-btn-active {
    background: #fff;
    color: #4f46e5;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ボタン */
.st-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.st-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}
.st-btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}
.st-btn-primary {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
}
.st-btn-primary:hover {
    background: #4338ca;
    border-color: #4338ca;
}
.st-btn-active {
    background: #eef2ff;
    color: #4f46e5;
    border-color: #4f46e5;
}
.st-btn-danger {
    color: #dc2626;
    border-color: #fca5a5;
}
.st-btn-danger:hover {
    background: #fef2f2;
    border-color: #dc2626;
}
.st-btn-edit {
    color: #2563eb;
    border-color: #93c5fd;
}
.st-btn-edit:hover {
    background: #eff6ff;
}
.st-btn-icon {
    padding: 8px 12px;
}

/* サマリーカード */
.st-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.st-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.st-card-label {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 6px;
}
.st-card-value {
    font-size: 1.5rem;
    font-weight: 700;
}
.st-card-income .st-card-value { color: #059669; }
.st-card-expense .st-card-value { color: #dc2626; }
.st-card-profit .st-card-value { color: #2563eb; }
.st-card-loss .st-card-value { color: #dc2626; }

/* セクション */
.st-section {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid #e5e7eb;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.st-section h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e5e7eb;
}
.st-section-header {
    margin-bottom: 0;
}
.st-section-header h2 {
    margin-bottom: 12px;
}

/* 検索ボックス */
.st-search-box {
    position: relative;
    margin-bottom: 16px;
}
.st-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none;
}
.st-search-input {
    width: 100%;
    padding: 10px 36px 10px 38px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.88rem;
    font-family: inherit;
    background: #f8fafc;
    box-sizing: border-box;
    transition: all 0.15s;
}
.st-search-input:focus {
    outline: none;
    border-color: #4f46e5;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(79,70,229,0.12);
}
.st-search-input::placeholder {
    color: #94a3b8;
}
.st-search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.st-search-clear:hover {
    color: #475569;
}
.st-search-count {
    font-size: 0.78rem;
    color: #64748b;
    margin-bottom: 12px;
    padding-left: 2px;
}
.st-search-no-results {
    text-align: center;
    padding: 32px 16px;
    color: #94a3b8;
    font-size: 0.9rem;
    display: none;
}

/* チャート */
.st-chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

/* テーブル */
.st-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.st-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.st-table th, .st-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
}
.st-table thead th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    position: sticky;
    top: 0;
}
.st-table tfoot th {
    background: #f1f5f9;
    font-weight: 700;
}
.st-table tbody tr:hover {
    background: #f8fafc;
}
.st-table tbody tr.st-row-hidden {
    display: none;
}
.text-right { text-align: right; }

/* 収入・経費カラー */
.st-income { color: #059669; font-weight: 600; }
.st-expense { color: #dc2626; font-weight: 600; }

/* バッジ */
.st-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}
.st-badge-income { background: #d1fae5; color: #065f46; }
.st-badge-expense { background: #fee2e2; color: #991b1b; }

/* リンク */
.st-link {
    color: #4f46e5;
    text-decoration: none;
    font-size: 0.8rem;
}
.st-link:hover { text-decoration: underline; }

/* アクション */
.st-actions {
    display: flex;
    gap: 4px;
    white-space: nowrap;
}
.st-inline-form { display: inline; }

/* カテゴリグリッド */
.st-category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.st-category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.st-category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: 6px;
}
.st-category-name {
    font-size: 0.85rem;
    color: #475569;
}
.st-category-amount {
    font-size: 0.9rem;
    font-weight: 600;
}

/* 空メッセージ */
.st-empty {
    text-align: center;
    color: #94a3b8;
    padding: 40px 20px;
    font-size: 0.9rem;
}

/* 確定申告セクション */
.st-tax-section {
    background: linear-gradient(135deg, #fefce8, #fef9c3);
    border-color: #fde047;
}
.st-tax-note {
    font-size: 0.78rem;
    color: #92400e;
    margin-bottom: 16px;
    line-height: 1.6;
}
.st-tax-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.st-tax-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255,255,255,0.7);
    border-radius: 6px;
}
.st-tax-label {
    font-size: 0.85rem;
    color: #475569;
}
.st-tax-value {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
}
.st-tax-divider {
    border-top: 2px solid #d1d5db;
    margin-top: 4px;
    padding-top: 12px;
}
.st-tax-total {
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid #a5b4fc;
}
.st-tax-total .st-tax-label {
    font-weight: 700;
    color: #1e293b;
}
.st-tax-total .st-tax-value {
    font-size: 1.2rem;
}

/* モーダル（モバイル対応改善） */
.st-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
.st-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.st-modal-content {
    position: relative;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.15);
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.st-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.st-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #1e293b;
}
.st-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 6px;
    transition: all 0.15s;
}
.st-modal-close:hover {
    color: #475569;
    background: #f1f5f9;
}
.st-modal-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
}
.st-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    background: #fff;
}

/* フォーム */
.st-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.st-form-group {
    margin-bottom: 14px;
}
.st-form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}
.st-required {
    color: #dc2626;
}
.st-form-group input,
.st-form-group select,
.st-form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    box-sizing: border-box;
    -webkit-appearance: none;
}
.st-form-group input:focus,
.st-form-group select:focus,
.st-form-group textarea:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
}

/* モバイル非表示ヘルパー */
.st-hide-mobile { display: inline; }

/* レスポンシブ */
@media (max-width: 768px) {
    .sales-tracking { padding: 12px; }

    .st-header { margin-bottom: 16px; }
    .st-header h1 { font-size: 1.3rem; }

    .st-nav {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .st-nav-left {
        justify-content: center;
    }
    .st-nav-right {
        justify-content: center;
        flex-wrap: wrap;
    }
    .st-hide-mobile { display: none; }

    /* 期間セレクター モバイル */
    .st-period-selector {
        flex: 0 0 auto;
    }
    .st-period-dropdown {
        left: 50%;
        transform: translateX(-50%);
        min-width: 240px;
    }

    .st-summary-cards { grid-template-columns: 1fr; gap: 10px; }
    .st-card { padding: 14px; }
    .st-card-value { font-size: 1.3rem; }

    .st-category-grid { grid-template-columns: 1fr; }
    .st-form-row { grid-template-columns: 1fr; }
    .st-table { font-size: 0.78rem; }
    .st-table th, .st-table td { padding: 8px 6px; }
    .st-chart-container { height: 220px; }
    .st-section { padding: 14px; }
    .st-section h2 { font-size: 0.95rem; }

    /* モーダル モバイル最適化 */
    .st-modal {
        align-items: flex-end;
    }
    .st-modal-content {
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
        border-radius: 16px 16px 0 0;
    }
    .st-modal-body {
        padding: 16px;
    }
    .st-modal-footer {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    /* 税金セクション */
    .st-tax-item { padding: 8px 10px; }
    .st-tax-label { font-size: 0.78rem; }
    .st-tax-value { font-size: 0.88rem; }
    .st-tax-total .st-tax-value { font-size: 1rem; }

    /* 検索ボックス */
    .st-search-input {
        font-size: 16px; /* iOSズーム防止 */
    }
}

/* PC用モーダル */
@media (min-width: 769px) {
    .st-modal {
        align-items: center;
    }
    .st-modal-content {
        border-radius: 12px;
        max-height: 90vh;
    }
}

/* タッチデバイス用ホバー無効化 */
@media (hover: none) {
    .st-btn:hover {
        background: #fff;
        border-color: #d1d5db;
    }
    .st-btn-primary:hover {
        background: #4f46e5;
        border-color: #4f46e5;
    }
}
