:root {
    /* Color Palette - Premium & Modern */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #10b981;
    --accent: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --error: #ef4444;

    /* Gradients */
    --grad-primary: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --grad-surface: linear-gradient(180deg, rgba(255, 255, 255, 1) 0%, rgba(248, 250, 252, 1) 100%);

    /* Elevations */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-premium: 0 20px 25px -5px rgb(0 0 0 / 0.05), 0 8px 10px -6px rgb(0 0 0 / 0.05);

    /* Transitions */
    --transit: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Layout */
    --border-radius: 16px;
    --header-height: 62px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.5;
    overflow-x: hidden;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Components */
.card {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transit);
    border: 1px solid var(--border);
}

.card:active {
    transform: scale(0.98);
}

.card.detailed-view {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    padding: 0 !important;
    width: 100% !important;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* 顧客枠、メモ枠などの共通スタイル（角丸ボックス化） */
.card.detailed-view .site-box,
.card.detailed-view .notes-area {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    margin: 0;
    width: 100%;
    box-shadow: var(--shadow-sm);
}

.card.detailed-view .site-box.main {
    border-left: 4px solid var(--error) !important;
    background-color: #fee2e2 !important;
}

.card.detailed-view .site-box.secondary {
    border-left: 4px solid var(--primary-light) !important;
    background-color: #e0e7ff !important;
}

/* 画像リストの角丸調整 */
.card.detailed-view .image-vertical-list {
    margin: 0.5rem 0 0 0 !important;
    width: 100%;
}

.card.detailed-view .list-image-item {
    border-radius: 12px;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    width: 100%;
    height: auto;
}

/* メモ欄の背景色調整 */
.card.detailed-view .notes-area {
    background: #fffbeb !important;
    border: 1px solid #fef3c7 !important;
}

/* 画像追加ボタンの背景色（薄いグレー） */
.card.detailed-view .add-image-btn {
    background: #f1f5f9 !important;
    border: 1px dashed var(--border) !important;
    color: var(--text-muted) !important;
    width: 100% !important;
    padding: 0.6rem 1.2rem !important;
    border-radius: 8px !important;
    font-size: 0.875rem !important;
    cursor: pointer !important;
}

.card.detailed-view .action-bar {
    border-top: none !important;
    padding-top: 0.5rem;
    padding-right: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.875rem 1.5rem;
    /* モバイル向けに少し拡大 */
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transit);
    gap: 0.5rem;
    min-height: 48px;
    /* タッチ領域の確保 */
}

.btn-primary {
    background: var(--grad-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    box-shadow: var(--shadow-lg);
    opacity: 0.9;
}

.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 64px;
    height: 64px;
    border-radius: 32px;
    background: var(--grad-primary);
    color: white;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

/* Header */
header {
    height: var(--header-height);
    background: var(--surface);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

/* Sticky Controls Container */
.sticky-controls {
    position: sticky;
    top: var(--header-height);
    z-index: 40;
    background-color: var(--background);
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 0.5rem 1.5rem 0;
}

.stat-card {
    background: var(--grad-primary);
    color: white;
    padding: 1.25rem;
    border-radius: var(--border-radius);
}

/* Customer List */
.customer-list {
    padding: 0 1.5rem 5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.customer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
}

.customer-info h3 {
    font-size: 1rem;
}

/* Modal / Overlay */
.overlay {
    position: absolute;
    /* 編集画面などの通常のオーバーレイ */
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    background: var(--background);
    display: none;
    z-index: 200;
}

.overlay-fixed {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    /* 半透明背景 */
    display: none;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.no-scroll {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
}

.modal {
    background: var(--background);
    /* ページの背景色と同じ */
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    /* 全画面なので丸角なし */
    padding: 0;
    /* paddingは内部要素で制御 */
    overflow-y: auto;
    animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    -webkit-overflow-scrolling: touch;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

#guide-bubble::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    border-width: 8px 8px 0;
    border-style: solid;
    border-color: var(--primary) transparent transparent;
}

/* Search Bar */
.search-container {
    padding: 5px 1.5rem 1rem;
    background-color: var(--background);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.search-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: 0.875rem 3rem 0.875rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 1rem;
}

.search-back-btn {
    position: absolute;
    right: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transit);
}

.search-back-btn:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.search-back-btn:active {
    transform: scale(0.9);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* Form Styles */
.form-section {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.form-section-header {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.form-section.main {
    border-left: 4px solid var(--error);
    background-color: #fee2e2;
}

.form-section.secondary {
    border-left: 4px solid var(--primary-light);
    background-color: #e0e7ff;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #f8fafc;
    font-size: 16px;
    /* iOS でのオートズーム防止 */
    transition: var(--transit);
}

/* Image Grid and Preview Styles */
.image-preview-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    z-index: 10;
}

/* Image List Styles */
.image-vertical-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.list-image-item {
    width: 100%;
    border-radius: 8px;
    height: auto;
}

/* Search Result Layout Improvements */
.info-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.info-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    font-size: 0.9375rem;
}

.info-content {
    flex: 1;
    color: var(--text-main);
}

.info-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 0.125rem;
}

.site-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.5rem;
}

.site-box.main {
    border-left: 4px solid var(--error);
    background-color: #fee2e2 !important;
}

.site-box.secondary {
    border-left: 4px solid var(--primary-light);
    background-color: #e0e7ff !important;
}

.notes-area {
    background: #fffbeb;
    border: 1px solid #fef3c7;
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.card-header {
    border-bottom: 1px dashed var(--border);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* Image Viewer Overlay */
.viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.viewer-overlay img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

.viewer-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    color: white;
    font-size: 2.5rem;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    z-index: 2001;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* QR Modal Specific */
#qr-modal-overlay {
    align-items: center !important;
    /* 強制的に中央配置 */
    justify-content: center !important;
}

.qr-modal {
    max-width: 340px;
    width: 90%;
    margin: 0 auto;
    text-align: center;
    border-radius: 20px;
    /* 四隅を丸く */
    transform: none;
    /* ボトムシートのアニメーションをキャンセル */
    animation: fadeIn 0.3s ease;
}

#qrcode img {
    margin: 0 auto;
    border: 8px solid white;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* Animations and Helpers */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spin {
    animation: spin 1s linear infinite;
}

#server-status-indicator {
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

/* Edit View (Page Mode) */
#edit-view {
    width: 100%;
    min-height: 100vh;
    background: var(--background);
    color: var(--text-main);
}

/* Image List Styles */
.image-vertical-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.list-image-item {
    width: 100%;
    border-radius: 8px;
    height: auto;
}

/* Search Result Layout Improvements */
.info-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.info-row {
    display: flex;
    flex-direction: column;
    gap: 0;
    font-size: 0.9375rem;
}

.info-content {
    flex: 1;
    color: var(--text-main);
}

.info-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 0.125rem;
}

.site-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.5rem;
}

.site-box.main {
    border-left: 4px solid var(--error);
    background-color: #fee2e2 !important;
}

.site-box.secondary {
    border-left: 4px solid var(--primary-light);
    background-color: #e0e7ff !important;
}

.notes-area {
    background: #fffbeb;
    border: 1px solid #fef3c7;
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.5rem;
}

.card-header {
    border-bottom: 1px dashed var(--border);
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* Image Viewer Overlay */
.viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.viewer-overlay img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

.viewer-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    color: white;
    font-size: 2.5rem;
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    z-index: 2001;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* QR Modal Specific */
#qr-modal-overlay {
    align-items: center !important;
    /* 強制的に中央配置 */
    justify-content: center !important;
}

.qr-modal {
    max-width: 340px;
    width: 90%;
    margin: 0 auto;
    text-align: center;
    border-radius: 20px;
    /* 四隅を丸く */
    transform: none;
    /* ボトムシートのアニメーションをキャンセル */
    animation: fadeIn 0.3s ease;
}

#qrcode img {
    margin: 0 auto;
    border: 8px solid white;
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
}

/* Animations and Helpers */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spin {
    animation: spin 1s linear infinite;
}

#server-status-indicator {
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

/* Edit View (Page Mode) */
#edit-view {
    width: 100%;
    min-height: 100vh;
    background: var(--background);
    animation: fadeIn 0.3s ease;
}

#edit-view header {
    justify-content: space-between;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.sync-pulse {
    animation: pulse 1.5s infinite ease-in-out;
}