* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f9fafb;
    color: #111827;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
    line-height: 1.6;
}

a {
    color: #2563eb;
}

.page {
    min-height: 100vh;
    padding: 32px 16px;
}

.page-health {
    display: grid;
    place-items: center;
}

.health-card,
.auth-card,
.dashboard {
    width: min(100%, 960px);
    margin: 0 auto;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 28px;
}

.auth-card {
    width: min(100%, 480px);
}

.eyebrow {
    margin: 0 0 8px;
    color: #2563eb;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
}

h1 {
    margin: 0 0 16px;
    font-size: 28px;
}

h2 {
    margin: 0 0 8px;
    font-size: 18px;
}

dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
}

dt {
    color: #4b5563;
    font-weight: 700;
}

label {
    display: grid;
    gap: 6px;
    margin: 16px 0;
    font-weight: 700;
}

input {
    min-height: 44px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 10px 12px;
    font: inherit;
}

input[type="checkbox"] {
    width: 22px;
    min-height: 22px;
}

select,
textarea {
    min-height: 44px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 10px 12px;
    font: inherit;
    background: #ffffff;
}

textarea {
    resize: vertical;
}

button {
    min-height: 44px;
    border: 0;
    border-radius: 6px;
    padding: 10px 16px;
    background: #2563eb;
    color: #ffffff;
    font: inherit;
    font-weight: 700;
}

.button,
.text-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    text-decoration: none;
}

.button {
    border-radius: 6px;
    padding: 10px 16px;
    background: #2563eb;
    color: #ffffff;
    font-weight: 700;
}

.button-secondary {
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
}

.button-danger {
    background: #dc2626;
}

.alert {
    border-radius: 6px;
    padding: 12px 14px;
    font-weight: 700;
}

.alert-error {
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

.alert-success {
    border: 1px solid #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.card {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 18px;
    background: #ffffff;
}

.admin-page .eyebrow {
    color: #4b5563;
}

.family-app {
    margin: 0;
    background: #f3f4f6;
    color: #111827;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
}

.family-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 20px;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid #d1d5db;
    background: #ffffff;
}

.family-header h1 {
    margin-bottom: 0;
    font-size: 24px;
}

.family-header-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0;
}

.family-header-meta div {
    min-width: 112px;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #f9fafb;
}

.family-header-meta dt {
    font-size: 12px;
}

.family-header-meta dd {
    margin: 0;
    font-weight: 700;
}

.family-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: calc(100vh - 89px);
}

.family-sidebar {
    border-right: 1px solid #d1d5db;
    background: #ffffff;
    padding: 16px;
}

.family-sidebar nav {
    display: grid;
    gap: 8px;
}

.family-nav-link {
    display: block;
    min-height: 44px;
    border-radius: 8px;
    padding: 10px 12px;
    color: #111827;
    font-weight: 700;
    text-decoration: none;
}

.family-nav-link:hover,
.family-nav-link.is-active {
    background: #dbeafe;
    color: #1d4ed8;
}

.family-nav-link.is-disabled {
    color: #6b7280;
}

.family-main {
    display: grid;
    gap: 18px;
    align-content: start;
    padding: 24px;
}

.status-grid,
.dashboard-columns,
.form-grid {
    display: grid;
    gap: 16px;
}

.status-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.dashboard-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel,
.metric-card {
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
}

.panel {
    padding: 18px;
}

.metric-card {
    display: grid;
    gap: 4px;
    padding: 16px;
}

.metric-label {
    color: #4b5563;
    font-size: 13px;
    font-weight: 700;
}

.metric-card strong {
    font-size: 24px;
}

.panel-header {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.panel-header h2 {
    margin-bottom: 0;
}

.ai-comment {
    margin: 0;
    border-left: 4px solid #2563eb;
    padding: 10px 12px;
    background: #eff6ff;
    font-weight: 700;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-normal {
    background: #f3f4f6;
    color: #374151;
}

.badge-ok {
    background: #dcfce7;
    color: #166534;
}

.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.list {
    display: grid;
    gap: 10px;
}

.list-row {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
}

.list-row div:first-child {
    display: grid;
    gap: 2px;
}

.list-row-danger {
    border-color: #fecaca;
    background: #fef2f2;
}

.list-row-warn {
    border-color: #fde68a;
    background: #fffbeb;
}

.row-actions,
.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.button-row {
    justify-content: flex-start;
}

.detail-box {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px;
    background: #f9fafb;
}

.danger-panel {
    border-color: #fecaca;
    background: #fff7f7;
}

.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.filter-bar label {
    margin: 0;
}

.checkbox-line {
    display: flex;
    gap: 10px;
    align-items: center;
    min-height: 44px;
    font-weight: 700;
}

.readonly-field {
    min-height: 44px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px 12px;
    background: #f9fafb;
}

.list-row small,
.note,
.empty {
    color: #6b7280;
}

.medicine-slots {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.slot {
    display: grid;
    gap: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    font-weight: 700;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.info-grid div {
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 10px;
}

.info-grid dd {
    margin: 0;
    font-weight: 700;
}

.stack-form {
    display: grid;
    gap: 12px;
}

.stack-form label {
    margin: 0;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.row-actions form {
    margin: 0;
}

.responsive-table {
    overflow-x: auto;
}

.responsive-table table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.responsive-table th,
.responsive-table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

.responsive-table th {
    color: #4b5563;
    font-size: 13px;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-actions form {
    margin: 0;
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.check-line {
    display: flex;
    gap: 8px;
    align-items: center;
    min-height: 44px;
    margin: 0;
}

.check-line input[type="checkbox"] {
    min-height: auto;
    width: 20px;
    height: 20px;
}

.chip-list,
.chart-grid,
.filter-form {
    display: grid;
    gap: 12px;
}

.chip-list {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.chip {
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    padding: 10px 12px;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 700;
    text-align: center;
}

.chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chart-placeholder {
    display: grid;
    gap: 8px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    padding: 12px;
    background: #f8fafc;
    color: #475569;
    font-weight: 700;
}

.chart-placeholder canvas {
    width: 100%;
    border-radius: 6px;
    background: linear-gradient(180deg, #ffffff, #f1f5f9);
}

.chart-panel canvas {
    display: block;
    width: 100%;
    min-height: 160px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.filter-form {
    grid-template-columns: repeat(3, minmax(0, max-content));
    align-items: end;
    margin-bottom: 14px;
}

.filter-form-wide {
    grid-template-columns: repeat(6, minmax(130px, 1fr));
}

.filter-form label {
    margin: 0;
}

.plain-list {
    margin: 0;
    padding-left: 20px;
}

.plain-list li + li {
    margin-top: 6px;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.memory-card {
    display: grid;
    gap: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px;
    background: #ffffff;
}

.memory-card h3,
.memory-card p {
    margin: 0;
}

.photo-thumb {
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 8px;
    background: #f3f4f6;
}

.photo-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.admin-app {
    margin: 0;
    background: #f3f4f6;
    color: #111827;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
}

.admin-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 20px;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #d1d5db;
    background: #ffffff;
}

.admin-header h1 {
    margin-bottom: 0;
    font-size: 24px;
}

.admin-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: calc(100vh - 82px);
}

.admin-sidebar {
    border-right: 1px solid #d1d5db;
    background: #ffffff;
    padding: 14px;
}

.admin-sidebar nav {
    display: grid;
    gap: 6px;
}

.admin-main {
    display: grid;
    gap: 18px;
    align-content: start;
    padding: 24px;
}

.admin-kpi {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.admin-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    min-width: 880px;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    border-bottom: 1px solid #e5e7eb;
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
}

.admin-table th {
    background: #f9fafb;
    color: #374151;
    font-size: 13px;
    white-space: nowrap;
}

.json-preview {
    overflow-x: auto;
    min-height: 72px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    background: #f9fafb;
    white-space: pre-wrap;
}

@media (max-width: 900px) {
    .family-header,
    .family-shell,
    .admin-header,
    .admin-shell,
    .dashboard-columns,
    .status-grid,
    .form-grid,
    .info-grid {
        grid-template-columns: 1fr;
    }

    .family-header {
        position: static;
    }

    .family-sidebar {
        border-right: 0;
        border-bottom: 1px solid #d1d5db;
    }

    .admin-sidebar {
        border-right: 0;
        border-bottom: 1px solid #d1d5db;
    }

    .family-sidebar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-sidebar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .medicine-slots {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .check-grid,
    .chart-grid,
    .filter-form,
    .filter-form-wide {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .family-main,
    .family-header,
    .family-sidebar,
    .admin-main,
    .admin-header,
    .admin-sidebar {
        padding: 14px;
    }

    .family-sidebar nav,
    .admin-sidebar nav,
    .medicine-slots {
        grid-template-columns: 1fr;
    }

    .list-row,
    .row-actions {
        align-items: stretch;
        flex-direction: column;
    }
}
