/* === Design System Variables === */
:root {
  /* Colors */
  --primary-color: #3b82f6;
  --company-color: #3b82f6; /* 会社イメージカラー（デフォルト） */
  /* Modern Blue */
  --primary-hover: #2563eb;
  --secondary-color: #64748b;
  /* Slate */
  --secondary-hover: #475569;
  --success-color: #10b981;
  /* Emerald */
  --success-hover: #059669;
  --danger-color: #ef4444;
  /* Red */
  --danger-hover: #dc2626;
  --background-color: #f8fafc;
  /* Very light slate */
  --surface-color: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;

  /* Spacing & Sizing */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --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);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* === Base Styles === */
body {
  font-family: var(--font-sans);
  background-color: var(--background-color);
  color: var(--text-main);
  margin: 0;
  padding: 40px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  color: var(--text-main);
  margin-top: 0;
}

a {
  text-decoration: none;
  color: var(--primary-color);
  transition: color 0.2s;
}

a:hover {
  color: var(--primary-hover);
}

/* === Header === */
header {
  background: var(--surface-color);
  padding: 16px 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  margin-bottom: 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border-color);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1.2;
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  opacity: 1;
  /* Override old opacity rule */
}

.btn:active {
  transform: translateY(0);
}

/* Button Variants */
.btn-primary,
.btn-main {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover,
.btn-main:hover {
  background-color: var(--primary-hover);
  color: white;
}

.btn-secondary,
.btn-cancel {
  background-color: var(--surface-color);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover,
.btn-cancel:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
}

.btn-danger,
.btn-delete {
  background-color: var(--danger-color);
  color: white;
}

.btn-danger:hover,
.btn-delete:hover {
  background-color: var(--danger-hover);
  color: white;
}

.btn-success,
.btn-sub {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover,
.btn-sub:hover {
  background-color: var(--success-hover);
  color: white;
}

.btn-pdf {
  background-color: #8b5cf6;
  /* Violet */
  color: white;
}

.btn-pdf:hover {
  background-color: #7c3aed;
  color: white;
}

.btn-output {
  background-color: #28a745;
  /* Green */
  color: white;
}

.btn-output:hover {
  background-color: #218838;
  color: white;
}

.btn-edit {
  background-color: var(--secondary-color);
  color: white;
}

.btn-edit:hover {
  background-color: var(--secondary-hover);
  color: white;
}

/* === Forms === */
.add-form,
.form-container {
  background: var(--surface-color);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  margin-bottom: 32px;
  border: 1px solid var(--border-color);
}

.add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
  font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
select,
textarea {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  /* Larger font for better readability */
  color: var(--text-main);
  background-color: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  /* Default to full width in containers */
  box-sizing: border-box;
}

/* Specific fix for search inputs in flex container */
.add-form input {
  width: auto;
  flex-grow: 1;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Number inputs */
input[type="number"] {
  text-align: right;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* === CSV Operations === */
.csv-container {
  background: var(--surface-color);
  padding: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.csv-import-form {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 !important;
  /* Override any default margins */
}

.csv-title {
  font-weight: 600;
  color: var(--text-main);
  margin-right: auto;
  /* Pushes actions to the right if needed, or remove to keep compact */
}

/* === Tables === */
.table-section {
  background: var(--surface-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  /* For rounded corners */
  border: 1px solid var(--border-color);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

th {
  background-color: #f8fafc;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: #f8fafc;
}

/* Table Utilities */
.table-number,
td.number,
th.number {
  text-align: right !important;
}

/* === Pagination === */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 32px;
}

.pagination span {
  font-weight: 600;
  color: var(--text-muted);
}

/* === Utilities === */
.text-right {
  text-align: right;
}

.mb-4 {
  margin-bottom: 1rem;
}

.mt-4 {
  margin-top: 1rem;
}

.review-container {
  max-width: 1200px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.section-card {
  background: var(--surface-color);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 16px 0;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-color);
}

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

.info-row {
  display: flex;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  width: 140px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 15px;
}

.info-value {
  flex: 1;
  color: var(--text-main);
  font-size: 15px;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.items-table col.col-item {
  width: 42%;
}

.items-table col.col-qty {
  width: 12%;
}

.items-table col.col-unit {
  width: 10%;
}

.items-table col.col-price {
  width: 18%;
}

.items-table col.col-subtotal {
  width: 18%;
}

.items-table th {
  background: #f8f9fa;
  color: var(--text-main);
  padding: 12px;
  text-align: left;
  font-weight: 600;
  font-size: 15px;
  border: 1px solid var(--border-color);
}

.items-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 15px;
}

.items-table .number {
  text-align: right;
}

.items-table .center {
  text-align: center;
}

.items-table tfoot td {
  font-weight: 600;
  background: #f8f9fa;
}

.items-table .total-row td {
  font-size: 17px;
  background: #e8f4f8;
}

.empty-message {
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
  font-size: 15px;
}

.button-group {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 32px;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .info-row {
    flex-direction: column;
    gap: 4px;
  }

  .info-label {
    width: 100%;
  }

  .items-table {
    font-size: 12px;
  }

  .items-table th,
  .items-table td {
    padding: 8px 4px;
  }

  .button-group {
    flex-direction: column;
  }

  .button-group .btn {
    width: 100%;
  }
}
/* === Specific Page Overrides === */
/* Estimate Detail Items Table */
#items th {
  background-color: #f1f5f9;
}

.item-table-wrapper {
  margin-top: 24px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.back-link {
  display: inline-block;
  margin-top: 24px;
  color: var(--text-muted);
  font-weight: 500;
}

.back-link:hover {
  color: var(--primary-color);
}

/* === Form Groups === */
.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}


/* ---- 共通フッター ---- */
.global-footer {
  margin-top: 30px;
  padding: 15px 10px;
  border-top: 1px solid #e0e0e0;
  color: #666;
  font-size: 13px;
  text-align: center;
}
.global-footer .footer-links {
  margin-bottom: 6px;
}
.global-footer .footer-links a {
  color: #666;
  text-decoration: none;
  padding: 0 4px;
}
.global-footer .footer-links a:hover {
  text-decoration: underline;
}
.global-footer .sep {
  color: #aaa;
  padding: 0 4px;
}

/* === Estimate Review & Total Summary === */
.pc-total-summary {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 18px 20px;
  margin-top: 16px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}
.pc-total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
}
.pc-total-label {
  font-size: 0.95rem;
  color: #9ca3af;
  font-weight: 600;
}
.pc-total-value {
  text-align: right;
  line-height: 1.3;
}
.pc-total-value-main {
  font-size: 1.6rem;
  font-weight: 800;
}
.pc-total-value-sub {
  font-size: 1.35rem;
  font-weight: 600;
}
.margin-green { color: #16a34a; font-weight: 700; }
.margin-orange { color: #e67e22; font-weight: 700; }
.margin-red { color: #dc2626; font-weight: 700; }
.margin-muted { color: #64748b; font-weight: 600; }
