:root {
    --bg-dark: #12121a;
    --bg-card: #1e1e2d;
    --text-main: #e2e2e8;
    --text-muted: #9a9cae;
    --accent-gradient: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
    --accent-line: linear-gradient(135deg, #00C300 0%, #00e000 100%);
    --border-color: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(0, 0, 0, 0.2);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'M PLUS Rounded 1c', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.4;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    position: relative;
    padding-bottom: 2rem;
}

/* 隅の独立した設定ボタン */
.settings-corner-btn {
    position: fixed;
    top: 3.5rem;
    right: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
    z-index: 10;
}

.settings-corner-btn:hover {
    color: #fff;
    background: var(--input-bg);
    transform: rotate(45deg) scale(1.05);
    border-color: #4facfe;
}

.test-corner-btn {
    position: fixed;
    top: 7rem;
    right: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    height: 48px;
    padding: 0 1rem;
    border-radius: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
    z-index: 10;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 700;
}

.test-corner-btn:hover {
    color: #fff;
    background: var(--input-bg);
    border-color: #ffb74d;
}

.app-container {
    width: 100%;
    max-width: 900px;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 0.4rem 1rem 1rem;
}

header h1 {
    font-size: 1.4rem;
    text-align: center;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.gradient-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Store Selector (固定：設定ボタンの上) */
.store-selector-fixed {
    position: fixed;
    top: 1rem;
    right: 1.5rem;
    z-index: 10;
}

.store-selector-fixed .store-dropdown {
    min-width: 240px;
    max-width: 320px;
}

/* Store Selector (旧ヘッダー内：非表示) */
.store-selector {
    display: none;
}

.store-dropdown {
    background: var(--input-bg);
    color: #fff;
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    min-width: 150px;
}

.small-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-family: inherit;
}

.small-btn:hover {
    color: #fff;
    border-color: #4facfe;
}

.delete-btn:hover {
    color: #ff4f4f;
    border-color: #ff4f4f;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--bg-card);
    border-radius: 8px;
    padding: 0.3rem;
    margin-bottom: 0.4rem;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.6rem;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s ease;
}

.tab-btn.active {
    background: var(--input-bg);
    color: #fff;
    border: 1px solid #4facfe;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.tab-content {
    display: none;
    height: 100%;
    animation: fadeIn 0.3s ease forwards;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

.modal-tabs-container {
    display: grid;
    grid-template-areas: "stack";
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
}

.modal-tab-content {
    grid-area: stack;
    display: flex;
    flex-direction: column;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
    min-height: max-content;
}

.modal-tab-content.active {
    visibility: visible;
    opacity: 1;
    z-index: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.split-layout {
    display: flex;
    gap: 1rem;
    flex: 1;
}

.left-panel,
.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (max-width: 650px) {
    .split-layout {
        flex-direction: column;
        padding-bottom: 1rem;
    }

    #count .left-panel,
    #count .right-panel {
        display: contents;
    }

    #count .total-card {
        order: 10;
        margin-top: 0;
    }

    /* スタッフ金庫カウント: 枚数→本数→合計 */
    #staff_count .left-panel,
    #staff_count .right-panel {
        display: contents;
    }

    #staff_count .left-panel>.card {
        order: 1;
    }

    #staff_count .right-panel>.card {
        order: 2;
    }

    #staff_count .total-card {
        order: 10;
        margin-top: 0;
    }
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.card-grow {
    flex: 1;
}

.card h2 {
    font-size: 1.05rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.4rem;
    color: #fff;
    font-weight: 700;
}

.description {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 0.8rem;
}

.input-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 0.82rem;
    color: #fff;
    margin-bottom: 0.3rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
}

input[type="number"] {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: #fff;
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 1rem;
    width: 100%;
    outline: none;
    transition: border-color 0.3s;
}

input[type="number"]:focus {
    border-color: #4facfe;
}

.coin-grid {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    flex: 1;
}

.coin-row {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1.5fr;
    gap: 0.8rem;
    align-items: center;
}

.header-row {
    font-size: 0.85rem;
    color: #fff;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
}

.coin-row label {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
}

.total-card {
    background: var(--accent-gradient);
    border-radius: 12px;
    padding: 1.2rem;
    text-align: center;
    color: #fff;
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.2);
    margin-top: auto;
}

.total-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    opacity: 1;
    margin-bottom: 0.3rem;
}

.total-amount {
    font-size: 2.4rem;
    font-weight: 800;
    letter-spacing: 1px;
}

.diff-amount {
    margin-top: 0.6rem;
    font-size: 1.45rem;
    font-weight: 800;
    background: rgba(0, 0, 0, 0.2);
    display: inline-block;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    line-height: 1.5;
}

.diff-amount.diff-plus {
    color: #4dfa73;
    border-color: rgba(77, 250, 115, 0.3);
}

.diff-amount.diff-minus {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}

.result-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    margin-bottom: 0.5rem;
    padding-right: 0.5rem;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.result-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border-color);
    margin: 0;
    list-style: none;
}

.result-list li:last-child {
    border-bottom: none;
}

.total-exchange {
    padding-top: 0.8rem;
    border-top: 2px dashed rgba(255, 255, 255, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
}

.total-exchange strong {
    font-size: 1.4rem;
    color: #4facfe;
    margin-left: auto;
    text-align: right;
}

.source-item {
    color: var(--text-muted);
}

.source-item span:first-child {
    font-size: 0.9rem;
}

.source-item span.value {
    color: #fff;
    font-weight: 500;
}

.source-item.highlight {
    background: rgba(79, 172, 254, 0.1);
    border-radius: 6px;
    padding: 0.6rem;
    margin: 0.4rem 0;
    border-left: 3px solid #4facfe;
}

.source-item.highlight span.value {
    color: #4facfe;
    font-weight: 700;
}

.source-item.return span.value {
    color: #e2a0ff;
    font-weight: 700;
}

.primary-btn {
    width: 100%;
    padding: 0.9rem;
    border: none;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
}

.primary-btn:active {
    transform: scale(0.98);
}

.line-btn {
    background: var(--accent-line);
}

/* モーダル (設定用) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 1.5rem;
    width: 90%;
    max-width: 600px;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-overlay.show .modal-content {
    transform: translateY(0) scale(1);
}

/* .header-row moved and refined above */

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.8rem;
}

.modal-header h2 {
    font-size: 1.2rem;
    color: #fff;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s, transform 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
}

.close-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    transform: rotate(90deg);
}

.settings-total {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(79, 172, 254, 0.1);
    border-radius: 8px;
    border-left: 4px solid #4facfe;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}

.settings-total strong {
    font-size: 1.5rem;
    color: #4facfe;
}

/* 認証画面 */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.auth-overlay.hidden {
    display: none;
}

.auth-box {
    background: var(--bg-card);
    padding: 2.5rem;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-color);
}

/* 汚破損・鑑定中紙幣セクション */
.damaged-bills-section {
    margin-top: 0.8rem;
    padding: 0.7rem 0.8rem;
    background: rgba(255, 193, 7, 0.07);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 8px;
}

.damaged-bills-label {
    font-size: 0.78rem;
    color: #ffc107;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: 0.01em;
}

.damaged-bills-section input[type="number"] {
    border-color: rgba(255, 193, 7, 0.3);
}

.damaged-bills-section input[type="number"]:focus {
    border-color: #ffc107;
}