* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; overflow: hidden; }
body { font-family: Verdana, Geneva, sans-serif; background-color: #ffffff; color: #000000; display: flex; flex-direction: column; }

header { padding: 5px 10px; border-bottom: 2px solid #000; display: flex; justify-content: space-between; align-items: center; background: #eee; flex-shrink: 0; height: 40px; }
h1 { margin: 0; font-size: 16px; font-weight: bold; }
.nav-links a { margin-left: 15px; color: #0000EE; text-decoration: none; font-weight: bold; font-size: 14px; }
.nav-links a:hover { text-decoration: underline; background: #000; color: #fff; }

.content { flex: 1; display: flex; flex-direction: column; padding: 0; overflow: hidden; }

/* Search Mode Styles */
.search-container { padding: 20px; overflow-y: auto; text-align: center; }
.search-box { margin: 20px auto; display: inline-block; background: #eee; padding: 15px; border: 1px solid #000; }
.result-card { border: 1px solid #000; padding: 10px; margin: 10px auto; max-width: 600px; text-align: left; }

/* Browse Mode Styles */
.browse-container { display: flex; flex-direction: column; height: 100%; }
.filter-bar { padding: 5px 10px; background: #eee; border-bottom: 1px solid #000; display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.filter-bar input, .filter-bar select { padding: 2px 5px; font-family: inherit; font-size: 12px; }
.filter-bar button { padding: 2px 8px; font-size: 12px; cursor: pointer; }
.table-wrapper { flex: 1; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
th, td { border: 1px solid #ccc; padding: 2px 4px; text-align: left; white-space: nowrap; }
th { background: #ddd; position: sticky; top: 0; border-bottom: 1px solid #000; font-weight: bold; z-index: 1; }
tr:nth-child(even) { background: #f9f9f9; }
tr:hover { background-color: #ffffcc; }

.status-bar { padding: 5px 10px; background: #eee; border-top: 1px solid #000; font-size: 12px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; height: 30px; }
.pagination a { text-decoration: none; color: #0000EE; font-weight: bold; padding: 0 5px; }
.pagination a:hover { background: #000; color: #fff; }

.error { color: red; font-weight: bold; }


/* Flash Messages */
.flash-messages { flex-shrink: 0; }
.flash { padding: 5px 10px; font-size: 12px; border-bottom: 1px solid #ccc; }
.flash-success { background: #d4edda; color: #155724; }
.flash-error { background: #f8d7da; color: #721c24; }

/* Form Styles */
.form-container { padding: 20px; overflow-y: auto; max-width: 700px; margin: 0 auto; width: 100%; }
.form-container h2 { margin: 0 0 15px 0; font-size: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; font-size: 12px; font-weight: bold; }
.form-grid input, .form-grid textarea, .form-grid select { margin-top: 3px; padding: 5px; font-family: inherit; font-size: 13px; border: 1px solid #999; }
.form-grid .full-width { grid-column: 1 / -1; }
.form-actions { margin-top: 15px; display: flex; gap: 10px; align-items: center; }
.form-actions button { padding: 6px 16px; font-size: 13px; font-weight: bold; cursor: pointer; border: 1px solid #000; background: #ddd; }
.form-actions button:hover { background: #000; color: #fff; }
.form-actions a { font-size: 13px; color: #0000EE; }

/* Detail Styles */
.detail-container { padding: 20px; overflow-y: auto; max-width: 700px; margin: 0 auto; width: 100%; }
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.detail-header h2 { margin: 0; font-size: 18px; }
.detail-actions { display: flex; gap: 10px; align-items: center; }
.detail-actions a { color: #0000EE; font-weight: bold; font-size: 13px; }
.delete-btn { background: #c00; color: #fff; border: 1px solid #900; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.delete-btn:hover { background: #900; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.detail-table th { text-align: left; background: #eee; padding: 5px 8px; border: 1px solid #ccc; width: 160px; white-space: nowrap; }
.detail-table td { padding: 5px 8px; border: 1px solid #ccc; }

/* Browse table link styling */
table a { color: #0000EE; text-decoration: none; }
table a:hover { text-decoration: underline; }
th a { color: inherit; text-decoration: none; }
th a:hover { text-decoration: underline; }

/* Log / Spreadsheet View */
.log-container { display: flex; flex-direction: column; height: 100%; }
.log-toolbar { padding: 5px 10px; background: #eee; border-bottom: 1px solid #000; display: flex; gap: 10px; align-items: center; flex-shrink: 0; font-size: 12px; }
.log-wrapper { flex: 1; overflow: auto; }
table.log-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 11px; font-family: 'Consolas', 'Courier New', monospace; }
table.log-table th, table.log-table td { border: 1px solid #bbb; padding: 2px 6px; white-space: nowrap; }
table.log-table th { background: #d0d0d0; position: sticky; top: 0; z-index: 2; font-weight: bold; border-bottom: 2px solid #000; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
table.log-table td { max-width: 250px; overflow: hidden; text-overflow: ellipsis; }
table.log-table tr:nth-child(even) { background: #f5f5f5; }
table.log-table tr:hover { background: #ffffcc; }
table.log-table .row-num { background: #e0e0e0; color: #666; text-align: right; font-size: 10px; width: 30px; position: sticky; left: 0; z-index: 1; }
table.log-table th:first-child { position: sticky; left: 0; z-index: 3; }
table.log-table .col-name { min-width: 150px; font-weight: bold; }

/* Diary View */
.diary-container { display: flex; height: 100%; overflow: hidden; }
.diary-sidebar { width: 180px; background: #f0f0f0; border-right: 2px solid #000; overflow-y: auto; flex-shrink: 0; }
.diary-sidebar h3 { margin: 0; padding: 8px 10px; font-size: 13px; background: #ddd; border-bottom: 1px solid #000; }
.diary-sidebar ul { list-style: none; margin: 0; padding: 0; }
.diary-sidebar li { border-bottom: 1px solid #ddd; }
.diary-sidebar a { display: flex; justify-content: space-between; padding: 6px 10px; font-size: 12px; color: #000; text-decoration: none; }
.diary-sidebar a:hover { background: #ffffcc; }
.diary-sidebar a.active { background: #000; color: #fff; font-weight: bold; }
.diary-sidebar .date-count { color: #888; font-size: 11px; }
.diary-sidebar a.active .date-count { color: #ccc; }
.diary-main { flex: 1; overflow-y: auto; padding: 0; }
.diary-day { border-bottom: 2px solid #ccc; }
.diary-day-header { position: sticky; top: 0; z-index: 1; background: #e8e8e8; padding: 8px 15px; border-bottom: 1px solid #000; display: flex; justify-content: space-between; align-items: center; }
.diary-day-header h2 { margin: 0; font-size: 15px; }
.diary-day-header span { font-size: 12px; color: #555; }
.diary-entry { padding: 10px 15px; border-bottom: 1px solid #eee; display: flex; gap: 15px; align-items: flex-start; }
.diary-entry:hover { background: #ffffcc; }
.diary-entry-name { font-weight: bold; font-size: 14px; min-width: 180px; }
.diary-entry-name a { color: #0000EE; text-decoration: none; }
.diary-entry-name a:hover { text-decoration: underline; }
.diary-entry-meta { font-size: 12px; color: #333; display: flex; flex-wrap: wrap; gap: 8px; }
.diary-entry-meta .tag { background: #ddd; padding: 1px 6px; font-size: 11px; }
.diary-entry-remarks { font-size: 12px; color: #555; font-style: italic; margin-top: 2px; }
.diary-all-link { display: block; padding: 8px 10px; text-align: center; font-size: 12px; background: #eee; border-top: 1px solid #000; }
table.log-table .col-remarks { max-width: 300px; white-space: normal; word-break: break-word; }
table.log-table .col-numeric { text-align: right; }
table.log-table .col-id { text-align: center; width: 40px; }

/* Responsive Design */
@media (max-width: 768px) {
  /* Navigation */
  header { flex-wrap: wrap; height: auto; padding: 10px; }
  h1 { width: 100%; margin-bottom: 8px; text-align: center; }
  .nav-links { display: flex; flex-wrap: wrap; justify-content: center; width: 100%; gap: 5px; }
  .nav-links a { margin: 0 5px; font-size: 12px; padding: 4px 8px; }
  
  /* Status bar */
  .status-bar { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 5px; justify-content: center; }
  
  /* Search */
  .search-container { padding: 15px; }
  .search-box { width: 100%; padding: 10px; }
  .result-card { width: 100%; margin: 10px 0; }
  
  /* Browse & Filter bar */
  .filter-bar { flex-wrap: wrap; padding: 8px; }
  .filter-bar input, .filter-bar select { flex: 1; min-width: 120px; margin-bottom: 5px; }
  
  /* Tables */
  .table-wrapper, .log-wrapper { overflow-x: auto; }
  table { min-width: 600px; }
  
  /* Forms */
  .form-container { padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full-width { grid-column: auto; }
  .form-actions { flex-wrap: wrap; }
  
  /* Detail */
  .detail-container { padding: 15px; }
  .detail-header { flex-wrap: wrap; gap: 10px; }
  .detail-table th, .detail-table td { display: block; width: 100%; }
  .detail-table th { background: #eee; position: static; width: 100%; border-bottom: 1px solid #000; }
  .detail-table td { border-left: none; border-right: none; }
  
  /* Diary */
  .diary-container { flex-direction: column; }
  .diary-sidebar { width: 100%; height: auto; max-height: 200px; border-right: none; border-bottom: 2px solid #000; }
  .diary-entry { flex-direction: column; gap: 5px; }
  .diary-entry-name { min-width: auto; }
  
  /* Log */
  .log-toolbar { flex-wrap: wrap; padding: 8px; }
}

@media (max-width: 480px) {
  /* Even smaller adjustments */
  header h1 { font-size: 14px; }
  .nav-links a { font-size: 11px; padding: 3px 6px; }
  
  .status-bar { font-size: 11px; }
  
  .form-container h2 { font-size: 16px; }
  .form-grid label { font-size: 11px; }
  .form-grid input, .form-grid textarea, .form-grid select { font-size: 12px; }
  
  .detail-header h2 { font-size: 16px; }
  
  .diary-day-header h2 { font-size: 14px; }
  .diary-entry-name { font-size: 13px; }
  .diary-entry-meta { font-size: 11px; }
}
