/* ============================================================
   teru Design System
   Tone: 静謐な知性 — 声を張らずに伝わるUI
   Base: 8px grid, 18px body, slate palette
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;600;700&family=Source+Serif+4:ital,wght@0,400;0,600;1,400&display=swap');

:root {
    /* Color — Slate + Ink */
    --c-bg:        #f8f9fb;
    --c-surface:   #ffffff;
    --c-border:    #e8eaef;
    --c-border-focus: #2b70ef;
    --c-text:      #1e293b;
    --c-text-sub:  #64748b;
    --c-text-mute: #94a3b8;
    --c-accent:    #2b70ef;
    --c-accent-hover: #1d5fd4;
    --c-accent-soft: #eff4ff;
    --c-success:   #059669;
    --c-success-bg:#ecfdf5;
    --c-warn:      #d97706;
    --c-warn-bg:   #fffbeb;
    --c-error:     #dc2626;
    --c-error-bg:  #fef2f2;

    /* Spacing — 8px grid */
    --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
    --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
    --s-12: 48px; --s-16: 64px;

    /* Radius */
    --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-full: 999px;

    /* Shadow */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06), 0 0 0 1px rgba(0,0,0,0.02);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);

    /* Transition */
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --duration: 180ms;
}

/* ---- Reset ---- */
*, *::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: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    font-weight: 400;
    background: var(--c-bg);
    color: var(--c-text);
    line-height: 1.8;
    letter-spacing: 0.01em;
}

/* スピンボタン非表示 */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

a { color: var(--c-accent); text-decoration: none; transition: color var(--duration) var(--ease); }
a:hover { color: var(--c-accent-hover); }

/* ============================================================
   Header
   ============================================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--c-border);
    height: 56px;
    display: flex;
    align-items: center;
    padding: 0 var(--s-6);
}
.header-inner {
    width: 100%;
    max-width: 1024px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--c-text);
    text-decoration: none;
    letter-spacing: -0.02em;
}
.logo span {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.6875rem;
    font-weight: 400;
    color: var(--c-text-mute);
    margin-left: var(--s-2);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.header-nav { display: flex; gap: var(--s-1); align-items: center; }
.header-nav a {
    color: var(--c-text-sub);
    font-size: 0.8125rem;
    font-weight: 500;
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-sm);
    transition: all var(--duration) var(--ease);
}
.header-nav a:hover {
    color: var(--c-text);
    background: var(--c-accent-soft);
}

/* ============================================================
   Main Container
   ============================================================ */
.app-main {
    max-width: 1024px;
    margin: 0 auto;
    padding: var(--s-8) var(--s-6) var(--s-16);
}

/* ============================================================
   Page Title
   ============================================================ */
h2 {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--c-text);
}

/* ============================================================
   Alerts
   ============================================================ */
.alert {
    padding: var(--s-3) var(--s-4);
    border-radius: var(--r-md);
    margin-bottom: var(--s-4);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.6;
    border-left: 3px solid;
    animation: alertIn 0.3s var(--ease);
}
@keyframes alertIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}
.alert-success { background: var(--c-success-bg); color: var(--c-success); border-color: var(--c-success); }
.alert-error { background: var(--c-error-bg); color: var(--c-error); border-color: var(--c-error); }

/* ============================================================
   Card
   ============================================================ */
.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    padding: var(--s-6);
    margin-bottom: var(--s-6);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--duration) var(--ease);
}
.card-title {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--c-text);
    margin-bottom: var(--s-4);
    letter-spacing: 0.02em;
}

/* ============================================================
   Stat Cards (Dashboard)
   ============================================================ */
.stat-value {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 2.25rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.03em;
}
.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--c-text-mute);
    margin-top: var(--s-2);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--s-2);
    padding: var(--s-2) var(--s-4);
    height: 36px;
    border-radius: var(--r-sm);
    font-size: 0.8125rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--duration) var(--ease);
    white-space: nowrap;
}
.btn-primary {
    background: var(--c-text);
    color: var(--c-surface);
    border-color: var(--c-text);
}
.btn-primary:hover {
    background: #334155;
    border-color: #334155;
    color: var(--c-surface);
    box-shadow: var(--shadow-md);
}
.btn-secondary {
    background: var(--c-surface);
    color: var(--c-text);
    border-color: var(--c-border);
}
.btn-secondary:hover {
    background: var(--c-bg);
    border-color: #cbd5e1;
}
.btn-danger {
    background: var(--c-surface);
    color: var(--c-error);
    border-color: #fecaca;
}
.btn-danger:hover {
    background: var(--c-error-bg);
    border-color: var(--c-error);
}
.btn-sm {
    height: 28px;
    padding: 0 var(--s-3);
    font-size: 0.75rem;
}

/* ============================================================
   Upload Dropzone
   ============================================================ */
.upload-dropzone {
    border: 1.5px dashed var(--c-border);
    border-radius: var(--r-lg);
    padding: var(--s-16) var(--s-8);
    text-align: center;
    cursor: pointer;
    transition: all 0.25s var(--ease);
    position: relative;
}
.upload-dropzone::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: var(--r-lg);
    opacity: 0;
    background: var(--c-accent-soft);
    transition: opacity 0.25s var(--ease);
    z-index: 0;
}
.upload-dropzone:hover::before,
.upload-dropzone.dragover::before { opacity: 1; }
.upload-dropzone:hover,
.upload-dropzone.dragover { border-color: var(--c-accent); }
.upload-dropzone * { position: relative; z-index: 1; }
.upload-dropzone .icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: var(--s-3);
    filter: grayscale(0.3);
}
.upload-dropzone p {
    color: var(--c-text-sub);
    font-size: 0.875rem;
    margin-bottom: var(--s-4);
}

/* ============================================================
   Progress
   ============================================================ */
.progress-container { margin-top: var(--s-6); }
.progress-bar {
    width: 100%;
    height: 3px;
    background: var(--c-border);
    border-radius: 2px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--c-accent);
    border-radius: 2px;
    width: 0%;
    transition: width 0.4s var(--ease);
}
.progress-text {
    margin-top: var(--s-3);
    font-size: 0.8125rem;
    color: var(--c-text-sub);
    text-align: center;
}

/* ============================================================
   Tables
   ============================================================ */
.table-responsive { overflow-x: auto; margin: 0 calc(var(--s-1) * -1); }
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: var(--s-3) var(--s-4);
    text-align: left;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--c-border);
}
th {
    font-weight: 500;
    color: var(--c-text-mute);
    font-size: 0.6875rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: transparent;
    border-bottom-width: 2px;
}
td { color: var(--c-text); vertical-align: middle; }
td a { font-weight: 500; }
tbody tr { transition: background var(--duration) var(--ease); }
tbody tr:hover { background: var(--c-bg); }

/* ============================================================
   Status Badge
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px var(--s-3);
    border-radius: var(--r-full);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.badge-completed { background: var(--c-success-bg); color: var(--c-success); }
.badge-completed::before { background: var(--c-success); }
.badge-processing { background: var(--c-warn-bg); color: var(--c-warn); }
.badge-processing::before { background: var(--c-warn); animation: pulse-dot 1.5s infinite; }
.badge-error { background: var(--c-error-bg); color: var(--c-error); }
.badge-error::before { background: var(--c-error); }
.badge-uploading { background: #eff6ff; color: #2563eb; }
.badge-uploading::before { background: #2563eb; animation: pulse-dot 1.5s infinite; }
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: var(--s-5); }
.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--c-text-sub);
    margin-bottom: var(--s-1);
    letter-spacing: 0.04em;
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: var(--s-2) var(--s-3);
    height: 40px;
    border: 1px solid var(--c-border);
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--c-text);
    background: var(--c-surface);
    transition: all var(--duration) var(--ease);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--c-border-focus);
    box-shadow: 0 0 0 3px rgba(43,112,239,0.08);
}
.form-group input::placeholder { color: var(--c-text-mute); }
.form-group select { cursor: pointer; }
.form-group textarea { height: auto; min-height: 80px; resize: vertical; }

/* Inline table inputs */
table input, table select {
    padding: var(--s-1) var(--s-2);
    height: 34px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: 0.8125rem;
    color: var(--c-text);
    background: transparent;
    transition: all var(--duration) var(--ease);
}
table input:hover, table select:hover { background: var(--c-bg); }
table input:focus, table select:focus {
    outline: none;
    border-color: var(--c-border-focus);
    background: var(--c-surface);
    box-shadow: 0 0 0 2px rgba(43,112,239,0.08);
}
.money-input { text-align: right; font-variant-numeric: tabular-nums; }
.tax-display { font-variant-numeric: tabular-nums; }

/* ============================================================
   Auth Layout (Login)
   ============================================================ */
.auth-card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
    padding: var(--s-10);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
}
.auth-card h1 {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: 1.375rem;
    font-weight: 600;
    margin-bottom: var(--s-1);
    color: var(--c-text);
    letter-spacing: -0.02em;
}
.auth-card .subtitle {
    font-size: 0.8125rem;
    color: var(--c-text-mute);
    margin-bottom: var(--s-8);
}
.auth-card .btn-primary {
    width: 100%;
    justify-content: center;
    height: 42px;
    font-size: 0.875rem;
    margin-top: var(--s-2);
}

/* ============================================================
   Remove Button (table row delete)
   ============================================================ */
.btn-remove {
    background: none;
    border: none;
    color: var(--c-text-mute);
    cursor: pointer;
    font-size: 1.125rem;
    padding: var(--s-1);
    border-radius: var(--r-sm);
    transition: all var(--duration) var(--ease);
    line-height: 1;
}
.btn-remove:hover { color: var(--c-error); background: var(--c-error-bg); }

/* ============================================================
   Upload Options (toggle row)
   ============================================================ */
.upload-options {
    display: flex;
    gap: var(--s-5);
    align-items: center;
    margin-bottom: var(--s-4);
}

/* ============================================================
   Hamburger Toggle
   ============================================================ */
.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--s-2);
    border-radius: var(--r-sm);
    transition: background var(--duration) var(--ease);
}
.nav-toggle:hover { background: var(--c-bg); }
.nav-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--c-text);
    border-radius: 1px;
    transition: all 0.25s var(--ease);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    .app-header { padding: 0 var(--s-4); }
    .app-main { padding: var(--s-4) var(--s-4) var(--s-10); }
    .card { padding: var(--s-4); }
    h2 { font-size: 1.25rem; }
    .upload-dropzone { padding: var(--s-10) var(--s-4); }
    .auth-card { padding: var(--s-6); margin: 0 var(--s-4); }

    /* Hamburger menu */
    .nav-toggle { display: flex; }
    .header-nav {
        display: none;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--c-surface);
        border-bottom: 1px solid var(--c-border);
        box-shadow: var(--shadow-lg);
        flex-direction: column;
        padding: var(--s-2) 0;
        z-index: 99;
    }
    .header-nav.open { display: flex; }
    .header-nav a {
        padding: var(--s-3) var(--s-6);
        font-size: 0.875rem;
        border-radius: 0;
    }
    .header-nav a:hover { background: var(--c-bg); }

    /* Index page: buttons stack */
    .mobile-stack { flex-direction: column !important; gap: var(--s-3) !important; }
    .mobile-stack > * { width: 100%; }

    /* Table → Card layout on mobile */
    .table-responsive table thead { display: none; }
    .table-responsive table,
    .table-responsive table tbody,
    .table-responsive table tr,
    .table-responsive table td {
        display: block;
        width: 100%;
    }
    .table-responsive table tr {
        padding: var(--s-3) 0;
        border-bottom: 1px solid var(--c-border);
    }
    .table-responsive table td {
        padding: var(--s-1) 0;
        border-bottom: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 0.8125rem;
    }
    .table-responsive table td::before {
        content: attr(data-label);
        font-size: 0.6875rem;
        font-weight: 500;
        color: var(--c-text-mute);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        flex-shrink: 0;
        margin-right: var(--s-3);
    }
    .table-responsive table td[style*="text-align:right"] { text-align: right !important; }

    /* Accordion summary: hide API cost on mobile */
    .api-cost-info { display: none !important; }

    /* Search form stacks vertically */
    .search-form { flex-direction: column !important; }
    .search-form > div { min-width: 0 !important; width: 100% !important; flex: none !important; }

    /* Stat cards: 2 columns on mobile */
    .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .stat-value { font-size: 1.75rem !important; }

    /* Upload options: horizontal, compact */
    .upload-options { gap: var(--s-4); justify-content: flex-start; }
    .toggle-label { white-space: nowrap; }
}

/* ============================================================
   Page Load Animation
   ============================================================ */
.app-main { animation: fadeUp 0.4s var(--ease); }
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
