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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
    background: #f0f2f5;
    color: #333;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
}

/* ===== Sidebar Layout ===== */

/* モバイル用ヘッダー (デスクトップでは非表示) */
.app-header {
    display: none;
    background: #1a56a0;
    color: #fff;
    padding: 12px 16px;
    align-items: center;
    gap: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}
.app-header h1 { font-size: 1.1rem; font-weight: 600; }

.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 1px;
}

/* サイドバー */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100dvh;
    background: #1a56a0;
    color: #fff;
    display: flex;
    flex-direction: column;
    z-index: 200;
    overflow-y: auto;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}

.sidebar-header {
    padding: 18px 14px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
}
.sidebar-appname {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.2;
}
.sidebar-appsub {
    font-size: 0.68rem;
    opacity: 0.7;
    margin-top: 2px;
    line-height: 1.3;
}
.sidebar-close {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.75);
    padding: 4px;
    line-height: 1;
    flex-shrink: 0;
}
.sidebar-close:hover { color: #fff; }

.sidebar-user {
    padding: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
}
.sidebar-email {
    font-size: 0.78rem;
    opacity: 0.8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 8px;
}
.sidebar-usage {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.header-usage {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    opacity: 0.9;
}
.header-usage-plan {
    background: rgba(255,255,255,0.15);
    border-radius: 4px;
    padding: 2px 8px;
    white-space: nowrap;
}
.header-usage-count { white-space: nowrap; }
.header-usage-count.usage-warn   { color: #fde68a; }
.header-usage-count.usage-danger { color: #fca5a5; font-weight: 600; }

.sidebar-nav {
    padding: 8px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-footer {
    padding: 8px 8px 14px;
    border-top: 1px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
}
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 7px;
    font-size: 0.87rem;
    font-weight: 500;
    color: rgba(255,255,255,0.88);
    text-decoration: none;
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}
.sidebar-nav-item:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}
.sidebar-nav-item.active {
    background: rgba(255,255,255,0.2);
    color: #fff;
    font-weight: 600;
}
.sidebar-logout { color: rgba(255,200,200,0.9); }
.sidebar-logout:hover { background: rgba(220,53,69,0.25); color: #fca5a5; }

/* サイドバーオーバーレイ (モバイル) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 150;
}
.sidebar-overlay.active { display: block; }

/* メインコンテンツ */
.main-content { margin-left: 240px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }

/* モバイル: サイドバーをスライドイン式に */
@media (max-width: 900px) {
    .app-header { 
        display: flex; 
        justify-content: space-between;
    }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: flex; align-items: center; justify-content: center; }
    .main-content { margin-left: 0; }
}

/* ===== Cards ===== */
.card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    margin-bottom: 20px;
    overflow: hidden;
}
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8f9fb;
}
.card-header .step-badge {
    background: #1a56a0;
    color: #fff;
    border-radius: 50%;
    width: 22px; height: 22px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700; flex-shrink: 0;
}
.card-body { padding: 20px; }

/* ===== Form Controls ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; color: #555; }
.form-group input, .form-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d0d5dd;
    border-radius: 6px;
    font-size: 16px;
    transition: border-color 0.2s;
    outline: none;
}
.form-group input:focus, .form-group select:focus { border-color: #1a56a0; box-shadow: 0 0 0 3px rgba(26,86,160,0.1); }
.form-group .hint { font-size: 0.8rem; color: #888; margin-top: 4px; }

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

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    border-radius: 6px;
    font-size: 14px; font-weight: 500;
    cursor: pointer; border: none;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #1a56a0; color: #fff; }
.btn-primary:hover { background: #154690; }
.btn-primary:disabled { background: #9ab0cc; cursor: not-allowed; transform: none; }
.btn-success { background: #2d8a4e; color: #fff; }
.btn-success:hover { background: #247040; }
.btn-success:disabled { background: #9ac4a8; cursor: not-allowed; }
.btn-secondary { background: #f0f2f5; color: #555; border: 1px solid #d0d5dd; }
.btn-secondary:hover { background: #e4e7ec; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== Progress & Status ===== */
.status-bar {
    padding: 12px 20px;
    background: #eef4fd;
    border-left: 4px solid #1a56a0;
    border-radius: 0 6px 6px 0;
    margin-top: 10px;
    margin-bottom: 16px;
    display: none;
}
.status-bar.active { display: flex; align-items: center; gap: 10px; }
.status-bar.error { background: #fef2f2; border-color: #dc3545; }
.status-bar.success { background: #f0fdf4; border-color: #2d8a4e; }

.progress-wrap { width: 100%; }
.progress-bar-outer {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-bar-inner {
    height: 100%;
    background: #1a56a0;
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

/* ===== Results Table ===== */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}
.results-count { font-weight: 600; color: #555; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
table thead th {
    background: #f8f9fb;
    border-bottom: 2px solid #e2e8f0;
    padding: 10px 8px;
    text-align: left;
    font-weight: 600;
    color: #555;
    white-space: nowrap;
}
table tbody tr { border-bottom: 1px solid #f0f2f5; }
table tbody tr:hover { background: #fafbfd; }
table tbody td { padding: 8px; vertical-align: middle; }

table input[type="text"], table input[type="date"], table input[type="number"], table select {
    width: 100%;
    padding: 5px 7px;
    border: 1px solid #d0d5dd;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    background: #fff;
}
table input:focus, table select:focus {
    border-color: #1a56a0;
    box-shadow: 0 0 0 2px rgba(26,86,160,0.1);
}

.col-date    { min-width: 110px; position: relative; }
.col-amount  { min-width: 90px; }
.col-account { min-width: 120px; }
.col-credit  { min-width: 110px; }
.col-desc    { min-width: 160px; }
.col-actions { min-width: 60px; text-align: center; }

/* ===== File List ===== */
.file-list { list-style: none; }
.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 4px;
    background: #f8f9fb;
    font-size: 13px;
}
.file-item .file-status {
    width: 20px; height: 20px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; flex-shrink: 0;
}
.file-item.pending   .file-status { background: #e2e8f0; color: #888; }
.file-item.analyzing .file-status { background: #dbeafe; color: #1a56a0; }
.file-item.done      .file-status { background: #dcfce7; color: #2d8a4e; }
.file-item.error     .file-status { background: #fee2e2; color: #dc3545; }
.file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .file-msg  { font-size: 11px; color: #888; }

/* ===== Settings section ===== */
.settings-toggle { cursor: pointer; user-select: none; }
.settings-toggle:hover { text-decoration: underline; }
.settings-body { display: none; padding-top: 16px; border-top: 1px solid #eee; margin-top: 16px; }
.settings-body.open { display: block; }

/* ===== Empty state ===== */
.empty-state {
    text-align: center; padding: 40px; color: #aaa;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-state svg { opacity: 0.3; }

/* ===== Spinner ===== */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    width: 16px; height: 16px;
    border: 2px solid #bbb;
    border-top-color: #1a56a0;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
.status-bar.success .spinner,
.status-bar.error .spinner {
    display: none;
}
.status-icon {
    display: none;
    width: 16px; height: 16px;
    flex-shrink: 0;
    font-size: 16px;
    line-height: 1;
}
.status-bar.success .status-icon { display: inline-block; }
.status-bar.error .status-icon   { display: inline-block; }

/* ===== Password Input ===== */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 42px; }
.toggle-pw {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; color: #9ca3af;
    padding: 4px; line-height: 0;
}
.toggle-pw:hover { color: #555; }

/* ===== Download Nudge Banner ===== */
.download-nudge {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    margin-top: 14px;
    background: #fffbeb;
    border: 1.5px solid #fbbf24;
    border-radius: 10px;
    color: #92400e;
    font-size: .88rem;
    animation: nudgePulse 2.4s ease-in-out infinite;
}
.download-nudge strong { display: block; margin-bottom: 2px; font-size: .9rem; }

.btn-warning {
    background: #f59e0b;
    color: #fff;
    border: none;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.btn-warning:hover { background: #d97706; }

@keyframes nudgePulse {
    0%, 100% { border-color: #fbbf24; box-shadow: none; }
    50%       { border-color: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,.18); }
}

/* ===== Misc ===== */
.text-muted { color: #888; }
.text-success { color: #2d8a4e; }
.text-danger  { color: #dc3545; }
.mt-2 { margin-top: 8px; }
.hidden { display: none !important; }

.action-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top:5px; }

/* ===== Usage Widget ===== */
.usage-widget {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    padding: 16px 20px;
    margin-bottom: 20px;
}
.usage-loading { color: #aaa; font-size: 0.85rem; }

.usage-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 16px;
    align-items: center;
}
@media (max-width: 700px) {
    .usage-grid { grid-template-columns: 1fr 1fr; }
}

.usage-stat { }
.usage-stat .label {
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.usage-stat .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1a56a0;
}
.usage-stat .value.warn  { color: #d97706; }
.usage-stat .value.danger { color: #dc3545; }
.usage-stat .sub {
    font-size: 0.75rem;
    color: #888;
    margin-top: 2px;
}

.usage-meter { flex: 1; min-width: 160px; }
.usage-meter .meter-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #555;
    margin-bottom: 5px;
}
.usage-meter .meter-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}
.usage-meter .meter-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
    background: #1a56a0;
}
.usage-meter .meter-fill.warn   { background: #d97706; }
.usage-meter .meter-fill.danger { background: #dc3545; }

.usage-limit-banner {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.9rem;
    color: #991b1b;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Usage History Modal ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-box {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    width: 90%; max-width: 500px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal-box h3 { margin-bottom: 16px; font-size: 1rem; }
.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th {
    background: #f8f9fb; padding: 8px;
    text-align: left; border-bottom: 2px solid #e2e8f0;
    font-weight: 600; color: #555;
}
.history-table td { padding: 8px; border-bottom: 1px solid #f0f2f5; }
.modal-close-btn { margin-top: 16px; }
