/* ============================================
   Zaiko styling — functional, mobile-first
   ============================================ */
* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
                 "Yu Gothic UI", Meiryo, sans-serif;
    color: #222; background: #f5f5f3;
    line-height: 1.55;
}
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.app-header {
    background: #2b2d2b; color: #fff; padding: 10px 0;
    border-bottom: 2px solid #d1a852;
    position: sticky; top: 0; z-index: 50;
}
.app-header .container { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.app-header .brand { font-weight: 700; font-size: 17px; color: #fff; text-decoration: none; letter-spacing: 0.04em; }
.app-header nav { display: flex; gap: 10px; flex-wrap: wrap; }
.app-header nav a {
    color: #ddd; text-decoration: none; font-size: 13px;
    padding: 4px 8px; border-radius: 4px; transition: background 0.1s;
}
.app-header nav a:hover { background: #3d3f3d; color: #fff; }
.app-header nav a.active { background: #d1a852; color: #1a1a1a; }

main { padding: 20px 0 40px; min-height: 70vh; }

/* Typography */
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 20px 0 8px; color: #444; }
h3 { font-size: 14px; margin: 16px 0 6px; color: #555; }
.muted { color: #888; font-size: 14px; }
small.hint { color: #888; font-size: 12px; }

/* Flashes */
.flashes { margin-top: 10px; }
.flash { padding: 10px 14px; border-radius: 4px; margin-bottom: 8px; font-size: 14px; }
.flash-success { background: #e0f5e4; color: #1d5d2e; border: 1px solid #b5dabb; }
.flash-error   { background: #fbe3e3; color: #8a1a1a; border: 1px solid #f0b7b7; }
.flash-info    { background: #e2ecf7; color: #1e4776; border: 1px solid #b7cee6; }
.flash-warn    { background: #fef3d9; color: #7a5a0d; border: 1px solid #eed59a; }

/* Cards (dashboard) */
.cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px; margin: 16px 0 24px;
}
.card {
    display: block; padding: 16px; background: #fff;
    border: 1px solid #e0ddd6; border-radius: 6px;
    text-decoration: none; color: inherit;
    transition: transform 0.1s, box-shadow 0.1s;
}
.card:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-color: #d1a852; }
.card h2 { margin: 0 0 8px; font-size: 14px; color: #555; }
.card-metric { font-size: 28px; font-weight: 700; color: #2b2d2b; }
.card-metric small { font-size: 14px; font-weight: 400; color: #888; }
.card-sub { font-size: 12px; color: #888; margin-top: 4px; }

.box {
    background: #fff; border: 1px solid #e0ddd6; border-radius: 6px;
    padding: 16px; margin-bottom: 16px;
}

/* Tables */
table.list { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
table.list th, table.list td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #eee; vertical-align: middle; }
table.list thead { background: #fafaf8; }
table.list thead th { font-size: 12px; color: #666; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tbody tr.clickable { cursor: pointer; }
table.list tbody tr.clickable:hover { background: #fafaf8; }
table.list input, table.list select { width: 100%; padding: 4px 6px; font-size: 13px; }

.thumb-sm { width: 60px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #eee; }
.code-sm { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: #666; }

/* Spec table (detail) */
table.spec { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; margin-bottom: 12px; }
table.spec th, table.spec td { padding: 8px 10px; border-bottom: 1px solid #eee; text-align: left; vertical-align: top; }
table.spec th { background: #fafaf8; width: 180px; color: #666; font-size: 13px; font-weight: normal; }

/* Buttons */
.btn {
    display: inline-block; padding: 6px 14px; border-radius: 4px; border: 1px solid #bbb;
    background: #fff; color: #333; font-size: 14px; text-decoration: none; cursor: pointer;
    transition: all 0.1s;
}
.btn:hover { background: #f0ede4; }
.btn-primary { background: #d1a852; color: #1a1a1a; border-color: #b99445; font-weight: 600; }
.btn-primary:hover { background: #c59840; color: #000; }
.btn-danger { background: #c94343; color: #fff; border-color: #a83333; }
.btn-danger:hover { background: #a83333; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 16px; }

/* Forms */
.form { max-width: 960px; }
.form-narrow { max-width: 480px; }
fieldset { border: 1px solid #ddd; border-radius: 6px; padding: 16px; margin-bottom: 16px; background: #fff; }
legend { padding: 0 8px; color: #666; font-size: 13px; font-weight: 600; }
label { display: block; margin-bottom: 10px; font-size: 13px; color: #555; }
label.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: #222; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search],
input[type=file], textarea, select {
    width: 100%; padding: 8px 10px; font-size: 14px; border: 1px solid #ccc; border-radius: 4px;
    background: #fff; color: #222;
}
input:focus, textarea:focus, select:focus { outline: 2px solid #d1a852; outline-offset: -1px; border-color: #d1a852; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 12px; align-items: end; }
@media (max-width: 720px) {
    .grid-2, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
}
.computed {
    background: #f4efe0; padding: 8px 10px; border-radius: 4px; font-size: 13px;
    align-self: end; border: 1px dashed #d1a852;
}
.computed strong { color: #7a5a0d; font-size: 16px; margin-right: 4px; }
.computed-box {
    background: #f4efe0; padding: 10px; border-radius: 4px;
    border: 1px dashed #d1a852; font-size: 13px;
}
.computed-box .big { font-size: 20px; font-weight: 700; color: #7a5a0d; margin: 4px 0; }

.form-actions { margin-top: 20px; display: flex; gap: 10px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 120px; }

/* Filters bar */
.filters {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end;
    background: #fff; padding: 10px 14px; border-radius: 4px; margin-bottom: 12px;
    border: 1px solid #e0ddd6;
}
.filters label { margin: 0; font-size: 12px; }
.filters input, .filters select { padding: 6px 8px; font-size: 13px; }

.toolbar { margin-bottom: 10px; }

/* Card grid (meiboku list) */
.card-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}
.item-card {
    background: #fff; border: 1px solid #e0ddd6; border-radius: 6px;
    text-decoration: none; color: inherit; overflow: hidden;
    transition: transform 0.1s, box-shadow 0.1s; display: flex; flex-direction: column;
}
.item-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); border-color: #d1a852; }
.item-card .thumb {
    position: relative; aspect-ratio: 4 / 3; background: #eee;
    display: flex; align-items: center; justify-content: center;
}
.item-card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-card .thumb .no-thumb { color: #aaa; font-size: 12px; }
.item-card .meta { padding: 10px 12px; }
.item-card .code { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: #888; }
.item-card .title { font-weight: 600; font-size: 15px; margin: 3px 0 5px; }
.item-card .sub { font-size: 12px; color: #888; }
.item-card .sell { margin-top: 6px; font-size: 16px; color: #7a5a0d; font-weight: 600; }

.badge-used, .badge-ok {
    display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.badge-used { background: #888; color: #fff; }
.badge-ok { background: #2a8049; color: #fff; }
.item-card .badge-used {
    position: absolute; top: 6px; right: 6px;
}

/* Detail */
.detail-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-header h1 { margin: 0; }
.detail-header .actions { display: flex; gap: 8px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 16px; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

.photo-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}
.photo-item { background: #fff; border: 1px solid #e0ddd6; border-radius: 4px; overflow: hidden; }
.photo-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.photo-item form { padding: 4px; text-align: center; }

.photo-upload { margin-top: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.used-form, .delete-form { background: #fff; padding: 16px; border-radius: 6px; border: 1px solid #eee; margin-top: 20px; }
.used-form h3 { margin-top: 0; }
.delete-form { border-color: #f0b7b7; background: #fcf3f3; }

.notice { padding: 10px 14px; border-radius: 4px; margin: 10px 0; }
.notice-warn { background: #fef3d9; color: #7a5a0d; border: 1px solid #eed59a; }

/* Auth box */
.auth-box { margin: 10px 0 20px; }
.auth-form { background: #fff; padding: 14px; border-radius: 6px; border: 1px solid #e0ddd6; display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.auth-form label { margin: 0; }
.auth-form input[type=password] { max-width: 160px; }
.auth-status { background: #f4efe0; padding: 10px 14px; border-radius: 4px; border: 1px dashed #d1a852; font-size: 14px; }
.auth-status.authed { color: #7a5a0d; }
.auth-status form, .auth-status a { margin-left: 8px; }

.app-footer { margin-top: 40px; padding: 16px 0; background: #2b2d2b; color: #999; text-align: center; }

/* Login page */
.login-body {
    background: #2b2d2b;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    margin: 0;
}
.login-box {
    background: #fff;
    padding: 40px 32px;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 380px;
    border-top: 4px solid #d1a852;
}
.login-box h1 {
    text-align: center;
    font-size: 18px;
    margin: 0 0 28px;
    color: #2b2d2b;
    line-height: 1.4;
}
.login-box h1 small {
    display: block;
    font-size: 14px;
    color: #888;
    font-weight: 400;
    margin-top: 4px;
}
.login-box label {
    font-size: 13px;
    color: #555;
    margin-bottom: 16px;
}
.login-box input[type=password] {
    margin-top: 4px;
    font-size: 18px;
    letter-spacing: 0.3em;
    text-align: center;
    padding: 12px;
}
.login-box .flash {
    margin-bottom: 16px;
}

/* Logout button in header */
.app-header .logout-form {
    margin-left: auto;
}
.app-header .logout-form button {
    background: transparent;
    border: 1px solid #555;
    color: #bbb;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.1s;
}
.app-header .logout-form button:hover {
    background: #3d3f3d;
    color: #fff;
    border-color: #777;
}

@media (max-width: 600px) {
    .app-header .container { flex-direction: column; align-items: flex-start; gap: 6px; }
    .app-header nav { gap: 6px; }
    .app-header nav a { font-size: 12px; padding: 3px 6px; }
    h1 { font-size: 20px; }
    .thumb-sm { width: 44px; height: 44px; }
}
