/* CSS Variables */
:root {
  --primary-bg: #171717;
  --secondary-bg: #f3f3f5;
  --surface-bg: #ffffff;
  --text-primary: #505050;
  --text-secondary: #9399a0;
  --text-muted: #808080;
  --accent-red: #fd253a;
  --border-color: #ddd;
  --gradient-from: #fafafa;
  --gradient-to: #d2d2d2;
}

/* Reset and Base Styles */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  background: var(--secondary-bg);
  color: var(--text-primary);
  font: 500 13px/1.4 Lato, Arial, Tahoma, sans-serif;
  overflow-x: hidden;
  min-width: 320px !important;
}

/* Typography */
h2, h3, h4, h5 {
  font: 700 14px Lato, Arial, Tahoma, sans-serif;
  margin-top: 0;
  margin-bottom: 16px;
}

h2 {
  font-size: 23px;
  color: var(--primary-bg);
}

h2:first-letter {
  color: var(--accent-red);
  font-size: 30px;
}

h2 span {
  padding-bottom: 6px;
  border-bottom: 1px solid #000;
  display: block;
  margin-bottom: 28px;
}

/* Links */
a {
  color: #b9bbbe;
  text-decoration: none;
  transition: color 0.3s ease;
}

a:hover {
  text-decoration: underline;
  color: white;
}

/* Container */
.container {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
header {
  padding: 20px 0;
  background-color: var(--primary-bg);
  width: 100%;
  min-height: 90px;
  position: relative;
}

.header-inner {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

@media (min-width: 768px) {
  .header-inner {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
  }
}

/* Top Line Navigation */
.top_line {
  height: 20px;
  overflow: hidden;
  order: 2;
}

@media (min-width: 768px) {
  .top_line {
    order: 1;
    margin-bottom: 18px;
  }
}

.top_line ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.top_line li {
  display: inline;
}

.top_line a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
}

.top_line a:hover {
  color: white;
  text-decoration: underline;
}

/* Logo */
.top_logo {
  order: 1;
  margin-bottom: 10px;
}

@media (min-width: 768px) {
  .top_logo {
    order: 2;
    width: 356px;
    margin-top: -46px;
  }
}

.top_logo a[href='https://foto.tadviser.ru'] {
  display: block;
  margin-bottom: 14px;
}

.top_logo img {
  max-width: 100%;
  height: auto;
}

.top_logo > div:last-child {
  margin-top: -7px;
  padding: 0 5px;
  color: #BBB;
  font-size: 13px;
}

/* Search Form */
.top_search {
  order: 3;
  width: 100%;
  background: linear-gradient(var(--gradient-from), var(--gradient-to));
  padding: 14px 16px;
  border-radius: 5px;
  margin-top: 10px;
}

@media (min-width: 768px) {
  .top_search {
    width: 460px;
    margin-top: -34px;
    margin-right: 5px;
    float: right;
  }
}

.top_search input[type='text'] {
  background-color: transparent;
  border: 0;
  border-bottom: 1px solid var(--text-muted);
  color: black;
  width: 100%;
  font-size: 16px;
  padding: 5px;
  margin-bottom: 8px;
}

@media (min-width: 480px) {
  .top_search input[type='text'] {
    width: calc(100% - 100px);
    font-size: 20px;
    margin-bottom: 0;
  }
}

.top_search input[type='submit'] {
  border: 1px solid #666;
  background: linear-gradient(var(--gradient-from), var(--gradient-to));
  cursor: pointer;
  font-size: 16px;
  height: 34px;
  width: 86px;
  border-radius: 4px;
  float: right;
}

.top_search > div {
  clear: both;
  font-size: 12px;
  color: var(--text-primary);
  margin-top: 4px;
}

/* Main Content */
section {
  padding: 26px 0;
  min-height: 100px;
}

.content-area {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

@media (min-width: 1024px) {
  .content-area {
    flex-direction: row;
  }
}

/* Gallery Blocks */
.gallery_block {
  background-color: var(--surface-bg);
  border: 1px solid #f2f2f2;
  margin: 0 0 14px 0;
  padding: 0 5px 10px 5px;
  overflow: hidden;
}

@media (min-width: 768px) {
  .gallery_block {
    float: left;
    width: calc(50% - 14px);
    margin: 0 0 14px 14px;
    max-width: 486px;
    height: 375px;
  }
  
  .gallery_block:nth-child(odd) {
    margin-left: 0;
  }
}

.gallery_block h2 {
  margin-bottom: 16px;
  padding-top: 10px;
  line-height: 1;
  cursor: pointer;
  font-size: 18px;
}

.gallery_block h2:hover {
  color: var(--accent-red);
}

.gallery_block font {
  font-size: 12px !important;
  color: #666;
  display: block;
  margin-top: 4px;
}

/* Photo Thumbs Grid */
.photo_thumb {
  float: left;
  padding: 5px;
  background: none;
  background-color: transparent;
  width: 150px;
  height: auto;
  border: none;
  margin: 0 2px 4px 0;
  text-align: center;
}

.photo_thumb a {
  display: block;
  height: auto;
}

.photo_thumb img {
  border: 1px solid #CCC;
  max-width: 100%;
  height: auto;
}

.photo_thumb > div:not(.buy_button) {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.2;
  margin: 2px 0;
}

/* Buy Button */
.buy_button {
  margin-left: -2px;
  color: #000;
  background: linear-gradient(var(--gradient-from), var(--gradient-to));
  padding: 4px 2px;
  margin-top: 4px;
  cursor: pointer;
  width: 150px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

.buy_button:hover {
  background: linear-gradient(#e6e6e6, #bebebe);
  text-decoration: none;
}

/* More Photos Link */
.gallery_block > div:last-child {
  padding-right: 8px;
  padding-top: 16px;
  font-size: 13px;
  float: left;
  clear: both;
}

.gallery_block > div:last-child a {
  color: #666;
  font-weight: bold;
}

.gallery_block > div:last-child a:hover {
  color: var(--accent-red);
}

/* Utility Classes */
.clear {
  clear: both;
}

.img-responsive {
  max-width: 100%;
  height: auto;
}

/* Form Styles */
form {
  margin: 0;
}

input, button {
  font-family: inherit;
}

/* Responsive Improvements */
@media (max-width: 767px) {
  .container {
    padding: 0 15px;
  }
  
  header {
    padding: 15px 0;
    min-height: auto;
  }
  
  .top_search {
    padding: 10px 12px;
  }
  
  .top_search input[type='text'] {
    font-size: 16px;
  }
  
  .top_search input[type='submit'] {
    width: 80px;
    font-size: 14px;
  }
  
  .gallery_block {
    height: auto !important;
  }
  
  .photo_thumb {
    width: calc(50% - 4px);
    margin: 0 2px 8px 0;
  }
  
  .photo_thumb:nth-child(even) {
    margin-right: 0;
  }
  
  .buy_button {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .photo_thumb {
    width: 100%;
    margin-right: 0;
  }
  
  .top_logo > div:last-child {
    font-size: 11px;
  }
  
  .gallery_block h2 {
    font-size: 16px;
  }
}

/* Print Styles */
@media print {
  .top_search,
  .buy_button {
    display: none;
  }
  
  .gallery_block {
    break-inside: avoid;
    height: auto !important;
  }
}